<p>I'm getting Microsoft.Rest.HttpOperationException: 'Operation returned an invalid status code 'BadRequest'' on this line.</p>

<p><code>var result = client.CreateNamespacedDeployment(deployment, namespace);</code></p>

<p>Kubernetes-client has a small number of good resources and most of them is written in other language such as java and python. So i'm referring to these documentations.</p>

<p>this is my implementation so far.</p>

<pre><code>        V1Deployment deployment = new V1Deployment()
        {
            ApiVersion = "extensions/v1beta1",
            Kind = "Deployment",
            Metadata = new V1ObjectMeta()
            {
                Name = "...",
                NamespaceProperty = env,
                Labels = new Dictionary&lt;string, string&gt;()
                {
                    { "app", "..." }
                }
            },
            Spec = new V1DeploymentSpec
            {
                Replicas = 1,
                Selector = new V1LabelSelector()
                {
                    MatchLabels = new Dictionary&lt;string, string&gt;
                    {
                        { "app", "..." }
                    }
                },
                Template = new V1PodTemplateSpec()
                {
                    Metadata = new V1ObjectMeta()
                    {
                        CreationTimestamp = null,
                        Labels = new Dictionary&lt;string, string&gt;
                        {
                             { "app", "..." }
                        }
                    },
                    Spec = new V1PodSpec
                    {
                        Containers = new List&lt;V1Container&gt;()
                        {
                            new V1Container()
                            {
                                Name = "...",
                                Image = "...",
                                ImagePullPolicy = "Always",
                                Ports = new List&lt;V1ContainerPort&gt; { new V1ContainerPort(80) }
                            }
                        }
                    }
                }
            },
            Status = new V1DeploymentStatus()
            {
                Replicas = 1    
            }
        };

        var result = client.CreateNamespacedDeployment(deployment, namespace);
</code></pre>

<p>I want to know the proper way on how to create kubernetes deployment using kubernetes-client, and also i want to know the cause of this issue.</p>

PANDA MAN
<p>For the full clarity and future visitors, it's worth to mention, what is exactly behind this bad request error (code: 400) returned from API server, when using your code sample:</p>

<pre><code>"the API version in the data (extensions/v1beta1) does not match the expected API version (apps/v1)"
</code></pre>

<p>Solution: </p>

<pre><code> ApiVersion = "extensions/v1beta1" -&gt; ApiVersion = "apps/v1"
</code></pre>

<p>Full code sample:</p>

<pre><code> private static void Main(string[] args)
        {
            var k8SClientConfig = new KubernetesClientConfiguration {  Host = "http://127.0.0.1:8080" };
            IKubernetes client = new Kubernetes(k8SClientConfig);

            ListDeployments(client);

            V1Deployment deployment = new V1Deployment()
            {
                ApiVersion = "apps/v1",
                Kind = "Deployment",
                Metadata = new V1ObjectMeta()
                {
                    Name = "nepomucen",
                    NamespaceProperty = null,
                    Labels = new Dictionary&lt;string, string&gt;()
                {
                    { "app", "nepomucen" }
                }
                },
                Spec = new V1DeploymentSpec
                {
                    Replicas = 1,
                    Selector = new V1LabelSelector()
                    {
                        MatchLabels = new Dictionary&lt;string, string&gt;
                    {
                        { "app", "nepomucen" }
                    }
                    },
                    Template = new V1PodTemplateSpec()
                    {
                        Metadata = new V1ObjectMeta()
                        {
                            CreationTimestamp = null,
                            Labels = new Dictionary&lt;string, string&gt;
                        {
                             { "app", "nepomucen" }
                        }
                        },
                        Spec = new V1PodSpec
                        {
                            Containers = new List&lt;V1Container&gt;()
                        {
                            new V1Container()
                            {
                                Name = "nginx",
                                Image = "nginx:1.7.9",
                                ImagePullPolicy = "Always",
                                Ports = new List&lt;V1ContainerPort&gt; { new V1ContainerPort(80) }
                            }
                        }
                        }
                    }
                },
                Status = new V1DeploymentStatus()
                {
                    Replicas = 1
                }
            };
</code></pre>
