Kubernetes Cheatsheet


Kubernetes Cheatsheet

Basic Commands

CommandDescription
kubectl getList resources
kubectl describeShow detailed information about a resource
kubectl createCreate a resource from a file or standard input
kubectl applyApply a configuration to a resource
kubectl deleteDelete resources
kubectl execExecute a command in a container
kubectl logsShow logs for a container
kubectl port-forwardForward a local port to a port on a container
kubectl proxyRun a proxy to the Kubernetes API server
kubectl versionShow client and server versions

Resource Types

CommandDescription
kubectl runRun a container in a pod
kubectl exposeExpose a deployment, service, or pod as a service
kubectl scaleScale a deployment or replicaset
kubectl autoscaleCreate an autoscaler for a deployment
kubectl rolloutManage a rollout of a deployment
kubectl configModify kubeconfig files
kubectl cluster-infoDisplay cluster information
kubectl cordonMark a node as unschedulable
kubectl drainDrain a node in preparation for maintenance
kubectl taintTaint a node with a key/value pair

Advanced Commands

CommandDescription
kubectl apply -fApply a configuration file
kubectl exec -itExecute a command in a container with a terminal session
kubectl logs -fStream logs for a container
kubectl port-forwardForward a local port to a port on a container
kubectl proxyRun a proxy to the Kubernetes API server
kubectl rollout statusShow the status of a rollout
kubectl rollout historyShow the history of a rollout
kubectl diffShow differences between the running and desired state of a resource
kubectl editEdit a resource in the default editor
kubectl labelAdd or remove labels from a resource
kubectl annotateAdd or remove annotations from a resource
kubectl apply --dry-runPreview changes to a resource without applying them
kubectl explainShow documentation for a resource or field
kubectl auth can-iCheck if the current user can perform a specific action on a resource

Plugins

CommandDescription
kubectl krewInstall and manage kubectl plugins
kubectl treeShow a resource hierarchy as a tree
kubectl ctxSwitch between kubectl contexts
kubectl nsSwitch between Kubernetes namespaces
kubectl neatReformat resource YAML for readability
kubectl view-secretView Kubernetes secrets in a decoded format
kubectl who-canShow who can perform a specific action on a resource
kubectl crdShow custom resource definitions
kubectl kustomizeCreate a customized Kubernetes configuration from a base configuration and patches
kubectl helmInteract with Helm charts in a Kubernetes cluster

Debugging and Troubleshooting

CommandDescription
kubectl get eventsShow cluster events
kubectl describe podShow detailed information about a pod
kubectl logsShow logs for a container
kubectl execExecute a command in a container
kubectl debugDebug a container with a new pod
kubectl run --rm -itCreate a temporary pod for debugging purposes
kubectl topShow resource usage by pods or nodes
kubectl port-forwardForward a local port to a port on a container
kubectl logs -f --previousStream logs from the previous container instance


Text © Muhammad Rehan Saeed. HTML © CSTOPICS Both provided under a MIT License.