Careeroza
Kubernetes Basics
Why Kubernetes?
Docker Compose runs containers on one machine. In production ShopEase runs 30+ containers on many machines, and someone must restart crashed containers, spread them across machines, scale them, and roll out new versions without downtime. Kubernetes (K8s) does this: you describe the desired state in YAML, and Kubernetes keeps the cluster in that state.
kubectl apply -f order-service.yaml
|
+----------v-----------+
| Control plane | API server, scheduler,
| (desired state) | controllers, etcd
+----------+-----------+
+------------------+------------------+
v v v
+---------+ +---------+ +---------+
| Node 1 | | Node 2 | | Node 3 |
| order-1 | | order-2 | | order-3 | <- Pods
| pay-1 | | gateway | | pay-2 |
+---------+ +---------+ +---------+Core Objects
| Object | What it is | ShopEase example |
|---|---|---|
| Pod | One or more containers that run together; the smallest unit | one order-service container |
| Deployment | Keeps N identical Pods running and rolls out new versions | order-service, replicas: 3 |
| Service | A stable DNS name and virtual IP that load-balances to Pods | http://order-service |
| ConfigMap | Non-secret configuration as key/values or files | Kafka address, feature flags |
| Secret | Sensitive values (passwords, keys) | DB password, Razorpay secret |
| Ingress | HTTP(S) entry from the internet, routes by host/path, TLS | api.shopease.in → api-gateway |
| Namespace | A folder that groups and isolates objects | shopease, observability |
| HorizontalPodAutoscaler | Changes replicas based on CPU or custom metrics | 3 → 10 order Pods during a sale |
What Changes for Spring Cloud?
- Service discovery: Kubernetes Services + DNS replace Eureka. order-service calls
http://payment-serviceand the Service load-balances. (Spring Cloud Kubernetes can also plug intoDiscoveryClient.) - Configuration: ConfigMaps and Secrets (as environment variables or files) often replace Config Server.
- Health: Actuator liveness and readiness groups become Kubernetes probes.
- Still useful: Spring Cloud Gateway (routing, auth, rate limits), OpenFeign, Resilience4j, Micrometer Tracing.
Example
Everyday kubectl commands:
kubectl get pods -n shopease
kubectl logs -f deploy/order-service -n shopease
kubectl describe pod order-service-6d8f7c9b5-x2kqp -n shopease
kubectl exec -it deploy/order-service -n shopease -- sh
kubectl port-forward svc/order-service 8082:80 -n shopeaseExample output
NAME READY STATUS RESTARTS AGE api-gateway-7b9c6d5f4-hk2lm 1/1 Running 0 2d order-service-6d8f7c9b5-x2kqp 1/1 Running 0 3h order-service-6d8f7c9b5-q8wzr 1/1 Running 0 3h order-service-6d8f7c9b5-m4tnv 1/1 Running 0 3h payment-service-5c4b8a7d6-7rjpd 1/1 Running 1 1d product-service-84f9d6c7b-zt5wq 1/1 Running 0 1d