Kubernetes 由于部署清单问题,无法掌舵安装

Kubernetes 由于部署清单问题,无法掌舵安装,kubernetes,kubernetes-helm,Kubernetes,Kubernetes Helm,尝试执行helm安装时 错误:无法从发布清单生成kubernetes对象: [无法识别“”:版本中的种类“服务”没有匹配项 “扩展/v1beta1”,验证“”时出错:验证数据时出错: ValidationError(Deployment.spec):中缺少必需字段“selector” io.k8s.api.apps.v1.DeploymentSpec] 我的服务.yaml如下所示 apiVersion: extensions/v1beta1 kind: Service metadata: n

尝试执行
helm安装时

错误:无法从发布清单生成kubernetes对象: [无法识别“”:版本中的种类“服务”没有匹配项 “扩展/v1beta1”,验证“”时出错:验证数据时出错: ValidationError(Deployment.spec):中缺少必需字段“selector” io.k8s.api.apps.v1.DeploymentSpec]

我的
服务.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
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
这里可能有什么问题?

在选择器中尝试此操作

  selector:
    matchLabels:
      app: helm-xxx-helper  

当您收到此错误时,表示您使用的是Kubernetes 1.16或更高版本

第1期-提供
服务

在此版本中,许多
apiVersion
已更改(部署、状态集、服务)。可以找到更多细节

在Kubernetes 1.16中,对于
服务
,您需要使用
apiVersion:v1
。否则,您将收到以下错误:

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期-带有
部署

  • spec.selector.matchLabels
    不包含类似于
    name
    的值。您需要使用
    标签中的值。因此,在这种情况下,您需要使用
    app:helm xxx helper
    而不是
    name:helm xxx helper
    ,否则您将收到如下错误:
  • 错误的YAML格式。在您的代码中
匹配标签的值应在第三个字母(t)以下。正如我在前面提到的,您需要将
name
更改为
app

正确的格式和正确的
匹配标签值

...
selector:
  matchLabels:
    app: helm-xxx-helper
...
您可以阅读
标签
选择器

正如您提到的,它是
HELM
,您需要将
Kubernetes版本
更改为早于1.16的版本,或者在
template
目录中的每个对象YAML中更改
apiVersion
。 已经有过类似的案例。请查看更多信息

下面是将创建
服务
部署
的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

你在运行什么版本的Kubernetes
extensions/v1beta1
已在我相信1.16中删除。@HariEnnekat更改
apiVersion:v1
并更正Deployment.yaml
.spec.selector.matchLabels
中的格式。那么一切都会好起来。@doelleri是的,我使用的是1.16版。这就说到点子上了。确定了与之相关的所有问题。我选择这个作为正确答案。
...
selector:
  matchLabels:
    app: helm-xxx-helper
...
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