This is my first foray in this forum so apologies if you consider a beginner’s question inappropriate. But if this is the case, please let me know where are the suitable forums for us to learn.
I am looking at an example provided during some Kubernetes training and I see too many labels here:
apiVersion: v1
kind: Service
metadata:
name: my-stateful-set
labels:
**app: my-stateful-set**
spec:
ports:
- port: 80
clusterIP: None
selector:
**app: my-stateful-set**
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: my-stateful-set
spec:
serviceName: my-stateful-set
replicas: 3
selector:
matchLabels:
**app: my-stateful-set**
template:
metadata:
labels:
app: my-stateful-set
spec:
terminationGracePeriodSeconds: 0
[...rest omitted for brevity...]
This is what I understood:
- Service.metadata.labels.app - is the label we give to the service so we can group/find similar services
- Service.spec.selector.app - apps with this label will be linked to the service my-stateful-set
- StatefulSet.spec.serviceName - specifies by (unique) name the service to bind to each pod created
- StatefulSet.spec.selector.matchLabels.app - what is this label needed for?
- StatefulSet.spec.template.metadata.labels.app - what is this label needed for?
Also, given point 3, why would you need a label in the service specification if the service name has been unambiguously specified through serviceName in the stateful set?