Script Valley
Kubernetes: From Containers to Clusters
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

Kubernetes Service types comparison diagram

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 8080

NodePort

spec:
  type: NodePort
  ports:
  - port: 80
    targetPort: 8080
    nodePort: 30080   # accessible at ANY node IP:30080
                      # range: 30000-32767

LoadBalancer

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

Up next

Kubernetes DNS: how Pods discover each other by name

Sign in to track progress

Kubernetes Services explained: ClusterIP, NodePort, and LoadBalancer โ€” Networking: Services, DNS, and Ingress โ€” Kubernetes: From Containers to Clusters โ€” Script Valley โ€” Script Valley