<p>getting a bad request error on deployment of yaml file in kubernetes cluster. </p>

<pre><code>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"

</code></pre>

<p>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.</p>

<p>tried apiVersion: apps/v1beta1 but no good. </p>

<pre><code>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"}
</code></pre>

<p>Here is the deployment.yaml file</p>

<pre><code>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

</code></pre>

<p>Expected result should be that the yaml file be deployed. </p>

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

RAnand
<p>As stated in the error description the issue is with the version compatibility of the deployment YAML. </p>

<p><code>no kind "service" is registered for version "v1"</code> </p>

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

<p>Try</p>

<p>This issue has the solution which is to use the appropriate apiVersion in the deployment YAML. <a href="https://github.com/kubernetes/kubernetes/issues/55894" rel="nofollow noreferrer">enter link description here</a></p>

<p>Here are some references.</p>

<ul>
<li><a href="https://kubernetes.io/docs/concepts/overview/kubernetes-api/#api-groups" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/overview/kubernetes-api/#api-groups</a></li>
<li>[for version 1.14] <a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.14/" rel="nofollow noreferrer">https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.14/</a></li>
</ul>

<hr>

<p><strong>Client - Server Version Mismatch</strong></p>

<p>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. </p>

<p>Reference - <a href="https://github.com/kubernetes/community/blob/master/contributors/design-proposals/release/versioning.md#supported-releases-and-component-skew" rel="nofollow noreferrer">https://github.com/kubernetes/community/blob/master/contributors/design-proposals/release/versioning.md#supported-releases-and-component-skew</a></p>
