<p>I'm pretty new to Kubernetes and I have to create a pod using Kubernetes <a href="https://github.com/kubernetes-client/python" rel="nofollow noreferrer">python-client</a>.
So to experiment around I'm trying to run <a href="https://github.com/kubernetes-client/python/tree/master/examples/notebooks" rel="nofollow noreferrer">examples notebooks</a> provided by the project without any change to see how things works.</p>
<p>Starting with <a href="https://github.com/kubernetes-client/python/blob/master/examples/notebooks/intro_notebook.ipynb" rel="nofollow noreferrer">intro_notebook.ipynb</a> at 3rd step I get an error:</p>
<pre class="lang-none prettyprint-override"><code>ValueError: Invalid value for `selector`, must not be `None`
</code></pre>
<p>Here is the code:</p>
<pre><code>from kubernetes import client, config
</code></pre>
<p>The only part I've changed is the second cell, because I'm running Kubernetes using Ubuntu's <code>microk8s</code>:</p>
<pre class="lang-py prettyprint-override"><code>config.load_kube_config('/var/snap/microk8s/current/credentials/client.config')
</code></pre>
<pre class="lang-py prettyprint-override"><code>api_instance = client.AppsV1Api()
dep = client.V1Deployment()
spec = client.V1DeploymentSpec() # &lt;&lt;&lt; At this line I hit the error!
</code></pre>
<p>Complete Traceback:</p>
<pre><code>ValueError                                Traceback (most recent call last)
&lt;ipython-input-9-f155901e8381&gt; in &lt;module&gt;
      1 api_instance = client.AppsV1Api()
      2 dep = client.V1Deployment()
----&gt; 3 spec = client.V1DeploymentSpec()

~/.local/share/virtualenvs/jupyter-2hJZ4kgI/lib/python3.8/site-packages/kubernetes/client/models/v1_deployment_spec.py in __init__(self, min_ready_seconds, paused, progress_deadline_seconds, replicas, revision_history_limit, selector, strategy, template)
     76         if revision_history_limit is not None:
     77             self.revision_history_limit = revision_history_limit
---&gt; 78         self.selector = selector
     79         if strategy is not None:
     80             self.strategy = strategy

~/.local/share/virtualenvs/jupyter-2hJZ4kgI/lib/python3.8/site-packages/kubernetes/client/models/v1_deployment_spec.py in selector(self, selector)
    215         &quot;&quot;&quot;
    216         if selector is None:
--&gt; 217             raise ValueError(&quot;Invalid value for `selector`, must not be `None`&quot;)  # noqa: E501
    218 
    219         self._selector = selector

ValueError: Invalid value for `selector`, must not be `None`
</code></pre>
<p>I'm running <code>python3.8</code>:</p>
<pre class="lang-sh prettyprint-override"><code>$ pip freeze | grep -e kuber
kubernetes==11.0.0

$ snap list microk8s 
Name      Version  Rev   Tracking       Publisher   Notes
microk8s  v1.18.6  1551  latest/stable  canonical✓  classic
</code></pre>
<h2>Update</h2>
<p>Downgrading microk8s to v1.15.11 did not solve the issue.</p>

<p>It's because they changed the validation to happen in the constructor, rather that later -- which is not what the notebook was expecting. <s>They</s> You just need to move those inner assignments up to be valid before constructing the <code>Deployment</code>:</p>
<pre class="lang-py prettyprint-override"><code>name = &quot;my-busybox&quot;
spec = client.V1DeploymentSpec(
    selector=client.V1LabelSelector(match_labels={&quot;app&quot;:&quot;busybox&quot;}),
    template=client.V1PodTemplateSpec(),
)
container = client.V1Container(
    image=&quot;busybox:1.26.1&quot;,
    args=[&quot;sleep&quot;, &quot;3600&quot;],
    name=name,
)
spec.template.metadata = client.V1ObjectMeta(
    name=&quot;busybox&quot;,
    labels={&quot;app&quot;:&quot;busybox&quot;},
)
spec.template.spec = client.V1PodSpec(containers = [container])
dep = client.V1Deployment(
    metadata=client.V1ObjectMeta(name=name),
    spec=spec,
)
</code></pre>
