educative.io

Educative

Why Have Labels for Deployments

I guess labels on services are matched against labels on pods.
So, what is the point of having labels on deployments or replica sets?
One reason I can think is to maybe to filter resources based on labels using --selector, e.g. kubectl get all --selector name=db

What I mean is

kind: Deployment

metadata:
  name: go-demo-2-db

  # part below feels redundant
  labels:
    type: db
    service: go-demo-2
    vendor: MongoLabs

Course: A Practical Guide to Kubernetes - Learn Interactively
Lesson: Updating Multiple Objects - A Practical Guide to Kubernetes

@Shameek_Agarwal1 Hi, Yes we use labels because replica set support set-based selector requirements. For example while creating a bare Pod, it is totally recommended to not have Pods with the same labels as the selector of one of your ReplicaSets. Because a ReplicaSet is not limited to owning Pods specified by its template. So if we don’t have labels on them we would be unable to identify them.