Unable to helm install due to deployment manifest issue

我的梦境 提交于 2020-07-07 11:08:23

问题


While trying to perform helm install

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]

My service.yaml looks like below

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

My 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

What could be the issue here?


回答1:


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

Issue 1 - With Service

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

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"

Issue 2 - With Deployment.

  • 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`
  • wrong YAML format. In your code you have
...
selector:
  matchLabels:
  name: helm-xxx-helper
...

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

Proper format with correct valye of matchLables:

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

You can read about Labels and Selectors here.

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.

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



回答2:


try this in selector

  selector:
    matchLabels:
      app: helm-xxx-helper  


来源:https://stackoverflow.com/questions/59369174/unable-to-helm-install-due-to-deployment-manifest-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!