<p>I need to set my environment in my code based on kubernetes(in AKS)  cluster name in python.
I have 2 clusters stg-my-cluster, prod-my-cluster,
How can I access to this info from inside my pod?
there is a better way ?
thx</p>

torxx666
<p>Once you're inside the cluster, it doesn't know that it has a &quot;name&quot;.  This only exists for management tools, such as the context name in your <code>.kube/config</code> file.</p>
<p>The setup I use day-to-day uses <a href="https://helm.sh" rel="nofollow noreferrer">Helm</a> as the primary installation mechanism, and there is a separate Helm values file per environment.  Our CD system knows how to <code>helm upgrade -f $CLUSTER_NAME.yaml</code>.  In that file we set:</p>
<pre class="lang-yaml prettyprint-override"><code># values.prod.yaml
cluster: prod-my-cluster
</code></pre>
<p>And then you can include that as an environment variable in your Deployment:</p>
<pre class="lang-yaml prettyprint-override"><code>env:
  - name: CLUSTER
    value: {{ .Values.cluster }}
</code></pre>
<p>Once you have it in an environment variable, in Python you can access it using <code>os.environ</code>.</p>
