Services & Networking
Intermediate
Overview
Pods come and go, each with a new IP. A Service gives a stable name and IP that load-balances traffic across the Pods matching its label selector.
ClusterIP (the default) is reachable only inside the cluster. NodePort opens a port on every node, and LoadBalancer provisions an external load balancer from your cloud provider.
Within the cluster, you reach a Service by its DNS name: <service>.<namespace>.svc.cluster.local (often just <service> from the same namespace).
Cheatsheet
kubectl get svcList serviceskubectl expose deploy/api --port=80Create a Service for a Deploymentkubectl port-forward svc/api 8080:80Forward a service to localhostkubectl describe svc apiInspect a service and its endpointsTry it
A safe, simulated terminal. Run the suggested commands to see typical output.
simulated terminal
Type a command and press Enter, or click a suggestion below to run it.
Quick quiz
1. Why do you need a Service in front of Pods?
2. Which Service type is reachable only inside the cluster?