1. Service object
A Service gives a stable name and virtual IP in front of a changing set of pods.
kind: ServiceTyporithm · easy
Step 1 of 8 · intro card
Networking
A ClusterIP Service gives pods a stable virtual IP and DNS name; its label selector tracks which pods receive traffic, and port/targetPort map the front to the back.
Pods are ephemeral and get new IPs on each restart, so clients cannot rely on a pod IP directly.
A ClusterIP Service solves this with a stable virtual IP and DNS name; its selector continuously matches pod labels to build the endpoint list.
port is what the Service listens on; targetPort is the pod's container port that traffic is forwarded to.
selector matches pod labels to pick endpoints.
port is the Service port; targetPort is the pod port.
ClusterIP is internal-only and the default type.
apiVersion: v1
kind: Service
metadata:
name: web
spec:
selector:
app: web
ports:
- port: 80
targetPort: 8080
type: ClusterIPConnect each part of the code to the concept before you type.
A Service gives a stable name and virtual IP in front of a changing set of pods.
kind: ServiceThe selector matches pod labels; matching pods become the Service's endpoints.
selector:
app: webport is the port the Service exposes on its ClusterIP.
port: 80targetPort is the port on the pod the traffic is forwarded to.
targetPort: 8080ClusterIP is the default — reachable only from inside the cluster.
type: ClusterIPRead the concept map and follow the code breakdown.
Type the implementation, repair mistakes and work through every recall exercise.
Use the final check without hints; revisit weak concepts in short practice sessions.