AI Generate Kubernetes docs instantly

Kubernetes Cheat Sheet

Quick reference guide with copy-paste ready code snippets

Try DocuWriter Free

Pods

3 snippets

Smallest deployable units

Pod YAML

apiVersion: v1
kind: Pod
metadata:
  name: my-app
  labels:
    app: my-app
spec:
  containers:
  - name: app
    image: nginx:1.25
    ports:
    - containerPort: 80
    resources:
      requests:
        cpu: "100m"
        memory: "128Mi"
      limits:
        cpu: "500m"
        memory: "256Mi"

Multi-container

spec:
  containers:
  - name: app
    image: my-app:latest
  - name: sidecar
    image: fluentd:latest
    volumeMounts:
    - name: logs
      mountPath: /var/log

Init Container

spec:
  initContainers:
  - name: wait-for-db
    image: busybox
    command: ['sh', '-c', 'until nc -z db 5432; do sleep 2; done']

Deployments

3 snippets

Manage replica sets and rollouts

Deployment YAML

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app
spec:
  replicas: 3
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
      - name: app
        image: my-app:1.0
        ports:
        - containerPort: 8080

Rolling Update

spec:
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 1
      maxSurge: 1

Rollout Commands

kubectl rollout status deployment/my-app
kubectl rollout history deployment/my-app
kubectl rollout undo deployment/my-app
kubectl rollout undo deployment/my-app --to-revision=2

Services

3 snippets

Network access to pods

ClusterIP

apiVersion: v1
kind: Service
metadata:
  name: my-app
spec:
  selector:
    app: my-app
  ports:
  - port: 80
    targetPort: 8080

LoadBalancer

spec:
  type: LoadBalancer
  selector:
    app: my-app
  ports:
  - port: 80
    targetPort: 8080

Ingress

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: my-ingress
spec:
  rules:
  - host: app.example.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: my-app
            port:
              number: 80

Tired of looking up syntax?

DocuWriter.ai generates documentation and explains code using AI.

Try Free

ConfigMaps & Secrets

3 snippets

Externalize configuration

ConfigMap

apiVersion: v1
kind: ConfigMap
metadata:
  name: app-config
data:
  DATABASE_URL: "postgres://db:5432/mydb"
  LOG_LEVEL: "info"

Secret

apiVersion: v1
kind: Secret
metadata:
  name: app-secrets
type: Opaque
stringData:
  DB_PASSWORD: "supersecret"
  API_KEY: "abc123"

Mount as Env

env:
- name: DATABASE_URL
  valueFrom:
    configMapKeyRef:
      name: app-config
      key: DATABASE_URL
- name: DB_PASSWORD
  valueFrom:
    secretKeyRef:
      name: app-secrets
      key: DB_PASSWORD

kubectl Commands

4 snippets

Essential CLI commands

Get & Describe

kubectl get pods -n default
kubectl get svc,deploy,ingress
kubectl describe pod my-app-xyz
kubectl get pods -o wide --all-namespaces

Logs & Exec

kubectl logs my-app-xyz
kubectl logs -f my-app-xyz -c sidecar
kubectl exec -it my-app-xyz -- /bin/sh
kubectl port-forward svc/my-app 8080:80

Apply & Delete

kubectl apply -f deployment.yaml
kubectl apply -f ./k8s/
kubectl delete pod my-app-xyz
kubectl delete -f deployment.yaml

Scale & Debug

kubectl scale deployment/my-app --replicas=5
kubectl top pods
kubectl get events --sort-by=.metadata.creationTimestamp
kubectl debug pod/my-app -it --image=busybox

Helm

3 snippets

Package manager for Kubernetes

Install & Upgrade

helm install my-release ./chart
helm upgrade my-release ./chart -f values.yaml
helm upgrade --install my-release ./chart

Common Commands

helm list
helm status my-release
helm history my-release
helm rollback my-release 1
helm uninstall my-release

Values

# values.yaml
replicaCount: 3
image:
  repository: my-app
  tag: "1.0"
resources:
  limits:
    cpu: 500m
    memory: 256Mi

More Cheat Sheets

FAQ

Frequently asked questions

What is a Kubernetes cheat sheet?

A Kubernetes cheat sheet is a quick reference guide containing the most commonly used syntax, functions, and patterns in Kubernetes. It helps developers quickly look up syntax without searching through documentation.

How do I learn Kubernetes quickly?

Start with the basics: variables, control flow, and functions. Use this cheat sheet as a reference while practicing. For faster learning, try DocuWriter.ai to automatically explain code and generate documentation as you learn.

What are the most important Kubernetes concepts?

Key Kubernetes concepts include variables and data types, control flow (if/else, loops), functions, error handling, and working with data structures like arrays and objects/dictionaries.

How can I document my Kubernetes code?

Use inline comments for complex logic, docstrings for functions and classes, and README files for projects. DocuWriter.ai can automatically generate professional documentation from your Kubernetes code using AI.

Related resources

Stop memorizing. Start shipping.

Generate Kubernetes Docs with AI

DocuWriter.ai automatically generates comments, docstrings, and README files for your code.

Auto-generate comments
Create README files
Explain complex code
API documentation
Start Free - No Credit Card

Join 33,700+ developers saving hours every week