Spring Boot Tutorial 0/110 lessons ~6 min read Lesson 75

    Kubernetes Basics

    Kubernetes schedules and heals containers across machines.

    Course progress0%
    Focus
    12 guided sections
    Practice signal
    Examples included
    Career prep
    Interview Q&A included

    Introduction

    Kubernetes schedules and heals containers across machines. For TechLearningPRO Orders you need a working mental model of Deployment, Service, ConfigMap, Secret, and Ingress — not every CRD in the catalog.

    A Deployment keeps N replicas of the Orders image. A Service gives them a stable DNS name. ConfigMaps hold non-secret config; Secrets hold sensitive refs. Readiness and liveness probes (Actuator) decide when traffic flows and when pods restart.

    On Boot 3 / Java 21, expose /actuator/health/readiness and /actuator/health/liveness separately so cold starts do not flap the Service.

    This lesson deploys Orders on Kubernetes before broader cloud platform choices.

    Purpose of this lesson

    Deploy Orders on Kubernetes with Deployment, Service, probes, and externalized config on Boot 3.

    Understanding the topic

    Pods are cattle; Kubernetes keeps the desired replica count alive.

    • Deployment: rolling updates and replica control for Orders pods.
    • Service: stable ClusterIP/DNS in front of changing pod IPs.
    • ConfigMap / Secret: inject config and credentials at runtime.
    • Probes: readiness gates traffic; liveness restarts stuck processes.
    • Ingress: HTTP routing and TLS at the cluster edge.

    Step-by-step explanation

    1. Create a Deployment for techlearningpro/orders:<sha> with 3 replicas.
    2. Add readiness/liveness probes to Actuator health groups.
    3. Mount non-secret config via ConfigMap; reference DB password via Secret key ref.
    4. Expose with a Service and optional Ingress host for the Orders API.

    Informative example

    Minimal Orders Deployment + Service with probes.

    yaml
    apiVersion: apps/v1
    kind: Deployment
    metadata:
    name: orders
    spec:
    replicas: 3
    selector:
    matchLabels: { app: orders }
    template:
    metadata:
    labels: { app: orders }
    spec:
    containers:
    - name: app
    image: techlearningpro/orders:1.0.0
    ports: [{ containerPort: 8080 }]
    env:
    - name: SPRING_PROFILES_ACTIVE
    value: prod
    - name: SPRING_DATASOURCE_PASSWORD
    valueFrom:
    secretKeyRef: { name: orders-db, key: password }
    readinessProbe:
    httpGet: { path: /actuator/health/readiness, port: 8080 }
    initialDelaySeconds: 10
    periodSeconds: 5
    livenessProbe:
    httpGet: { path: /actuator/health/liveness, port: 8080 }
    initialDelaySeconds: 30
    periodSeconds: 10
    ---
    apiVersion: v1
    kind: Service
    metadata:
    name: orders
    spec:
    selector: { app: orders }
    ports: [{ port: 80, targetPort: 8080 }]

    Real-world use

    TechLearningPRO once used only a liveness probe on the main health endpoint. During Flyway migrations the app was 'up' but not ready — Kubernetes kept sending traffic and checkouts 500'd. Splitting readiness vs liveness on Boot 3 Actuator groups made rollouts boring again.

    Security implications

    Cluster config is privileged territory.

    • RBAC: least privilege for deploy service accounts.
    • Do not commit Secret manifests with real values — use sealed/external secrets.
    • Lock down Actuator beyond health; never expose heapdump publicly.

    Best practices

    • Pin image digests in prod manifests.
    • Separate readiness and liveness; include DB only in readiness if policy allows.
    • Store secrets in a vault-backed Secret provider — never in git.

    Common mistakes

    • Baking environment-specific YAML into the image.
    • Single probe that restarts pods still warming caches.
    • Missing resource requests so the scheduler packs Orders onto saturated nodes.

    Advanced interview questions

    Interview Prep

    Practice concise answers, then expand each card for the explanation.

    3 questions
    1BeginnerQuestionDeployment vs Service?+

    Answer

    Deployment manages pod replicas and rollouts; Service provides stable networking to those pods.
    2IntermediateQuestionWhy split readiness and liveness for Spring Boot?+

    Answer

    Readiness stops traffic during warmup; liveness restarts only when the process is truly wedged — mixing them causes restart storms.
    3BeginnerQuestionWhere should DB passwords live?+

    Answer

    In Kubernetes Secrets (ideally vault-synced), injected as env or files — never baked into the image or committed in plaintext.

    Hands-on exercise

    Lab. Apply the Deployment/Service above to a local cluster (kind/minikube). Break readiness by pointing the probe at a missing path and observe the Service endpoint emptying. Fix probes and confirm three ready pods.

    Summary

    Kubernetes basics get TechLearningPRO Orders scheduled and healed. Next: choose a cloud deployment style that matches team maturity.

    Ready to mark this lesson complete?Track your journey across the entire course.