The official cheat sheet can be found here.
A short summary of kubectl
commands.
kubectl --help
You can use help on any other sub-command. Examples:
kubectl get --help
kubectl run --help
kubectl create svc clusterip --help
Run a single pod without anything more.
kubectl run --image nginx demo
Print the logs to your console that were generated by a container inside the pod.
kubectl logs -f <POD-NAME>
Open a shell or execute a binary.
kubectl exec -it <POD-NAME> -- <BINARY>
Examples:
kubectl exec -it demo -- sh
kubectl exec -it demo -- whoami
Simple, short table output: kubectl get <RESOURCE-KIND>
Descriptive ouptut: kubectl describe <RESOURCE-KIND <RESOURCE-NAME>
Examples:
kubectl get pods
kubectl get deployments,services
kubectl get secret
kubectl get po -l demo
kubectl describe pod demo
Create Kubernetes objects.
Imperatively: kubectl create <RESOURCE-KIND> ...
Examples:
kubectl create deploy demo --image nginx --replicas=2
kubectl create svc clusterip demo --tcp 8000:8000
Declaratively: kubectl apply -f <FILE-NAME>.yaml
Delete Kubernetes objects.
kubectl delete <RESOURCE-KIND> <RESOURCE-NAME>
Examples:
kubectl delete deployment demo
kubectl delete -f <FILE-NAME>.yaml
kubectl get po -o yaml | kubectl delete -f -
Access a pod or service on the Kubernetes cluster via localhost.
kubectl port-forward <RESOURCE-KIND> <LOCAL-PORT>:<REMOTE-PORT>
Examples:
kubectl port-forward po demo 8080:8000
kubectl port-forward svc demo 80:8000