Skip to content

Services Explained

A Kubernetes Service is a stable virtual IP in front of a set of pods. Which one you pick determines where packets are load-balanced.

TypeScopeReached viaTypical use
ClusterIPIn-clusterCluster-internal virtual IPIn-cluster east–west
NodePortNode port<any-node-ip>:30000-32767Bare metal, quick expose
LoadBalancerExternal LBCloud LB → node port → podPublic entrypoints
HeadlessDNS-onlyPer-pod DNS A records, no VIPStatefulSets, DBs
flowchart LR
  U[Client] -->|1. DNS| S[my-svc.default.svc.cluster.local]
  S -->|2. kube-proxy DNAT| C[ClusterIP: 10.96.44.12]
  C -->|3. iptables / IPVS rule| P1[pod-a: 10.244.1.7]
  C -.-> P2[pod-b: 10.244.2.4]
  C -.-> P3[pod-c: 10.244.1.9]
clusterip.yaml
apiVersion: v1
kind: Service
metadata:
name: api
spec:
type: ClusterIP # default
selector:
app: api
ports:
- port: 80 # service port
targetPort: 8080 # container port
Terminal window
# Resolve the service via cluster DNS
kubectl run -it --rm debug --image=nicolaka/netshoot --restart=Never -- \
dig +short api.default.svc.cluster.local
# See where kube-proxy routes it (iptables mode)
iptables -t nat -L KUBE-SERVICES -n | grep api
# See endpoints
kubectl get endpoints api -o yaml