<p>Is there a way to pass environment variables through the services in Kubernetes?</p>

<p>I tried passing it in to my service yaml like this:</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  labels:
    name: kafka
  name: kafka
spec:
  ports:
    - port: 9092
    selector:
      name: kafka
  env:
    - name: BROKER_ID
      value: "1"
</code></pre>

<p>The service is being consumed by kubectl, and is created.</p>

<p>I've confirmed the service is connected to my container through <code>env | grep KAFKA</code> and the output of variables greatly increase, as expected when my service is up.</p>

<p>However, I would like to pass in custom environment-variables that have to be different depending on which instance of the container it is in.</p>

<p>Is this possible?</p>

<p>The way that Kubernetes is designed has Services decoupled from Pods.  You can not inject a Secret or an env var into a running Pod.  What you want is to configure the Pod to use the env var or Secret.</p>
