Services: ClusterIP, NodePort, LoadBalancer
Give your pods a stable address and pick the Service type that matches the traffic you actually have.
Open this lesson in the learning hubKey points
- Pod IPs change constantly. A Service is a stable virtual IP and DNS name in front of a moving set of pods.
- It selects pods by label, not by Deployment. Endpoints update automatically as pods come and go.
ClusterIPis the default and is internal only. Reach it asorders, ororders.prod.svc.cluster.localfrom another namespace.NodePortopens one port in the 30000-32767 range on every node. Useful in dev, blunt in production.LoadBalancerasks the cloud for a real load balancer, one per Service, so the bill adds up fast.clusterIP: Nonemakes it headless. DNS then returns the pod IPs directly, which is what StatefulSets use.
Example
apiVersion: v1
kind: Service
metadata:
name: orders
spec:
type: ClusterIP # default: reachable only inside the cluster
selector:
app: orders # matches pod labels, not the Deployment name
ports:
- port: 80 # the Service port
targetPort: 8080 # the container port
---
apiVersion: v1
kind: Service
metadata:
name: orders-public
spec:
type: LoadBalancer # cloud provisions an external IP
selector:
app: orders
ports:
- port: 443
targetPort: 8080
A Service turns a churning set of pods into one name that never changes.
This is a reading copy. The full lesson — with the visual explainer, the interactive lab and a Run button for the code — lives in the Kubernetes course, and every lesson in it is listed on the Kubernetes contents page.