0
0
Kubernetesdevops~5 mins

Why Kubernetes networking matters - Why It Works

Choose your learning style9 modes available
Introduction
Kubernetes networking connects all parts of your app so they can talk to each other. Without it, your app's pieces can't share data or work together smoothly.
When you want your app's containers to communicate inside the cluster.
When you need to expose your app to users outside the cluster.
When you want to control who can talk to your app and how.
When you want to connect multiple services in your app securely.
When you want to monitor or debug network traffic between app parts.
Commands
This command shows all pods with their IP addresses so you can see how Kubernetes assigns network addresses to each pod.
Terminal
kubectl get pods -o wide
Expected OutputExpected
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES my-app-pod-1 1/1 Running 0 10s 10.244.1.5 node-1 <none> <none>
-o wide - Shows extra details including pod IP addresses
This command lists services that provide stable network endpoints to access your pods inside or outside the cluster.
Terminal
kubectl get svc
Expected OutputExpected
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 1d my-service ClusterIP 10.96.123.45 <none> 80/TCP 10m
This command shows detailed info about the service, including which pods it routes traffic to and on which ports.
Terminal
kubectl describe svc my-service
Expected OutputExpected
Name: my-service Namespace: default Labels: <none> Selector: app=my-app Type: ClusterIP IP: 10.96.123.45 Port: http 80/TCP Endpoints: 10.244.1.5:80 Session Affinity: None Events: <none>
Key Concept

If you remember nothing else from this pattern, remember: Kubernetes networking lets your app parts find and talk to each other reliably inside the cluster.

Common Mistakes
Trying to access a pod directly from outside the cluster without a service.
Pods have dynamic IPs and are not reachable from outside the cluster without a service.
Create a service to expose your pods with a stable IP or DNS name.
Assuming pod IPs never change.
Pod IPs can change when pods restart or move, breaking direct IP connections.
Use services to provide stable network endpoints instead of pod IPs.
Not labeling pods correctly to match service selectors.
Services use labels to find pods; if labels don't match, traffic won't reach pods.
Ensure pod labels match the service selector labels exactly.
Summary
Use 'kubectl get pods -o wide' to see pod IP addresses assigned by Kubernetes.
Use 'kubectl get svc' to list services that provide stable network access to pods.
Use 'kubectl describe svc <service-name>' to see how services route traffic to pods.