kubernetes version: 1.8 - Date: October 2017
Kubectl Autocomplete
Setup autocomplete in bash
apt install bash-completion
source <(kubectl completion bash)
Context and Configuration
Show kubeconfig settings
kubectl config view
Set the default context (cluster)
kubectl config use-context CLUSTER-NAME
Creating Objects
Create resource(s)
kubectl create -f FILE.yaml [FILE2.yaml]
- Create app-v1 from a file:
kubectl create -f app-v1.yaml
Create resource(s) in all manifest files in a directory
kubectl create -f PATH/DIR/
Create resource(s) from url
kubectl create -f https://URL
Run a single instance (pod)
kubectl run NAME ARGS
- Start a single instance (pod) of nginx
kubectl run nginx --image=nginx
Viewing, Finding Resources
List main resources
kubectl get all
List all services in the namespace
kubectl get services [--namespace NS]
List all pods in all namespaces
kubectl get pods --all-namespaces
List a particular deployment
kubectl get deployment DEPLOYMENT
Get the version label of all pods with label version=v1
kubectl get pods --selector=version=v1
Describe commands with verbose output
kubectl describe nodes NODE
kubectl describe pods POD
Updating Resources
Rolling update
kubectl rolling-update POD ARGS
Rolling update pods of app-v1:
kubectl rolling-update app-v1 -f app-v2.yaml
Change the name of the resource and update the image:
kubectl rolling-update app-v1 app-v2 --image=image:v2
Force replace, delete and then re-create the resource. Will cause a service outage.
kubectl replace --force -f POD.json