部署 yaml 文件时出现 BadRequest 错误

BadRequest error on deployment of yaml file

在 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)。我正在门户本身和 运行 kubectl 命令中登录到 Azure CLI。

试过 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 文件错误还是我遗漏了什么?

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

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

这意味着资源类型 service 无法被 Kubernetes API 和版本 v1 识别,如部署 yaml 中所述api版本:v1

尝试

这个问题有解决方案,就是在部署 YAML 中使用适当的 apiVersion。 enter link description here

这里有一些参考。


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

另外值得一提的是客户端和服务端的kubernetes版本不匹配。 Kubernetes 通过 1 个次要版本支持 master 在客户端后面的兼容性,但这并不是真正推荐的。由于您的版本相隔 2 个次要版本,因此我建议使服务器至少与客户端的版本相匹配。

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