kubernetes
Kubernetes Deployment YAML Generator
Generate a Kubernetes Deployment and ClusterIP Service YAML with resource requests/limits, liveness/readiness probes, and configurable replicas, image, and environment variables.
Kubernetes Deployment Patterns
A Deployment manages a ReplicaSet which manages Pods. This three-level hierarchy provides rolling updates, rollback, and self-healing.
Resource Sizing
request = what you need on average
limit = what you allow at peak (CPU: 4–8× request, memory: 1.5–2× request)Probe Configuration
livenessProbe:
httpGet:
path: /healthz
port: 3000
initialDelaySeconds: 10 # wait for app to start
periodSeconds: 15 # check every 15s
failureThreshold: 3 # kill after 3 failuresreadinessProbe: httpGet: path: /ready port: 3000 initialDelaySeconds: 5 periodSeconds: 10 ```
Rolling Update Strategy
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1 # create 1 extra pod during update
maxUnavailable: 0 # never remove a pod before new one is readyPod Disruption Budget
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: my-app-pdb
spec:
minAvailable: 1
selector:
matchLabels:
app: my-appFrequently Asked Questions
What's the difference between resource requests and limits?
Requests are what Kubernetes uses to schedule the pod — it guarantees that much CPU/memory is available. Limits are the maximum — exceeding CPU limits causes throttling, exceeding memory limits kills the pod (OOMKilled). Always set requests; set limits with care. Never set CPU limits to 0 or omit them on shared clusters.
What should my liveness vs readiness probe check?
Readiness: is the app ready to serve traffic? Check if DB connections are established, caches are warmed. If readiness fails, traffic is removed but the pod keeps running. Liveness: is the app stuck or deadlocked? If liveness fails, the pod is killed and restarted. Use different endpoints: /ready and /healthz.
Why use 2 replicas minimum?
A single replica means zero availability during node maintenance (kubectl drain) or pod eviction. With 2 replicas and a PodDisruptionBudget of minAvailable: 1, Kubernetes ensures at least one pod is always running during disruptions.
What is IfNotPresent vs Always for image pull policy?
IfNotPresent pulls the image only if not already cached on the node — faster for stable tags like v1.2.3. Always pulls on every pod start — required if you use mutable tags like latest. For production, use immutable image tags (SHA or version) with IfNotPresent.