A label is a key-value metadata pair attached to a Kubernetes resource. Labels organize objects and loosely connect application components without tightly coupling their definitions. section 15.2
Label a Pod and select it from a Service
Add labels such as app: numbers and component: api under metadata. Then select the matching Pod with kubectl get po --selector app=numbers,component=api. A Service can use the same selector to route traffic to that Pod. section 15.2
Listing 15.2 A Pod spec for the random number REST API
apiVersion: v1
kind: Pod
metadata:
name: numbers-api
labels:
app: numbers
component: api
spec:
containers:
- name: api
image: kiamol/ch03-numbers-api
ports:
- containerPort: 80
name: http
Inspect a complete Pod manifest showing labels alongside the container and port configuration. section 15.2
Verify and use labels with kubectl:
- Run kubectl get pods --show-labels to display labels. section 15.2
- Use matching app and component selectors to identify Pods and connect them to a Service. section 15.2






