Devops

Kubernetes Cheatsheet

Kubernetes orchestrates containers at scale. This cheatsheet covers kubectl commands and core object definitions.

Kubernetes is a container orchestration platform for deploying, scaling, and managing containerized apps. This cheatsheet covers kubectl and core objects.

Cluster Info

Inspect the cluster.

kubectl cluster-info
kubectl get nodes
kubectl config get-contexts
kubectl config use-context <name>

Pods

The smallest deployable unit.

kubectl get pods                 # list pods
kubectl get pods -A              # all namespaces
kubectl describe pod <name>      # details
kubectl logs <name>              # view logs
kubectl logs -f <name>           # follow logs
kubectl exec -it <name> -- sh    # shell into pod

Deployments

Manage replicated apps.

kubectl get deployments
kubectl scale deploy/web --replicas=3
kubectl rollout status deploy/web
kubectl rollout undo deploy/web
kubectl set image deploy/web app=img:v2

Applying Config

Declarative management.

kubectl apply -f manifest.yaml
kubectl delete -f manifest.yaml
kubectl diff -f manifest.yaml

Deployment YAML

Define a deployment.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: web
spec:
  replicas: 3
  selector:
    matchLabels: { app: web }
  template:
    metadata:
      labels: { app: web }
    spec:
      containers:
        - name: web
          image: nginx:latest
          ports:
            - containerPort: 80

Services

Expose pods on the network.

kubectl get services
kubectl expose deploy/web --port=80 --type=LoadBalancer
kubectl port-forward svc/web 8080:80

Namespaces

Isolate resources.

kubectl get namespaces
kubectl create namespace staging
kubectl get pods -n staging

Debugging

Diagnose problems.

kubectl describe <resource> <name>
kubectl get events --sort-by=.lastTimestamp
kubectl top pods

Kubernetes standardizes how you run containers in production. Learn pods, deployments, and services first, then explore ingress, ConfigMaps, and Helm.

For full documentation, see https://kubernetes.io/docs/

Promote your content

Reach over 400,000 developers and grow your brand.

Join our developer community

Hang out with over 4,500 developers and share your knowledge.