Kubernetes documentation is written for many audiences at once, and much of it is about running clusters rather than running applications on them. If you are a developer whose team has "moved to Kubernetes", the learning curve can feel steep.
The good news is that you only need a small part of Kubernetes to ship software well, provided you understand that part properly. This guide focuses on it.
Five objects worth knowing well
Pod. The smallest unit Kubernetes runs: one or more containers that share a network namespace and storage. You rarely create Pods directly, but everything about how your container runs is defined in the Pod template.
Deployment. Manages a set of identical Pods. It keeps the requested number of replicas running and handles rolling updates and rollbacks.
Service. Gives a set of Pods a stable DNS name and virtual IP, and load-balances between them. Pods come and go; the Service name (payments.default.svc) stays.
ConfigMap and Secret. Configuration and sensitive values, kept outside the image and injected as environment variables or files. The same image can then run in every environment.
Ingress. Routes external HTTP traffic to Services by host and path, usually with TLS.
Health probes are part of your application
Kubernetes decides whether your application is healthy by asking it. Getting probes right is one of the most important things a developer can do.
- Readiness probe: "Can I receive traffic right now?" Failing readiness removes the Pod from the Service without restarting it. Use it during startup and when a critical dependency is temporarily unavailable.
- Liveness probe: "Am I stuck and in need of a restart?" Keep it simple and local. A liveness probe that checks the database will restart every Pod when the database blips, turning a small incident into a big one.
- Startup probe: for slow-starting applications, holds off the other probes until startup completes.
containers:
- name: api
image: registry.example.com/api:2.3.1
ports: [{ containerPort: 8080 }]
readinessProbe:
httpGet: { path: /ready, port: 8080 }
periodSeconds: 5
livenessProbe:
httpGet: { path: /live, port: 8080 }
initialDelaySeconds: 10
periodSeconds: 10
resources:
requests: { cpu: "250m", memory: "256Mi" }
limits: { memory: "512Mi" }Resource requests and limits
Requests tell the scheduler how much CPU and memory your container needs, and are used to place it on a node. Limits cap what it can use.
- If you exceed a memory limit, the container is killed (
OOMKilled). Set it with headroom above your real peak usage. - Exceeding a CPU limit throttles the container rather than killing it, which can cause mysterious latency. Many teams set CPU requests but no CPU limit.
- Requests that are too low lead to overloaded nodes; requests that are too high waste money. Measure real usage and adjust.
Runtimes need to know about their limits too. For example, make sure your JVM or Node.js heap size is set relative to the container's memory limit, not the node's total memory.
Shut down gracefully
During a rolling update, Kubernetes sends your container SIGTERM, waits for a grace period (30 seconds by default), and then kills it. If your application exits immediately on SIGTERM, in-flight requests fail.
// Go: stop accepting new connections, finish in-flight requests, then exit.
srv := &http.Server{Addr: ":8080", Handler: mux}
go srv.ListenAndServe()
stop := make(chan os.Signal, 1)
signal.Notify(stop, syscall.SIGTERM, os.Interrupt)
<-stop
ctx, cancel := context.WithTimeout(context.Background(), 25*time.Second)
defer cancel()
srv.Shutdown(ctx)Also fail your readiness probe as soon as shutdown begins, so the Service stops sending new traffic.
Configuration and secrets
- Read configuration from environment variables or mounted files; never bake environment-specific values into the image.
- Treat Kubernetes Secrets as sensitive but not magic. By default they are only base64-encoded. Clusters should enable encryption at rest, or integrate with an external secrets manager.
- Do not log configuration at startup if it may contain secrets.
About the dockershim deprecation
Kubernetes 1.20 deprecated "dockershim", the component that let the kubelet use Docker Engine as its container runtime. Many developers worried this meant Docker images would stop working. It does not. Images built with Docker are standard OCI images and run on containerd and CRI-O just the same. The change affects cluster operators, not the images you build or the Dockerfiles you write.
A good local workflow
You do not need a cloud cluster to develop against Kubernetes:
- kind, k3d or minikube run a small cluster on your laptop.
- Skaffold or Tilt rebuild and redeploy automatically as you edit code.
- Helm or Kustomize (built into
kubectl) template manifests for different environments.
A handful of kubectl commands cover most debugging:
kubectl get pods -l app=api # what is running?
kubectl describe pod api-7c9f8d-x2kq # events: scheduling, probes, OOM kills
kubectl logs api-7c9f8d-x2kq --previous # logs from the crashed container
kubectl port-forward svc/api 8080:80 # call the service locally
kubectl rollout undo deployment/api # roll back a bad releaseA checklist for every service
- Readiness and liveness probes that reflect real health
- Memory limit and CPU/memory requests based on measured usage
- Graceful shutdown on
SIGTERM - Configuration from environment, secrets from Secrets or a vault
- Runs as a non-root user
- Logs to stdout/stderr in a structured format
Get these right and most of what makes Kubernetes feel unpredictable goes away.
Our secure SDLC team builds services that run well on Kubernetes, and our Kubernetes security checks the platform underneath them.