<p>When I run an image in Kubernetes with <code>kubectl run</code>, environment variables are injected into the container.</p>

<p>My problem is that the values are wrong. I do not have anything running at <code>10.0.0.1</code>. I believe the correct value there would be <code>10.1.0.1</code>. This misconfiguration causes, as far as I know, among other things, the error from kube-dns reproduced below.</p>

<p>I would like to ask how are these variables injected into the container, preferably for a link into the code which takes care of this (I could not find anything). Also, some hints where the value 10.0.0.1 could be coming from.</p>

<p>pod variables:</p>

<pre><code>$ kubectl run -i --image=busybox --restart=Never -t busybox
If you don't see a command prompt, try pressing enter.
/ # env
KUBERNETES_SERVICE_PORT=443
KUBERNETES_PORT=tcp://10.0.0.1:443
HOSTNAME=busybox
SHLVL=1
HOME=/root
TERM=xterm
KUBERNETES_PORT_443_TCP_ADDR=10.0.0.1
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
KUBERNETES_PORT_443_TCP_PORT=443
KUBERNETES_PORT_443_TCP_PROTO=tcp
KUBERNETES_SERVICE_PORT_HTTPS=443
KUBERNETES_PORT_443_TCP=tcp://10.0.0.1:443
KUBERNETES_SERVICE_HOST=10.0.0.1
PWD=/
</code></pre>

<p>kube-dns error:</p>

<pre><code>$ kubectl --namespace kube-system logs kube-dns-2190035132-gxf80 kubedns
[...]
E0119 10:04:05.271499      55 reflector.go:199] k8s.io/dns/vendor/k8s.io/client-go/tools/cache/reflector.go:94: Failed to list *v1.Service: Get https://10.0.0.1:443/api/v1/services?resourceVersion=0: dial tcp 10.0.0.1:443: i/o timeout
I0119 10:04:05.771477      55 dns.go:174] Waiting for services and endpoints to be initialized from apiserver...
</code></pre>

<p>The closest thing to <code>10.0.0.1</code> that I have in my config is <code>--service-cluster-ip-range=10.0.0.0/24</code> parameter I am giving to <code>kube-apiserver</code>.</p>

<p>I have the IP <code>10.0.0.1</code> in my etcd, in</p>

<pre><code># ETCDCTL_API=3 etcdctl get "" --from-key
[...]
/registry/services/specs/default/kubernetes
k8s

v1Service


kubernetes▒default"*$b198bc22-fcff-11e7-83a9-185e0fec8ce528B
                                                           Z
        component       apiserverZ
provider
kuberneteszC
▒
httpsTCP▒▒(10.0.0.1"    ClusterIPClientIPBRZ`▒
▒"
/registry/services/specs/kube-system/kubernetes-dashboard
k8s

v1Service

kubernetes-dashboard▒
                     kube-system"*$b9f0daef-fcff-11e7-83a9-185e0fec8ce528B
                                                                         ԾZ,
addonmanager.kubernetes.io/mode ReconcileZ
ppkubernetes-dashboardZ*
kubernetes.io/minikube-addons   dashboardZ3
&amp;kubernetes.io/minikube-addons-endpoint dashboardb
0kubectl.kubernetes.io/last-applied-configuration{"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"addonmanager.kubernetes.io/mode":"Reconcile","app":"kubernetes-dashboard","kubernetes.io/minikube-addons":"dashboard","kubernetes.io/minikube-addons-endpoint":"dashboard"},"name":"kubernetes-dashboard","namespace":"kube-system"},"spec":{"ports":[{"nodePort":30000,"port":80,"targetPort":9090}],"selector":{"app":"kubernetes-dashboard"},"type":"NodePort"}}
z_

TCP▒PG▒(
ppkubernetes-dashboard▒ 10.0.0.82NodePort:NoneBRZCluster`▒
▒"
</code></pre>

<p><a href="https://github.com/kubernetes/kubernetes/blob/v1.9.0/pkg/kubelet/envvars/envvars.go#L45-L48" rel="nofollow noreferrer">https://github.com/kubernetes/kubernetes/blob/v1.9.0/pkg/kubelet/envvars/envvars.go#L45-L48</a> which I found via <code>git grep SERVICE_PORT</code></p>

<p>It's possible that if your <code>kubernetes.default.svc.cluster.local</code> is pointing to the wrong IP, then <code>kubectl --namespace=kube-system edit svc kubernetes</code> and changing the <code>ClusterIP</code> would sort that out; I don't have a cluster in front of me to test it, though</p>
