Skip to content

Kubectl

Basic Commands

Command Description
kubectl get List resources
kubectl describe Show detailed information about a resource
kubectl create Create a resource from a file or standard input
kubectl apply Apply a configuration to a resource
kubectl delete Delete resources
kubectl exec Execute a command in a container
kubectl logs Show logs for a container
kubectl port-forward Forward a local port to a port on a container
kubectl proxy Run a proxy to the Kubernetes API server
kubectl version Show client and server versions

Resource Types

Command Description
kubectl run Run a container in a pod
kubectl expose Expose a deployment, service, or pod as a service
kubectl scale Scale a deployment or replicaset
kubectl autoscale Create an autoscaler for a deployment
kubectl rollout Manage a rollout of a deployment
kubectl config Modify kubeconfig files
kubectl cluster-info Display cluster information
kubectl cordon Mark a node as unschedulable
kubectl drain Drain a node in preparation for maintenance
kubectl taint Taint a node with a key/value pair

Advanced Commands

Command Description
kubectl apply -f Apply a configuration file
kubectl exec -it Execute a command in a container with a terminal session
kubectl logs -f Stream logs for a container
kubectl port-forward Forward a local port to a port on a container
kubectl proxy Run a proxy to the Kubernetes API server
kubectl rollout status Show the status of a rollout
kubectl rollout history Show the history of a rollout
kubectl diff Show differences between the running and desired state of a resource
kubectl edit Edit a resource in the default editor
kubectl label Add or remove labels from a resource
kubectl annotate Add or remove annotations from a resource
kubectl apply --dry-run Preview changes to a resource without applying them
kubectl explain Show documentation for a resource or field
kubectl auth can-i Check if the current user can perform a specific action on a resource

Plugins

Command Description
kubectl krew Install and manage kubectl plugins
kubectl tree Show a resource hierarchy as a tree
kubectl ctx Switch between kubectl contexts
kubectl ns Switch between Kubernetes namespaces
kubectl neat Reformat resource YAML for readability
kubectl view-secret View Kubernetes secrets in a decoded format
kubectl who-can Show who can perform a specific action on a resource
kubectl crd Show custom resource definitions
kubectl kustomize Create a customized Kubernetes configuration from a base configuration and patches
kubectl helm Interact with Helm charts in a Kubernetes cluster

Debugging and Troubleshooting

Command Description
kubectl get events Show cluster events
kubectl describe pod Show detailed information about a pod
kubectl logs Show logs for a container
kubectl exec Execute a command in a container
kubectl debug Debug a container with a new pod
kubectl run --rm -it Create a temporary pod for debugging purposes
kubectl top Show resource usage by pods or nodes
kubectl port-forward Forward a local port to a port on a container
kubectl logs -f --previous Stream logs from the previous container instance