Kubernetes Basics
Kubernetes schedules and heals containers across machines.
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
- Create a Deployment for
techlearningpro/orders:<sha>with 3 replicas. - Add readiness/liveness probes to Actuator health groups.
- Mount non-secret config via ConfigMap; reference DB password via Secret key ref.
- Expose with a Service and optional Ingress host for the Orders API.
Informative example
Minimal Orders Deployment + Service with probes.
apiVersion: apps/v1kind: Deploymentmetadata:name: ordersspec:replicas: 3selector:matchLabels: { app: orders }template:metadata:labels: { app: orders }spec:containers:- name: appimage: techlearningpro/orders:1.0.0ports: [{ containerPort: 8080 }]env:- name: SPRING_PROFILES_ACTIVEvalue: prod- name: SPRING_DATASOURCE_PASSWORDvalueFrom:secretKeyRef: { name: orders-db, key: password }readinessProbe:httpGet: { path: /actuator/health/readiness, port: 8080 }initialDelaySeconds: 10periodSeconds: 5livenessProbe:httpGet: { path: /actuator/health/liveness, port: 8080 }initialDelaySeconds: 30periodSeconds: 10---apiVersion: v1kind: Servicemetadata:name: ordersspec: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.
1BeginnerQuestionDeployment vs Service?+
Answer
2IntermediateQuestionWhy split readiness and liveness for Spring Boot?+
Answer
3BeginnerQuestionWhere should DB passwords live?+
Answer
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.