Deployment invalid: spec.template.metadata.labels: Invalid value

前端 未结 2 1864
攒了一身酷
攒了一身酷 2021-01-01 11:21

Deploying my service to production:

envsubst < ./kubernetes/pre-production/aks.yaml | kubectl apply -f -

I\'m getting the following erro

相关标签:
2条回答
  • 2021-01-01 11:24

    You need to add selector in spec of Deployment.

    And also, these selector should match with labels in PodTemplate.

    apiVersion: apps/v1beta1
    kind: Deployment
    metadata:
      name: moverick-mule-pre
    spec:
      replicas: 2
      selector:
        matchLabels:
          app: moverick-mule-pre
          commit: $CI_COMMIT_SHA
      strategy:
        type: RollingUpdate
        rollingUpdate:
          maxSurge: 1
          maxUnavailable: 1
      template:
        metadata:
          labels:
            app: moverick-mule-pre
            commit: $CI_COMMIT_SHA
    

    Otherwise, you will get error like below

    The Deployment "moverick-mule-pre" is invalid:

    • spec.selector: Required value
    • spec.template.metadata.labels: Invalid value: map[string]string{...} selector does not match template labels
    0 讨论(0)
  • 2021-01-01 11:37
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: backend-security-deployment
    spec:
      replicas: 2
      selector:
        matchLabels:
          app: backend-security
      template:
        metadata:
          labels: # labels to select/identify the deployment
            app: backend-security
        spec:     # pod spec                  
          containers: 
          - name: backend-security
            image: yurifull/backend-security:v1.0.0 # image we pushed
            ports:
            - containerPort: 3001
    

    this works for me...

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