Networking Services
Master ClusterIP, NodePort, LoadBalancers, and Ingress to expose your applications.
Theory: How Pods Talk
Pods are ephemeral—they die, and their IPs change. A Service is an abstract way to expose an application running on a set of Pods as a network service. A Service gets a stable IP and DNS name.
Types of Services
- ClusterIP: (Default) Exposes the Service on a cluster-internal IP. Not reachable from outside.
- NodePort: Exposes the Service on each Node's IP at a static port. Reaches it via `NodeIP:NodePort`.
- LoadBalancer: Exposes the Service externally using a cloud provider's load balancer.
- Ingress: Not actually a Service type, but an API object linking routing rules (like URL paths) to internal Services.
Hands-on Labs
Interview Prep: Networking
NodePort exposes the service on a static port across all Nodes' external IPs. LoadBalancer does this as well, but automatically provisions a managed external load balancer from the cloud provider (like AWS ELB) to route traffic to those NodePorts.
CoreDNS watches the Kubernetes API for new Services and creates DNS records for them. If a Pod needs to talk to a Service named "database" in the same namespace, it can simply resolve "database". If it's in a different namespace (e.g., "prod"), it would use "database.prod.svc.cluster.local".
Using NetworkPolicies. By default, all traffic is allowed. Once a NetworkPolicy selects a Pod, it blocks all traffic unless explicitly allowed by the policy rules (either Ingress for incoming, or Egress for outgoing traffic).