ReplicaSet fails with invalid: spec.template.metadata.labels

前端 未结 2 756
再見小時候
再見小時候 2021-01-27 08:55

I am trying to do some research on replicaSet for my learning purpose. I was able to create a replicaSet successfully with matchLabels. To test the matchExpression selector, I c

相关标签:
2条回答
  • 2021-01-27 09:04

    Can you try with the following by changing the label in template section.

    apiVersion: apps/v1
    kind: ReplicaSet
    metadata:
      name: replicaset-2
    spec:
      replicas: 2
      selector:
        matchExpressions:
          - {key: tier, operator: In, values: [frontend1]}
      template:
        metadata:
          labels:
            tier: frontend1
        spec:
          containers:
          - name: nginx
            image: nginx
    
    0 讨论(0)
  • 2021-01-27 09:17

    To make pod fall into newly created ReplicaSet's scope using matchExpressions you have to either use the same labels in RS as defined in already created pod or you have to add additional label in the expression so it looks like following:

    apiVersion: apps/v1
    kind: ReplicaSet
    metadata:
      name: replicaset-2
    spec:
      replicas: 2
      selector:
        matchExpressions:
        - key: tier
          operator: In
          values:
          - frontend1
          - nginx
      template:
        metadata:
          labels:
            tier: nginx
        spec:
          containers:
          - name: nginx
            image: nginx
    

    This way RS will recognize already existing pod as its own and create only one more pod to meet the requirements defined in replicas field.

    0 讨论(0)
提交回复
热议问题