Kubernetes Cheatsheet

Complete kubectl command reference. Search, filter by category, and click to copy.

Kubernetes Cheatsheet

Essential kubectl commands for container orchestration

97

Commands

8

Categories

0

Favorites

14

Sections

Cluster
Cluster Info
kubectl cluster-info

Display cluster info

kubectl version

Show kubectl version

kubectl config view

Show kubeconfig

kubectl config get-contexts

List contexts

kubectl config use-context [name]

Switch context

kubectl config current-context

Show current context

kubectl get nodes

List all nodes

kubectl get nodes -o wide

Nodes with details

kubectl describe node [name]

Node details

kubectl top nodes

Node resource usage

Cluster
Namespaces
kubectl get ns

List namespaces

kubectl create ns [name]

Create namespace

kubectl delete ns [name]

Delete namespace

kubectl config set-context --current --namespace=[ns]

Set default namespace

Pods
Pod Management
kubectl get pods

List pods

kubectl get pods -A

All namespaces

kubectl get pods -o wide

With node info

kubectl get pods -w

Watch pods

kubectl get pods -l app=[label]

Filter by label

kubectl describe pod [name]

Pod details

kubectl logs [pod]

Pod logs

kubectl logs -f [pod]

Follow logs

kubectl logs [pod] -c [container]

Container logs

kubectl logs --tail=100 [pod]

Last 100 lines

kubectl exec -it [pod] -- bash

Shell into pod

kubectl exec [pod] -- [cmd]

Run command

kubectl cp [pod]:/path /local

Copy from pod

kubectl delete pod [name]

Delete pod

kubectl run [name] --image=[img]

Run pod

kubectl port-forward [pod] 8080:80

Port forward

Deployments
Deployment Operations
kubectl get deploy

List deployments

kubectl get deploy -o wide

With details

kubectl describe deploy [name]

Deployment details

kubectl create deploy [name] --image=[img]

Create deployment

kubectl scale deploy [name] --replicas=3

Scale replicas

kubectl set image deploy/[name] [container]=[img]

Update image

kubectl rollout status deploy/[name]

Rollout status

kubectl rollout history deploy/[name]

Rollout history

kubectl rollout undo deploy/[name]

Rollback

kubectl rollout restart deploy/[name]

Restart deployment

kubectl delete deploy [name]

Delete deployment

kubectl edit deploy [name]

Edit deployment

Deployments
Other Workloads
kubectl get rs

List ReplicaSets

kubectl get ds

List DaemonSets

kubectl get sts

List StatefulSets

kubectl get jobs

List Jobs

kubectl get cronjobs

List CronJobs

Services
Service Management
kubectl get svc

List services

kubectl get svc -o wide

With details

kubectl describe svc [name]

Service details

kubectl expose deploy [name] --port=80

Expose deployment

kubectl expose deploy [name] --type=NodePort --port=80

NodePort service

kubectl expose deploy [name] --type=LoadBalancer --port=80

LoadBalancer

kubectl delete svc [name]

Delete service

kubectl port-forward svc/[name] 8080:80

Port forward

Services
Ingress
kubectl get ing

List ingresses

kubectl describe ing [name]

Ingress details

kubectl get ing -A

All namespaces

Config
ConfigMaps & Secrets
kubectl get cm

List ConfigMaps

kubectl describe cm [name]

ConfigMap details

kubectl create cm [name] --from-literal=key=val

Create ConfigMap

kubectl create cm [name] --from-file=[file]

From file

kubectl get secrets

List secrets

kubectl describe secret [name]

Secret details

kubectl create secret generic [name] --from-literal=key=val

Create secret

kubectl get secret [name] -o jsonpath='{.data}'

Get secret data

Storage
Persistent Storage
kubectl get pv

List PersistentVolumes

kubectl get pvc

List PersistentVolumeClaims

kubectl describe pv [name]

PV details

kubectl describe pvc [name]

PVC details

kubectl get sc

List StorageClasses

RBAC
Access Control
kubectl get sa

List ServiceAccounts

kubectl get roles

List Roles

kubectl get rolebindings

List RoleBindings

kubectl get clusterroles

List ClusterRoles

kubectl get clusterrolebindings

List ClusterRoleBindings

kubectl auth can-i [verb] [resource]

Check permissions

kubectl auth can-i --list

List all permissions

Advanced
Resource Management
kubectl apply -f [file.yaml]

Apply config

kubectl delete -f [file.yaml]

Delete from file

kubectl create -f [file.yaml]

Create from file

kubectl get all

List all resources

kubectl get all -A

All namespaces

kubectl api-resources

List API resources

kubectl explain [resource]

Resource docs

Advanced
Labels & Annotations
kubectl label pod [name] key=value

Add label

kubectl label pod [name] key-

Remove label

kubectl annotate pod [name] key=value

Add annotation

kubectl get pods --show-labels

Show labels

Advanced
Node Operations
kubectl cordon [node]

Mark unschedulable

kubectl uncordon [node]

Mark schedulable

kubectl drain [node]

Drain node

kubectl taint node [node] key=val:NoSchedule

Add taint

Advanced
Debugging
kubectl get events

List events

kubectl get events --sort-by='.lastTimestamp'

Sorted events

kubectl top pods

Pod resource usage

kubectl describe pod [name] | grep -A5 Events

Pod events

Quick Reference

Get

kubectl get [resource]

Describe

kubectl describe [res]

Logs

kubectl logs [pod]

Exec

kubectl exec -it [pod] -- bash

About Kubernetes

Kubernetes (K8s) is an open-source container orchestration platform that automates deployment, scaling, and management of containerized applications.