Use of Labels in Kubernetes deployments

12/17/2018

I am interested in knowing how pervasively labels / selectors are getting used in Kubernetes. Is it widely used feature in field to segregate container workloads. If not, what are other ways that are used to segregate workloads in kubernetes.

-- vishal
kubernetes

1 Answer

6/27/2019

I'm currently running a Kubernetes in production for some months and using the labels on some pods to spread them out over the nodes using the podAntiAffinity rules. So that these pods aren't all located on a single node. Mind you, I'm running a small cluster of three nodes.

affinity:
  podAntiAffinity:
    requiredDuringSchedulingIgnoredDuringExecution:
    - labelSelector:
        matchExpressions:
        - key: app
          operator: In
          values:
          - your-deployment-name
      topologyKey: "kubernetes.io/hostname"

I've found this a useful way to use labels.

-- ekloosterman
Source: StackOverflow