A
apiVersion: v1
kind: Service
metadata:
name: shop # (1) the name that never changes
spec:
selector:
app: shop # (2) shine on Pods wearing this tag
ports:
- port: 80 # (3) the port customers use
targetPort: 8080 # (4) the port the container listens on
name: inside the cluster, other Pods reach the shop simply as shop (or shop.<namespace>; chapter 4).
selector: the label to shine on. It must match the Pods' labels exactly, typos included.
port: what callers connect to on the Service.
targetPort: where the container is actually listening. Getting these two mixed up is the most common Service mistake.
Kubernetes keeps a live list of the
kubectl get endpointslices -l kubernetes.io/service-name=shop # older clusters: kubectl get endpoints shop