Kubernetes Master API SERVER IP

12/18/2018

I've k8s cluster and pod which one living in there . So , I have got a requirements for pod process .

Pod need a Cluster Ip for manage some jobs . How I can set the API Server name as a Environment variable .

My Pod Yaml shown as below :

 apiVersion: v1
 kind: Pod
 metadata:
  name: api-server-check
 spec:
  containers:
   - name: container-1
   image: project_reg/pod:latest
   env:
    - name: MY_NODE_NAME
      valueFrom:
        fieldRef:
          fieldPath: spec.nodeName
    - name: CLUSTER_IP
      valueFrom:
        fieldRef:
          fieldPath: ???????? ### Problem is here I think . 

If you have another suggestion for me , I will apply it to the Pod yaml . (Shell script or etc .. )

Thanks

-- ColossusMark1
configuration-management
devops
kubernetes

1 Answer

12/18/2018

You can use the cluster internal DNS to point to the Kubernetes API Server.
The API Service should already be exposed as a service called "kubernetes" in the default namespace.
kubernetes.default.svc.cluster.local should resolve to the API server.

Also, if you dump the env inside a running pod you should see that there is an environment variable which already has this information... KUBERNETES_SERVICE_HOST

-- switchboard.op
Source: StackOverflow