Skip to main content

Kubectl Cheats

Cheat sheet for kubectl commands.

info

This page was automatically generated from a navi cheat file available at difranca/navi-cheats.
Navi is an interactive cheatsheet tool for the command-line. To learn more about it, visit denisidoro/navi.


Configโ€‹

Set which Kubectl cluster kubectl communicates with and modify configuration information.

CommandDescription
kubectl config viewShow Merged kubeconfig settings
kubectl config get-contextsDisplay list of contexts
kubectl config current-contextDisplay the current-context
kubectl config use-context {context_name}Set the default context to my-cluster-name

Createโ€‹

Manage applications through files.

CommandDescription
kubectl create -f {filename}Create resource(s) from file
kubectl apply -f {filename}Create or modify resource(s) from file

List Resourcesโ€‹

List resources from cluster.

CommandDescription
kubectl get {resource} -n {namespace}List namespace-scoped resources
kubectl get {resource} -n {namespace} -o wideList namespace-scoped resources with extra details
kubectl get {resource}List cluster-scoped resources

Describe & Inspectโ€‹

View detailed information about resources.

CommandDescription
kubectl describe {resource} -n {namespace}Describe a resource in a namespace
kubectl get {resource} -n {namespace} -o yamlGet a resource as YAML
kubectl get pod {pod} -n {namespace} -o yamlGet a specific pod as YAML
kubectl get events -n {namespace} --sort-by='.lastTimestamp'Get events sorted by last timestamp

Logsโ€‹

View container logs.

CommandDescription
kubectl logs {pod} -n {namespace}Show logs for a pod
kubectl logs -f {pod} -n {namespace}Follow (stream) logs for a pod
kubectl logs --previous {pod} -n {namespace}Show logs for a pod from the previous container instance
kubectl logs --tail={number_of_lines} {pod} -n {namespace}Show logs for the last N lines

Execโ€‹

Execute commands inside containers.

CommandDescription
kubectl exec -it {pod} -n {namespace} -- /bin/shOpen a shell in a pod
kubectl exec {pod} -n {namespace} -- {command}Run a command in a pod

Deleteโ€‹

Delete resources from cluster.

CommandDescription
kubectl delete -f {filename}Delete resource(s) from file
kubectl delete pod {pod} -n {namespace}Delete a pod
kubectl delete {resource} {name} -n {namespace}Delete a resource by name

Scaleโ€‹

Scale resource replicas.

CommandDescription
kubectl scale deployment {deployment} -n {namespace} --replicas={number_of_replicas}Scale a deployment to a number of replicas

Port Forwardโ€‹

Forward local ports to pods or services.

CommandDescription
kubectl port-forward {pod} {local_port}:{remote_port} -n {namespace}Forward a local port to a pod port
kubectl port-forward svc/{service} {local_port}:{remote_port} -n {namespace}Forward a local port to a service port

Administrationโ€‹

Interacting with nodes and cluster.

CommandDescription
kubectl cordon {node_name}Mark node as unschedulable
kubectl uncordon {node_name}Mark my-node as schedulable
kubectl drain {node_name}Drain node in preparation for maintenance
kubectl cluster-infoDisplay cluster information