<p>My pod has a volume as:</p>
<pre class="lang-json prettyprint-override"><code>        &quot;volumes&quot;: [
            {
                &quot;name&quot;: &quot;configs&quot;,
                &quot;secret&quot;: {
                    &quot;defaultMode&quot;: 420,
                    &quot;secretName&quot;: &quot;some_secret&quot;
                }
            },
            ....]
</code></pre>
<p>I want to be able to read it using Python as <code>V1Volume</code>.</p>
<p>Tried to do:</p>
<pre class="lang-py prettyprint-override"><code>    from kubernetes import config
    config.load_incluster_config()
    spec = client.V1PodSpec()
</code></pre>
<p>But I'm stuck as it gives me</p>
<pre class="lang-py prettyprint-override"><code>    raise ValueError(&quot;Invalid value for `containers`, must not be `None`&quot;)
</code></pre>
<p>and I'm not sure how to continue. How can I get the volumes from the <code>V1PodSpec</code>?</p>

<p>It gives you the error because you initialise <code>V1PodSpec</code> without any arguments. <code>V1PodSpec</code> used to create pods, not to read them.</p>
<p>To read pod <code>spec</code> from Kubernetes:</p>
<pre class="lang-py prettyprint-override"><code>from  kubernetes import client,config
config.load_kube_config()
# or 
# config.load_incluster_config()
core_api = client.CoreV1Api()
response = core_api.read_namespaced_pod(name=&quot;debug-pod&quot;, namespace='dev')

# access volumes in the returned response
type(response.spec.volumes[0])
# returns:
# &lt;class 'kubernetes.client.models.v1_volume.V1Volume'&gt;
</code></pre>
