Kubernetes Basics for Backend Developers

Understand pods, deployments, services and config well enough to ship and debug your service on a cluster.

Advanced · about 10 hours · difficulty 4/5

Learn first: Containers with Docker

Kubernetes (K8s) runs containers across a cluster of machines, restarting them when they crash, scaling them and routing traffic to them. As a backend developer you usually do not run the cluster, but you do need to deploy to it and debug your service there.

The objects you will touch

  • Pod: one or more containers scheduled together; the smallest unit. Pods are disposable.
  • Deployment: declares how many replicas of a pod should run and rolls out new versions gradually.
  • Service: a stable internal address and load balancer in front of a set of pods.
  • Ingress / Gateway: routes external HTTP traffic to services.
  • ConfigMap and Secret: configuration and credentials injected as environment variables or files.
  • HorizontalPodAutoscaler: adds or removes replicas based on CPU or custom metrics.

Making your app cluster-friendly

  • Expose liveness (am I stuck?) and readiness (can I take traffic?) probes; they are different questions.
  • Set resource requests and limits so the scheduler can place pods and one service cannot starve others.
  • Handle SIGTERM gracefully: stop accepting new work, finish in-flight requests, then exit.
  • Keep pods stateless; state lives in databases and object storage.

Daily commands

kubectl get pods, kubectl logs, kubectl describe pod (look at Events), kubectl rollout status and kubectl rollout undo cover most debugging.

Is it worth it?

For a small team, a PaaS or managed container service (Cloud Run, ECS, Fly.io, Render) is often simpler. Kubernetes pays off with many services and a platform team.

You are ready to move on when you can deploy your container to a local cluster (kind or minikube) with probes and limits, scale it, and roll back a bad release.

Key concepts

  • Pods and Deployments
  • Services and Ingress
  • ConfigMaps and Secrets
  • Liveness and readiness probes
  • Resource requests and limits
  • Graceful shutdown on SIGTERM
  • Horizontal Pod Autoscaler
  • Helm charts

Mini project

Deploy your API and Postgres to a kind cluster with a Deployment, Service, Ingress and Secret, add probes, then perform and roll back a rolling update.

Check yourself

What is the difference between a failing liveness probe and a failing readiness probe, and what does Kubernetes do in each case?

Free resources