Tip: Adding –record flag to kubctl apply will stick the command to the object, so that it will appear under CHANGE-CAUSE in history
Get details for a particular deployment revision
kubectl rollout history deploy <deploymentname> --revision=<revisionnumber>
Rollback a deployment
kubectl rollout undo deploy <deploymentname>
Tip: It is better to avoid this rollback mechanism, and downgrade the version in the deployment.yaml itself and reposting it with “kubectl apply”. This “imperative” way could cause inconsistent environment, where the version of the running container instance doesn’t match the yaml manifest, and any redeployment could accidentally deploy unwanted version. “Declarative” approach is preferred.
Get snapshot logs for a particular pod with only one container
kubectl run -i --tty <name> --image=<imagename> <command>
kubectl run -i --tty loader --image=busybox /bin/sh
Note: This command will create a pod and will run the container inside it. if “–replica=<number>” is used, it will also create a replication controller in the cluster and will monitor the pod. This is useful when testing (i.e.: hitting a service and generating load, checking service/pod network, etc)
Summary and References
This post contains a list of commonly used commands when interacting with a Kubernetes cluster. Shout out to @nigelpoulton and his great ACG course: “Kubernetes Deep Dive“. Also, here is a far better Cheat Sheet from original kubernetes team.