0

在 Kubernetes 集群中部署 yaml 文件时出现错误请求错误。

Error from server (BadRequest): error when creating "deployment.yaml": service in version "v1" cannot be handled as a Service: no kind "service" is registered for version "v1" in scheme "k8s.io/kubernetes/pkg/api/legacyscheme/scheme.go:29"
Error from server (BadRequest): error when creating "deployment.yaml": deployment in version "v1" cannot be handled as a Deployment: no kind "deployment" is registered for version "apps/v1" in scheme "k8s.io/kubernetes/pkg/api/legacyscheme/scheme.go:29"

kubernetes 集群是 1.14.7 版本,有 2 个节点池。一个是带有 linux 节点的默认节点池,另一个是用于 windows 容器的 windows 节点池(节点数为 1)。我正在门户中登录 Azure CLI 并运行 kubectl 命令。

试过 apiVersion: apps/v1beta1 但不好。

kubectl version

Client Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.0", GitCommit:"2bd9643cee5b3b3a5ecbd3af49d09018f0773c77", GitTreeState:"clean", BuildDate:"2019-09-18T14:36:53Z", GoVersion:"go1.12.9", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.6", GitCommit:"96fac5cd13a5dc064f7d9f4f23030a6aeface6cc", GitTreeState:"clean", BuildDate:"2019-08-19T11:05:16Z", GoVersion:"go1.12.9", Compiler:"gc", Platform:"linux/amd64"}

这是deployment.yaml文件

apiVersion: v1
kind: Service
metadata:  
  name: sampleapp
  labels:
    app: sampleapp
spec:
  type: LoadBalancer  
  ports:
  - name: proxy
    protocol: TCP
    port: 9163
    targetPort: 9163
  - name: banyan
    protocol: TCP
    port: 23010
    targetPort: 23010      
  selector:
    app: sampleapp
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: sampleapp
  labels:
    app: sampleapp
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: sampleapp
    spec:
      nodeSelector:
        "beta.kubernetes.io/os": windows
      imagePullSecrets:
        - name: docker-secret
      containers:
      - name: proxyservice
        image: docker.azurecr.io/proxyservice:326
        ports:
        - containerPort: 9163        
        env:
        - name: sup_hostname
          value: "xac-dev-docker4.eastus.cloudapp.azure.com"
      - name: syncservice
        image: docker.azurecr.io/syncservice:326
        ports:
        - containerPort: 23010
        env:
        - name: broker_hostname
          value: "" 
  selector:
    matchLabels:
      app: sampleapp

预期结果应该是部署了 yaml 文件。

不确定这是否与文件的缩进有关。yaml 文件是错误的还是我遗漏了什么?

4

1 回答 1

1

如错误描述中所述,问题在于部署 YAML 的版本兼容性。

no kind "service" is registered for version "v1"

这意味着Kubernetes API 无法识别具有版本v1的资源类型服务,如部署 yaml 的apiVersion: v1中所述

尝试

这个问题的解决方案是在部署 YAML 中使用适当的 apiVersion。在此处输入链接描述

这里有一些参考。


客户端 - 服务器版本不匹配

另外值得一提的是客户端和服务器 Kubernetes 版本之间的版本不匹配。Kubernetes 支持 master 落后于客户端 1 个小版本的兼容性,但实际上并不推荐。由于您的版本是 2 个次要版本,因此我建议使服务器最后匹配客户端的版本。

参考 - https://github.com/kubernetes/community/blob/master/contributors/design-proposals/release/versioning.md#supported-releases-and-component-skew

于 2019-10-24T06:18:32.407 回答