Networking: Services, DNS, and IngressLesson 3.1
Kubernetes Services explained: ClusterIP, NodePort, and LoadBalancer
Service definition, virtual IP, kube-proxy iptables rules, ClusterIP type, NodePort type, LoadBalancer type, service selector, targetPort vs port, endpoint object
Services Give Pods a Stable Address
Pods are ephemeral — they die and get replaced with new IP addresses. A Service provides a stable virtual IP and DNS name that routes to the current healthy Pods matching its selector.
ClusterIP (Default)
apiVersion: v1
kind: Service
metadata:
name: backend-svc
spec:
type: ClusterIP # default — only reachable inside cluster
selector:
app: backend
ports:
- port: 80 # Service listens on port 80
targetPort: 8080 # forwards to container port 8080NodePort
spec:
type: NodePort
ports:
- port: 80
targetPort: 8080
nodePort: 30080 # accessible at ANY node IP:30080
# range: 30000-32767LoadBalancer
In cloud environments (GKE, EKS, AKS), type: LoadBalancer provisions an external cloud load balancer automatically. On bare-metal clusters, use MetalLB or an Ingress controller instead — LoadBalancer type does nothing without a cloud provider integration.
spec:
type: LoadBalancer
ports:
- port: 443
targetPort: 8443