【问题标题】:What is the best way to verify a deployment.yaml kubernetes file? [duplicate]验证 deployment.yaml kubernetes 文件的最佳方法是什么? [复制]
【发布时间】:2020-11-22 03:22:04
【问题描述】:

我在 Kuberentes 中有以下 deployment.yaml 文件:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: basic-deployment
spec:
  replicas: 2
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: basic
    spec:
      containers:
      - name: basic
        image: nginx
        volumeMounts:
        - name: config-volume
          mountPath: /etc/nginx/conf.d
      volumes:
      - name: config-volume
        configMap:
          name: basic-config

我不确定在运行kubectl create -f basic-deployment.yaml 时如何解决以下错误:

部署“basic-deployment”无效:spec.template.metadata.labels:无效值:map[string]string{"app":"basic"}:selector 不匹配模板@ 987654324@

【问题讨论】:

    标签: kubernetes kubectl kubernetes-deployment


    【解决方案1】:
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: basic-deployment
    spec:
      replicas: 2
      selector:
        matchLabels:
          app: basic
      template:
        metadata:
          labels:
            app: basic
        spec:
          containers:
          - name: basic
            image: nginx
            volumeMounts:
            - name: config-volume
              mountPath: /etc/nginx/conf.d
          volumes:
          - name: config-volume
            configMap:
              name: basic-config
    

    基本上,部署规范中的选择器匹配标签需要与模板中的标签匹配。在您的情况下,您将 app: nginx 作为选择器的匹配标签,并且您的模板中有 app: basic,因此不匹配。

    您必须同时拥有app: nginxapp: basic 中的任何一个,以便匹配。

    【讨论】:

      猜你喜欢
      • 2011-10-22
      • 2010-09-06
      • 1970-01-01
      • 2018-04-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多