title: Getting IP into env variable via DNS in kubernetes
body: <p>I'm trying to get my head around K8s coming from <code>docker compose</code>. I would like to setup my first pod with two containers which I pushed to a registry. Following question:</p>
  
  <p>How do I get the IP via DNS into a environment variable, so that registrator can connect to consul? See container registrtor in args <code>consul://consul:8500</code>. The consul needs to be changed with the env.</p>
  
  <pre><code>{
    "kind": "Pod",
    "apiVersion": "v1",
    "metadata": {
      "name": "service-discovery",
      "labels": {
        "name": "service-discovery"
      }
    },
    "spec": {
      "containers": [
        {
          "name": "consul",
          "image": "eu.gcr.io/{myproject}/consul",
          "args": [
            "-server",
            "-bootstrap",
            "-advertise=$(MY_POD_IP)"
          ],
          "env": [{
            "name": "MY_POD_IP",
            "valueFrom": {
              "fieldRef": {
                "fieldPath": "status.podIP"
              }
            }
          }],
          "imagePullPolicy": "IfNotPresent",
          "ports": [
            {
              "containerPort": 8300,
              "name": "server"
            },
            {
              "containerPort": 8400,
              "name": "alt-port"
            },
            {
              "containerPort": 8500,
              "name": "ui-port"
            },
            {
              "containerPort": 53,
              "name": "udp-port"
            },
            {
              "containerPort": 8443,
              "name": "https-port"
            }
          ]
        },
        {
          "name": "registrator",
          "image": "eu.gcr.io/{myproject}/registrator",
          "args": [
            "-internal",
            "-ip=$(MY_POD_IP)",
            "consul://consul:8500"
          ],
          "env": [{
            "name": "MY_POD_IP",
            "valueFrom": {
              "fieldRef": {
                "fieldPath": "status.podIP"
              }
            }
          }],
          "imagePullPolicy": "Always"
        }
      ]
    }
  }
  </code></pre>