【问题标题】:Unable to helm install due to deployment manifest issue由于部署清单问题,无法进行掌舵安装
【发布时间】:2019-12-17 18:52:18
【问题描述】:

在尝试执行helm install

错误:无法从发布清单构建 kubernetes 对象: [无法识别“”:版本中没有匹配类型“服务” “extensions/v1beta1”,错误验证“”:错误验证数据: ValidationError(Deployment.spec):缺少必填字段“选择器” 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? extensions/v1beta1 在我相信 1.16 中被删除。
  • @HariEnnekat 更改 apiVersion: v1 并更正 Deployment.yaml .spec.selector.matchLabels 中的格式。那么一切都会好起来的。
  • @doelleri 是的,我使用的是 1.16 版。

标签: kubernetes kubernetes-helm


【解决方案1】:

当您收到此错误时,这意味着您使用的是 Kubernetes 1.16 或更高版本。

问题 1 - Service

在此版本中,许多apiVersion 已更改(部署、StatefulSet、服务)。更多详情请见here

在 Kubernetes 1.16 中,您需要将 apiVersion: v1 用于 service。否则你会收到类似的错误

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,否则您将收到如下错误:
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 的值应在第三个字母 (t) 之下。另外,正如我在前面提到的,您需要将name 更改为app

正确的格式和正确的值matchLables:

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

您可以阅读有关LabelsSelectors here 的信息。

正如您提到的它是HELM,您需要将Kubernetes version 更改为早于1.16 或更改template 目录中每个对象YAML 中的apiVersion。 已经有类似的案例了。详情请查看this thread

在将创建 ServiceDeployment 的两个 YAML 下方。在 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

【讨论】:

  • 这是重点。确定了与之相关的所有问题。我选择这个作为正确答案。
【解决方案2】:

在选择器中试试这个

  selector:
    matchLabels:
      app: helm-xxx-helper  

【讨论】:

    猜你喜欢
    • 2018-06-02
    • 1970-01-01
    • 2020-03-16
    • 2020-04-02
    • 1970-01-01
    • 1970-01-01
    • 2021-06-25
    • 2020-08-29
    • 2021-12-06
    相关资源
    最近更新 更多