Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Deploying my service to production:

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

I'm getting the following error:

The Deployment "moverick-mule-pre" is invalid: spec.template.metadata.labels: Invalid value: map[string]string{"commit":"750a26deebc3582bec4bfbb2426b3f22ee042eaa", "app":"moverick-mule-pre"}: selector does not match template labels

My yaml file is:

apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: moverick-mule-pre
spec:
  replicas: 2
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
  template:
    metadata:
      labels:
        app: moverick-mule-pre
        commit: $CI_COMMIT_SHA
    spec:
      containers:
      - name: moverick-mule-pre
        image: $REGISTRY_SERVER_PRE/$CI_PROJECT_NAME:$CI_COMMIT_REF_NAME
        imagePullPolicy: Always
        ports:
        - containerPort: 80
        envFrom:
          - secretRef:
              name: moverick-pre
        livenessProbe:
          httpGet:
            path: /console
            port: 80
          initialDelaySeconds: 5
          periodSeconds: 5
        volumeMounts:
        - name: logs
          mountPath: /opt/mule/logs/
        - name: asc
          mountPath: /opt/mule/asc/
      imagePullSecrets:
      - name: registry-pre
      volumes:
      - name: logs
        azureFile:
          secretName: azure-files-pre
          shareName: logs-pre
          readOnly: false
      - name: asc
        azureFile:
          secretName: azure-asc-pre
          shareName: asc-pre
          readOnly: false
---
apiVersion: v1
kind: Service
metadata:
  name: moverick-mule-pre
spec:
  ports:
  - port: 80
  selector:
    app: moverick-mule-pre
question from:https://stackoverflow.com/questions/65713594/the-deployment-helloworld-is-invalid-spec-selector-invalid-value

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
738 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...