Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

K8s node labels with keys and no values

Tags:

kubernetes

Sometimes k8s nodes are labelled as k8s.infra/postgres= . Is this a valid label for a node ?

How do we use this kind of label whilst adding node affinities in our Deployment manifests ?

    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: k8s.infra/postgres
                operator: Exists
                values:
                - 
                - 
like image 877
nevosial Avatar asked Sep 02 '25 17:09

nevosial


1 Answers

Sometimes k8s nodes are labelled as k8s.infra/postgres= . Is this a valid label for a node?

Yes, it is a valid label. The type the key is a string and the value is also a string but the value can be empty string: "".

How do we use this kind of label whilst adding node affinities in our Deployment manifests?

The operators Exists and DoesNotExist only use key: and not values: so you can write:

        - matchExpressions:
          - key: k8s.infra/postgres
            operator: Exists
like image 135
Jonas Avatar answered Sep 05 '25 16:09

Jonas