This is a draft cheat sheet. It is a work in progress and is not finished yet.
Creating Objects
Create resources (multiple allowed) |
kubectl create -f ./x.yaml ./y.yaml
|
Start a single instance of nginx |
kubectl run nginx --image=nginx
|
Get the documentation |
|
Viewing, Finding Resources
List all services in the namespace |
|
All namespace |
kubectl get pods --all-namespaces
|
More details |
|
List Services Sorted by Name |
kubectl get services --sort-by=.metadata.name
|
Get using label |
kubectl get pods --selector=app=cassandra
|
Describe commands with verbose output |
kubectl describe nodes my-node
|
Updating Resources
Rolling update pods of frontend-v1 |
kubectl rolling-update frontend-v1 -f frontend-v2.json
|
Change the name of the resource and update the image |
kubectl rolling-update frontend-v1 frontend-v2 --image=image:v2
|
Update the pods image of frontend |
kubectl rolling-update frontend --image=image:v2
|
Abort existing rollout in progress |
kubectl rolling-update frontend-v1 frontend-v2 --rollback
|
Force replace, delete and then re-create the resource. Will cause a service outage. |
kubectl replace --force -f ./pod.json
|
Add a Label |
kubectl label pods my-pod new-label=awesome
|
Auto scale a deployment "foo" |
kubectl autoscale deployment foo --min=2 --max=10
|
Scaling Resources
Scale a replicaset named 'foo' to 3 |
kubectl scale --replicas=3 rs/foo
|
Scale a resource specified in "foo.yaml" to 3 |
kubectl scale --replicas=3 -f foo.yaml
|
If the deployment named mysql's current size is 2, scale mysql to 3 |
kubectl scale --current-replicas=2 --replicas=3 deployment/mysql
|
Scale multiple replication controllers |
kubectl scale --replicas=5 rc/foo rc/bar rc/baz
|
|
|
Deleting Resources
Delete a pod using the type and name specified in pod.json |
kubectl delete -f ./pod.json
|
Delete pods and services with same names "baz" and "foo" |
kubectl delete pod,service baz foo
|
Delete pods and services with label name=myLabel |
kubectl delete pods,services -l name=myLabel
|
Delete all pods and services in namespace my-ns |
kubectl -n my-ns delete po,svc --all
|
Interacting with running Pods
dump pod logs (stdout) |
|
dump pod container logs (stdout, multi-container case) |
kubectl logs my-pod -c my-container
|
stream pod logs (stdout) |
|
Attach to Running Container |
|
Forward port 6000 of Pod to your to 5000 on your local machine |
kubectl port-forward my-pod 5000:6000
|
Run command in existing pod (1 container case) |
kubectl exec my-pod -- ls /
|
Show metrics for a given pod and its containers |
kubectl top pod POD_NAME --containers
|
|