由于部署清单问题,无法掌舵安装 [英] Unable to helm install due to deployment manifest issue

查看:382
本文介绍了由于部署清单问题,无法掌舵安装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试执行helm install

错误:无法从发布清单中构建kubernetes对象: [无法识别":版本中与服务"类型不匹配 "extensions/v1beta1",验证错误":验证数据错误: ValidationError(Deployment.spec):在中缺少必填字段选择器" io.k8s.api.apps.v1.DeploymentSpec]

Error: unable to build kubernetes objects from release manifest: [unable to recognize "": no matches for kind "Service" in version "extensions/v1beta1", error validating "": error validating data: ValidationError(Deployment.spec): missing required field "selector" in io.k8s.api.apps.v1.DeploymentSpec]

我的service.yaml如下所示

apiVersion: extensions/v1beta1
kind: Service
metadata:
  name: helm-xxx-helper-api
spec:
  type: NodePort
  ports:
    - nodePort: 31235
      port: 80
      targetPort: 8080
  selector:
     app: helm-xxx-helper

我的deployment.yaml

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: helm-xxx-helper
spec:
  replicas: 2
  selector:
    matchLabels:
    name: helm-xxx-helper
  template:
    metadata:
      labels:
        app: helm-xxx-helper
    spec:
      containers:
      - name: helm-xxx-helper
        image: xxxxxxxxx:5001/devops/xxx-helper:latest
        imagePullPolicy: Always
        env:
          - name: XXX_STAGE
            value: "DEV"
        ports:
        - containerPort: 8080

这里可能是什么问题?

推荐答案

收到此错误表示您正在使用Kubernetes 1.16或更高版本.

As you received this error it means that you are using version Kubernetes 1.16 or newer.

问题1 -使用Service

在此版本中,许多apiVersion已更改(部署,StatefulSet,服务).可以在此处中找到更多详细信息.

In this version many apiVersion has been changed (Deployments, StatefulSet, Service). More details can be found here.

在Kubernetes 1.16中,您需要将apiVersion: v1用于service.否则,您会收到类似

In Kubernetes 1.16 you need to use apiVersion: v1 for service. Otherwise you will receive errors like

error: unable to recognize "STDIN": no matches for kind "Service" in version "extensions/v1beta1"
error: unable to recognize "STDIN": no matches for kind "Service" in version "extensions/v1"
error: unable to recognize "STDIN": no matches for kind "Service" in version "apps/v1"

问题2 -使用Deployment.

  • spec.selector.matchLabels不包含像name这样的值.您需要使用labels中的值.因此,在这种情况下,您需要使用app: helm-xxx-helper而不是name: helm-xxx-helper,否则您将收到类似以下错误:
  • spec.selector.matchLabels does not contain value like name. You need to use value from labels. So in this case instead of name: helm-xxx-helper you need to use app: helm-xxx-helper otherwise you will receive error like:
The Deployment "helm-xxx-helper" is invalid: spec.template.metadata.labels: Invalid value: map[string]string{"app":"helm-xxx-helper"}: `selector` does not match template `labels`

  • 错误的YAML格式.在您的代码中,您有
  • ...
    selector:
      matchLabels:
      name: helm-xxx-helper
    ...
    

    matchLabels的值应在第3个字母(t)以下.另外,正如我在前面提到的那样,您需要将name更改为app

    Value for matchLabels should be under 3rd letter (t). Also as I mentioned in previous point you need to change name to app

    正确格式为matchLables的正确格式:

    Proper format with correct valye of matchLables:

    ...
    selector:
      matchLabels:
        app: helm-xxx-helper
    ...
    

    您可以在此处阅读有关LabelsSelectors的信息. .

    You can read about Labels and Selectors here.

    正如您提到的是HELM,您需要将Kubernetes version更改为早于1.16,或者在template目录中的每个对象YAML中更改apiVersion. 已经有一个类似的案例.请检查此线程以获取更多信息.

    As you mentioned it is HELM, you will need to change Kubernetes version to older than 1.16 or change apiVersion in each object YAML in template directory. There was already a similar case. Please check this thread for more information.

    在两个将创建ServiceDeployment的YAML下方.在Kubernetes 1.16.1上进行了测试.

    Below both YAMLs which will create Service and Deployment. Tested on Kubernetes 1.16.1.

    apiVersion: v1
    kind: Service
    metadata:
      name: helm-xxx-helper-api
    spec:
      type: NodePort
      ports:
        - nodePort: 31235
          port: 80
          targetPort: 8080
      selector:
        app: helm-xxx-helper
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: helm-xxx-helper
    spec:
      replicas: 2
      selector:
        matchLabels:
          app: helm-xxx-helper
      template:
        metadata:
          labels:
            app: helm-xxx-helper
        spec:
          containers:
          - name: helm-xxx-helper
            image: nginx # As I dont have your image ive put nginx
            imagePullPolicy: Always
            env:
              - name: XXX_STAGE
                value: "DEV"
            ports:
            - containerPort: 8080
    

    这篇关于由于部署清单问题,无法掌舵安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆