CKA CheatSheet
CKA CheatSheet
$ source <(kubectl completion bash) # setup autocomplete in bash, bash-completion package should be
installed first.
$ source <(kubectl completion zsh) # setup autocomplete in zsh
Creating Objects
Kubernetes manifests can be defined in json or yaml. The file extension .yaml, .yml,
Updating Resources
$ kubectl rolling-update frontend-v1 -f frontend-v2.json # Rolling update pods of frontend-v1
$ kubectl rolling-update frontend-v1 frontend-v2 --image=image:v2 # Change the name of the resource and
update the image
$ kubectl rolling-update frontend --image=image:v2 # Update the pods image of frontend
$ kubectl rolling-update frontend-v1 frontend-v2 --rollback # Abort existing rollout in progress
$ cat pod.json | kubectl replace -f - # Replace a pod based on the JSON
passed into stdin
# Force replace, delete and then re-create the resource. Will cause a service outage.
$ kubectl replace --force -f ./pod.json
# Create a service for a replicated nginx, which serves on port 80 and connects to the containers on port
8000
$ kubectl expose rc nginx --port=80 --target-port=8000
# Update a single-container pod's image version (tag) to v4
$ kubectl get pod mypod -o yaml | sed 's/\(image: myimage\):.*$/\1:v4/' | kubectl replace -f -
$ kubectl label pods my-pod new-label=awesome # Add a Label
$ kubectl annotate pods my-pod icon-url=http://goo.gl/XXBTWq # Add an annotation
$ kubectl autoscale deployment foo --min=2 --max=10 # Auto scale a deployment "foo"
Patching Resources
Patch a resource(s) with a strategic merge patch.
Scaling Resources
$ kubectl scale --replicas=3 rs/foo # Scale a replicaset named 'foo' to 3
$ kubectl scale --replicas=3 -f foo.yaml # Scale a resource specified in
"foo.yaml" to 3
$ kubectl scale --current-replicas=2 --replicas=3 deployment/mysql # If the deployment named mysql's
current size is 2, scale mysql to 3
$ kubectl scale --replicas=5 rc/foo rc/bar rc/baz # Scale multiple replication
controllers
Deleting Resources
$ kubectl delete -f ./pod.json # Delete a pod using the type and name specified in
pod.json
$ kubectl delete pod,service baz foo # Delete pods and services with same names "baz" and
"foo"
$ kubectl delete pods,services -l name=myLabel # Delete pods and services with label name=myLabel
$ kubectl -n my-ns delete po,svc --all # Delete all pods and services in namespace my-ns
Resource types
The following table includes a list of all the supported resource types and their abbreviated
aliases.
componentstatuses cs
configmaps cm
daemonsets ds
deployments deploy
endpoints ep
event ev
horizontalpodautoscalers hpa
ingresses ing
jobs
limitranges limits
namespaces ns
networkpolicies
nodes no
statefulsets
persistentvolumeclaims pvc
persistentvolumes pv
pods po
podsecuritypolicies psp
podtemplates
replicasets rs
replicationcontrollers rc
resourcequotas quota
cronjob
secrets
serviceaccount sa
services svc
storageclasses
thirdpartyresources
Formatting output
To output details to your terminal window in a specific format, you can add either the -o or -