Skip to Content
Asterrr's Handbook
Cheat sheets

Workload snippets

The YAML fragments you type most on the CKA exam, covering probes, resources, security context, scheduling, HPA, Jobs and Pod disruption budgets.

Container essentials

containers:
- name: app
  image: nginx:1.27
  command: ["sh","-c","exec nginx -g 'daemon off;'"]
  env:
  - { name: MODE, value: prod }
  - name: DB_PW
    valueFrom: { secretKeyRef: { name: db, key: pw } }
  envFrom: [{ configMapRef: { name: app } }]
  resources:
    requests: { cpu: 100m, memory: 128Mi }
    limits:   { memory: 256Mi }
  securityContext: { runAsNonRoot: true, runAsUser: 1000, allowPrivilegeEscalation: false, readOnlyRootFilesystem: true }
  volumeMounts: [{ name: data, mountPath: /data }]

Probes

startupProbe:   { httpGet: { path: /healthz, port: 8080 }, failureThreshold: 30, periodSeconds: 10 }
livenessProbe:  { httpGet: { path: /healthz, port: 8080 }, periodSeconds: 10 }
readinessProbe: { tcpSocket: { port: 8080 }, initialDelaySeconds: 5, periodSeconds: 5 }
# exec: { command: ["cat","/tmp/ready"] }   grpc: { port: 9090 }

Scheduling

nodeSelector: { disk: ssd }
tolerations:
- { key: gpu, operator: Equal, value: "true", effect: NoSchedule }
affinity:
  nodeAffinity:
    requiredDuringSchedulingIgnoredDuringExecution:
      nodeSelectorTerms:
      - matchExpressions: [{ key: zone, operator: In, values: [a, b] }]
  podAntiAffinity:
    requiredDuringSchedulingIgnoredDuringExecution:
    - labelSelector: { matchLabels: { app: web } }
      topologyKey: kubernetes.io/hostname
topologySpreadConstraints:
- { maxSkew: 1, topologyKey: topology.kubernetes.io/zone, whenUnsatisfiable: DoNotSchedule, labelSelector: { matchLabels: { app: web } } }
priorityClassName: high

Deployment strategy and PDB

strategy: { type: RollingUpdate, rollingUpdate: { maxSurge: 1, maxUnavailable: 0 } }
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata: { name: web }
spec: { minAvailable: 2, selector: { matchLabels: { app: web } } }

HPA (autoscaling/v2)

apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata: { name: web }
spec:
  scaleTargetRef: { apiVersion: apps/v1, kind: Deployment, name: web }
  minReplicas: 2
  maxReplicas: 10
  metrics:
  - type: Resource
    resource: { name: cpu, target: { type: Utilization, averageUtilization: 60 } }

Job and CronJob

spec:                      # Job
  completions: 5
  parallelism: 2
  backoffLimit: 3
  activeDeadlineSeconds: 600
  ttlSecondsAfterFinished: 300
  template: { spec: { restartPolicy: Never, containers: [...] } }
# CronJob adds: schedule, concurrencyPolicy: Forbid, successfulJobsHistoryLimit, startingDeadlineSeconds

Quota and limits

kind: ResourceQuota
spec: { hard: { pods: "10", requests.cpu: "4", requests.memory: 8Gi, limits.memory: 16Gi } }
---
kind: LimitRange
spec: { limits: [{ type: Container, default: { memory: 256Mi }, defaultRequest: { cpu: 100m, memory: 128Mi } }] }

On this page