<p>I have the following code using the k8s python client:</p>
<pre><code>config.load_incluster_config()
v1 = client.CoreV1Api()
object_meta = k8s.V1ObjectMeta(generate_name='myprefix',
                               namespace='my_name_space')
body = k8s.V1Secret(string_data=data, kind='Secret', type='my_type', metadata=object_meta)
api_response = v1.create_namespaced_secret(namespace='my_name_space', body=body)
</code></pre>
<p>This creates a secret in my K8s namespace. Since I'm using generate_name it assigned to it some random value with the prefix I gave so the name can be <code>myprefix-fbdsu3</code> or anything like it.</p>
<p>My question is how do I get the name assigned to that secret after it was created?</p>

Slava
<p>You can pass the secret name into this code and get the example of the secret</p>
<pre><code>from kubernetes import client, config
config.load_kube_config()
v1 = client.CoreV1Api()
secret = v1.read_namespaced_secret(&quot;Secret-name&quot;, &quot;Namespace-Name&quot;)
print(secret)
</code></pre>
<p>decode the secret and get the detail s</p>
<pre><code>from kubernetes import client, config
import base64
import sys    
config.load_kube_config()
v1 = client.CoreV1Api()
sec = str(v1.read_namespaced_secret(&quot;secret-name&quot;, &quot;namespace-name&quot;).data)
pas = base64.b64decode(sec.strip().split()[1].translate(None, '}\''))
print(pas)
</code></pre>
<p>Read more at : <a href="https://www.programcreek.com/python/?CodeExample=create+secret" rel="nofollow noreferrer">https://www.programcreek.com/python/?CodeExample=create+secret</a></p>
