xutil.dev
Login

Kubernetes (kubectl) Cheatsheet

Quick reference for kubectl commands covering pods, deployments, services, ConfigMaps, namespaces, nodes, debugging, and context switching

67 commands

kubectl get pods

List all pods

kubectl get pods -A

List pods in all namespaces

kubectl get pods -o wide

List pods with extended info

kubectl get pods -w

Watch pods in real-time

kubectl describe pod

Show detailed pod information

kubectl run

Create and run a pod

kubectl delete pod

Delete a pod

kubectl delete pod --force

Force delete a pod

kubectl get pods -l

Filter pods by label

kubectl get pod -o yaml

Show pod YAML definition

kubectl get deployments

List all deployments

kubectl create deployment

Create a deployment

kubectl apply -f

Apply a manifest file

kubectl delete -f

Delete resources defined in manifest

kubectl scale

Scale deployment replicas

kubectl rollout status

Check rollout status

kubectl rollout history

Show rollout history

kubectl rollout undo

Rollback a deployment

kubectl rollout restart

Restart a deployment

kubectl set image

Update container image

kubectl autoscale

Set up Horizontal Pod Autoscaler

kubectl get svc

List all services

kubectl expose

Expose resource as a service

kubectl get ingress

List all ingresses

kubectl describe svc

Show detailed service info

kubectl delete svc

Delete a service

kubectl get endpoints

List endpoints

kubectl port-forward svc

Port-forward to a service

kubectl get configmaps

List ConfigMaps

kubectl create configmap

Create a ConfigMap

kubectl get secrets

List secrets

kubectl create secret generic

Create a generic secret

kubectl create secret tls

Create a TLS secret

kubectl describe configmap

Describe a ConfigMap

kubectl get secret -o jsonpath

Decode and display secret value

kubectl edit configmap

Edit a ConfigMap

kubectl get namespaces

List all namespaces

kubectl create namespace

Create a namespace

kubectl delete namespace

Delete a namespace

kubectl config set-context --namespace

Set default namespace

kubectl get all -n

List all resources in namespace

kubectl apply -n

Apply manifest in namespace

kubectl get nodes

List all nodes

kubectl describe node

Show detailed node info

kubectl top nodes

Show node resource usage

kubectl top pods

Show pod resource usage

kubectl cordon

Mark node as unschedulable

kubectl uncordon

Mark node as schedulable

kubectl drain

Drain node for maintenance

kubectl taint nodes

Add taint to node

kubectl logs

View pod logs

kubectl logs -f

Stream pod logs in real-time

kubectl logs --previous

View previous container logs

kubectl logs -c

View specific container logs

kubectl exec -it

Execute interactive command in pod

kubectl port-forward

Port-forward to a pod

kubectl get events

List cluster events

kubectl debug

Add ephemeral debug container

kubectl explain

Explain resource fields

kubectl api-resources

List available API resources

kubectl config get-contexts

List available contexts

kubectl config current-context

Show current context

kubectl config use-context

Switch context

kubectl config set-context

Set a context

kubectl cluster-info

Display cluster info

kubectl config view

View kubeconfig

kubectl version

Show client and server version