Kubernetes Networking, Services, Scaling & Rolling Updates
පිටුව 17: Kubernetes Networking, Services, Autoscaling සහ Zero-Downtime Rolling Updates
Pods වල IPs නිතර වෙනස් වෙන ප්රශ්නය විසඳන Services (ClusterIP, NodePort, LoadBalancer), CoreDNS, සහ Users ලට නොදැනී Update කරන Rolling Updates.
Lab 17 of 20 · K8s Services & Scaling · 5 hands-on activities · bilingual (English + සිංහල)
පිටුව 17: Kubernetes Networking, Services, Autoscaling සහ Zero-Downtime Rolling Updates
Pods වල IPs නිතර වෙනස් වෙන ප්රශ්නය විසඳන Services (ClusterIP, NodePort, LoadBalancer), CoreDNS, සහ Users ලට නොදැනී Update කරන Rolling Updates.
💡 සරල සිංහලෙන්: Kubernetes Service එකක් සහ Rolling Update එකක් කියන්නේ මොකක්ද?
Receptionist කෙනෙක්ගේ උපමාව (The Service):
Pod එකක් මැරිලා අලුත් එකක් එනකොට IP එක වෙනස් වෙනවා. එතකොට පිටින් එන මිනිස්සුන්ට හොයාගන්න බෑ. Service එක කියන්නේ හෝටලයේ Receptionist කෙනෙක් වගේ. කාමරේ ඉන්න කෙනා මාරු වුණත් Receptionist ගේ අංකය ස්ථාවරයි. පාරිභෝගිකයා කතා කරන්නේ Receptionist ට, එයා නියම Pod එකට කෝල් එක හරවනවා.
Zero-Downtime Rolling Update:
වෙබ් සයිට් එකේ අලුත් Version එකක් දාද්දි සයිට් එක වහන්න ඕන නෑ! පරණ Pods 3ක් තියෙනවා නම්, මුලින්ම අලුත් Pod එකක් On කරලා, පරණ එකක් Off කරනවා. මේ විදියට එකින් එක මාරු කරන නිසා පාරිභෝගිකයාට කිසිම බාධාවක් වෙන්නේ නෑ.
Architectural Foundation & Systems Diagram
Pods are ephemeral. When a pod crashes or is rescheduled, it receives a brand new IP address. You cannot hardcode pod IPs! To route traffic reliably, Kubernetes provides Services.
-
🌐 Service Types — • ClusterIP: Default internal IP accessible only inside the cluster.
• NodePort: Exposes port (30000-32767) on every node.
• LoadBalancer: Provisions a real AWS/GCP external Load Balancer. -
📈 Scaling Replicas (HPA) — Scale workloads with
kubectl scale deployment web-app --replicas=10, or configure the Horizontal Pod Autoscaler (HPA) to dynamically scale based on CPU/RAM saturation. -
🔄 Zero-Downtime Rolling Updates — When deploying a new version, Kubernetes spins up new version pods before terminating old pods. Customers experience 0 seconds of downtime! If a bug is caught, roll back instantly:
kubectl rollout undo.
Step-by-step practical lab
Step 01: Expose Deployment as a NodePort Service
සිංහලෙන් — Deployment එකට පිටතින් ඇතුල් විය හැකි NodePort Service එකක් සාදමු.
Create a stable network service abstraction with a dedicated NodePort accessible from outside the cluster.
kubectl expose deployment web-app --port=80 --target-port=80 --type=NodePortexpose: Pods සඳහා ස්ථාවර IP එකක් සහ Port එකක් ලබාදෙන Service එකක් සාදයි.--type=NodePort: Cluster එකේ සෑම Node එකකම 30000-32767 අතර port එකක් විවෘත කරයි.
Expected output
service/web-app exposedSRE Tip: Pod IPs are temporary and change on crash; Service ClusterIPs are permanent and load balance traffic automatically across all pods.
Step 02: Inspect Cluster Services and Assigned NodePorts
සිංහලෙන් — Cluster එකේ ඇති Services සහ Port අංක පරීක්ෂා කරමු.
Display all registered services, assigned virtual ClusterIPs, and exposed external ports.
kubectl get svcget svc: Services ලැයිස්තුව, ClusterIPs සහ mapped ports පෙන්වයි.
Expected output
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 443/TCP 14d
web-app NodePort 10.104.182.45 80:31842/TCP 45sSRE Tip: You can now access your application from any browser using http:// :31842!
Step 03: Scale Deployment Replicas Under High Load
සිංහලෙන් — පාරිභෝගික තදබදය වැඩි වූ විට Pods ගණන 3 සිට 5 දක්වා ක්ෂණිකව වැඩි කරමු.
Scale deployment replica count from 3 up to 5 pods in real time to absorb sudden traffic spikes.
kubectl scale deployment web-app --replicas=5scale: Deployment එකක replica count එක ක්ෂණිකව වැඩි හෝ අඩු කරයි.
Expected output
deployment.apps/web-app scaled to 5 replicasSRE Tip: In production, configure Horizontal Pod Autoscaler (HPA) to scale pods automatically based on CPU and memory thresholds.
Step 04: Execute Zero-Downtime Rolling Update
සිංහලෙන් — Users ලට නොදැනී සයිට් එකේ අලුත් Version එක දාන Zero-Downtime Rolling Update එකක් කරමු.
Trigger a zero-downtime rolling update to upgrade container image version from nginx:alpine to nginx:1.25.
kubectl set image deployment/web-app nginx=nginx:1.25set image: Pods එකින් එක යාවත්කාලීන කරමින් zero-downtime rolling update එකක් ආරම්භ කරයි.
Expected output
deployment.apps/web-app image updatedSRE Tip: Kubernetes brings up new version pods and waits for readiness probes before terminating old version pods, guaranteeing 0 downtime!
Step 05: Track Rolling Update Rollout Status
සිංහලෙන් — Rolling update එක සාර්ථකව අවසන් වූ බව තහවුරු කර ගනිමු.
Watch the rollout progress in real time and verify all 5 new replica pods are healthy.
kubectl rollout status deployment/web-approllout status: Rolling update එකේ ප්රගතිය සජීවීව බලා සිටියි.
Expected output
deployment "web-app" successfully rolled out! (Zero-Downtime achieved)SRE Tip: If a rollout introduces a bug, immediately execute 'kubectl rollout undo deployment/web-app' to rollback in 3 seconds!
Hands-on practice activities
Work through these yourself — tick them off as you go.
- Activity 81: Expose Deployment as NodePort Service (Drill) — Create a stable network service abstraction with an external NodePort.
- Activity 82: Inspect Cluster Services and Ports (Drill) — Display all registered services, assigned virtual ClusterIPs, and exposed external ports.
- Activity 83: Scale Deployment Replicas (Drill) — Scale deployment replica count from 3 up to 5 pods to absorb increased customer traffic.
- Activity 84: Execute Zero-Downtime Rolling Update (Drill) — Trigger a zero-downtime rolling update to upgrade container image version.
- Activity 85: Default Service Type Quiz (Quiz) — What is the default Kubernetes Service type used for internal cluster communication? Answer: ClusterIP.
Keep going: ← Lab 16 · Lab 18 → · Track your progress in the Self Guide
ExerciseKnowledge check
What is the default Kubernetes Service type used for internal cluster communication? / Cluster එක ඇතුළත සන්නිවේදනය සඳහා භාවිතා වන default Service වර්ගය කුමක්ද?
Finished this one?
Part of Self Guide · Stage 11: SRE Labs II — cloud, containers and delivery. Progress is saved in this browser.


