BBackend CourseLeroy Labs
0/0
Search the course

Kubernetes essentials for backend engineers

Pods, Deployments, Services, Ingress, ConfigMaps and Secrets, probes, resource requests and limits, HPA autoscaling, rolling updates, and how your Docker and Actuator setup maps onto it.

● advanced

Why Kubernetes

You’ve deployed with compose on a VM, Fargate and Render. Kubernetes is the industry-standard orchestrator. You declare the desired state (“3 replicas of image X, healthy, reachable at /api”), and the control plane keeps reality matching it: rescheduling crashed pods, rolling out updates and scaling.

Core objects

Object What it is Your-world equivalent
Pod One or more containers sharing a network and volumes One docker run
Deployment Manages ReplicaSets: replicas, rolling updates, rollback ECS service
Service A stable virtual IP and DNS name in front of pods Compose service name
Ingress / Gateway API HTTP routing and TLS from outside ALB / Cloudflare Tunnel
ConfigMap / Secret Config and secrets as env vars or files .env, SSM
HPA Autoscaling on CPU or custom metrics ECS autoscaling
Job / CronJob Run-to-completion and scheduled work @Scheduled + ShedLock alternative
StatefulSet + PVC Stable identity and storage RDS (prefer managed DBs anyway)

A Deployment for a Spring Boot app

apiVersion: apps/v1
kind: Deployment
metadata: { name: sperotek-api }
spec:
  replicas: 3
  strategy: { rollingUpdate: { maxUnavailable: 0, maxSurge: 1 } }   # zero-downtime
  selector: { matchLabels: { app: sperotek-api } }
  template:
    metadata: { labels: { app: sperotek-api } }
    spec:
      securityContext: { runAsNonRoot: true, runAsUser: 1001 }
      containers:
        - name: api
          image: ghcr.io/you/sperotek-api:3f9c2ab          # git SHA tag
          ports: [{ containerPort: 8080 }]
          envFrom: [{ secretRef: { name: sperotek-secrets } }, { configMapRef: { name: sperotek-config } }]
          resources:
            requests: { cpu: "500m", memory: "1Gi" }      # used for scheduling
            limits:   { memory: "1Gi" }                   # OOM-killed above this; MaxRAMPercentage=75 applies
          readinessProbe: { httpGet: { path: /actuator/health/readiness, port: 8080 }, periodSeconds: 5 }
          livenessProbe:  { httpGet: { path: /actuator/health/liveness,  port: 8080 }, initialDelaySeconds: 30 }
          lifecycle: { preStop: { exec: { command: ["sleep", "10"] } } }   # let the LB deregister first
      terminationGracePeriodSeconds: 45

Spring Boot detects Kubernetes and enables the liveness and readiness probe groups automatically, which ties directly to the Observability and Graceful Shutdown lessons.

Concepts to know

  • Requests vs limits. CPU limits cause throttling (many teams set only CPU requests). The memory limit is a hard kill.
  • Rolling update + readiness gives zero-downtime deploys.
  • Namespaces, RBAC, NetworkPolicies for isolation.
  • Helm / Kustomize for packaging and environment overlays.
  • GitOps (Argo CD, Flux): the cluster pulls its desired state from git.
  • Managed clusters: EKS, GKE, AKS, DigitalOcean, or k3s for small setups.

Check yourself

1. Which probe failing removes a pod from Service endpoints without restarting it?
2. Container exceeds its memory limit. Result?