BadRequest error on deployment of yaml file

10/24/2019

getting a bad request error on deployment of yaml file in kubernetes cluster.

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 cluster is version 1.14.7 with 2 nodepools. one is the default nodepool with a linux node and the other is a windows node pool (node count 1) for windows containers. I am logging into the Azure CLI within the portal itself and running the kubectl commands.

tried apiVersion: apps/v1beta1 but no good.

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"}

Here is the deployment.yaml file

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

Expected result should be that the yaml file be deployed.

not sure if this is related to indentation of the file. Is the yaml file wrong or am i missing something?

-- RAnand
azure-kubernetes
kubernetes
kubernetes-cluster
kubernetes-deployment

1 Answer

10/24/2019

As stated in the error description the issue is with the version compatibility of the deployment YAML.

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

This means the resources type service is not recognized by Kubernetes API with version v1 as mentioned in the deployment yaml's apiVersion: v1

Try

This issue has the solution which is to use the appropriate apiVersion in the deployment YAML. enter link description here

Here are some references.


Client - Server Version Mismatch

Also worth mentioning is the version mismatch between the client and server kubernetes version. Kubernetes supports compatibility of master being behind the client by 1 minor version but that is not really recommended. Since your versions are 2 minor versions apart I would recommend making the server to atelast match the client's version.

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

-- damitj07
Source: StackOverflow