Services & Networking

Pods are ephemeral and get assigned new dynamic IP addresses whenever recreated. A Kubernetes Service provides a static IP address and DNS name entry to route traffic reliably to matching Pods.

1. Service Types Comparison

Service TypeScope & AccessibilityBest For
ClusterIP (Default)Internal cluster IP onlyInter-pod communication (Databases, Microservices, Caches)
NodePortExposes static port (30000-32767) on all Worker Node IPsDevelopment / On-premise bare-metal testing
LoadBalancerProvisions cloud provider external Load Balancer (AWS ELB, GCP LB)Production public-facing web applications & APIs
ExternalNameMaps service to external CNAME recordIntegrating external third-party services outside cluster

2. Production LoadBalancer Service Manifest

apiVersion: v1
kind: Service
metadata:
  name: frontend-service
spec:
  type: LoadBalancer
  selector:
    app: api-server # Routes traffic to Pods labeled 'app: api-server'
  ports:
    - protocol: TCP
      port: 80        # Public Service Port
      targetPort: 3000 # Container Port inside Pod

Next Up

Learn Ingress & Ingress Controllers: Nginx Ingress, host/path-based routing, and Cert-Manager TLS/SSL.

Next Lesson: Ingress & TLS Termination →