<p>I want my application to behave differently based on whether it's running within K8s vs on developer machines.</p>

<p>Is there any way that my Java application can get to know if it's running within the context of K8s?</p>

Aravind
<p>One way would be to look for environment variables that are exclusively present when your application is running in a Kubernetes cluster.</p>

<p>You can get a list of those variables with: <code>kubectl exec -it -n &lt;namespace&gt; &lt;pod&gt; printenv | grep '^KUBERNETES_'</code>. For reference, these are the variables I get (service pod):</p>

<ul>
<li><code>KUBERNETES_SERVICE_HOST</code></li>
<li><code>KUBERNETES_PORT_443_TCP</code></li>
<li><code>KUBERNETES_SERVICE_PORT_HTTPS</code></li>
<li><code>KUBERNETES_PORT</code></li>
<li><code>KUBERNETES_PORT_443_TCP_ADDR</code></li>
<li><code>KUBERNETES_PORT_443_TCP_PORT</code></li>
<li><code>KUBERNETES_SERVICE_PORT</code></li>
<li><code>KUBERNETES_PORT_443_TCP_PROTO</code></li>
</ul>
