<p>I am trying to get yaml for the particular storage class using Kubernetes python client, following code does the job:</p>
<pre><code>list_storage_class = v1.list_storage_class(_preload_content=False)
storageclass = list_storage_class.read().decode('utf-8') # &lt;class 'urllib3.response.HTTPResponse'&gt;
print(json.dumps(json.loads(storageclass),indent=2))
</code></pre>
<p>Is it a way to specify storage class with the call? On the same hand is it possible to get response directly in yaml conforming to <code>k get sc NAME -o yaml</code> ?</p>

l00p
<p>Take a look at the <a href="https://github.com/kubernetes-client/python/blob/master/kubernetes/docs/StorageV1Api.md" rel="nofollow noreferrer"><code>StorageV1API</code></a> documentation. To get a single <code>StorageClass</code>, you want the <code>read_storage_class</code> method:</p>
<pre><code>&gt;&gt;&gt; from kubernetes import client, config
&gt;&gt;&gt; config.load_kube_config()
&gt;&gt;&gt; v1 = client.StorageV1Api()
&gt;&gt;&gt; sc = v1.read_storage_class('ocs-external-storagecluster-ceph-rbd')
&gt;&gt;&gt; sc.metadata.name
'ocs-external-storagecluster-ceph-rbd'
</code></pre>
<p>If you want to dump the result to a YAML document:</p>
<pre><code>&gt;&gt;&gt; import yaml
&gt;&gt;&gt; print(yaml.safe_dump(sc.to_dict()))
allow_volume_expansion: true
allowed_topologies: null
api_version: storage.k8s.io/v1
kind: StorageClass
metadata:
  annotations:
    description: Provides RWO Filesystem volumes, and RWO and RWX Block volumes
    storageclass.kubernetes.io/is-default-class: 'true'
  labels:
    app.kubernetes.io/instance: cluster-resources-ocp-staging
...
</code></pre>
