<p>I have a helm chart that installs/creates an instance of our app. Our app consist of multiple micro-services and one of them is nginx. The nginx service is of type loadbalancer. </p>

<p>So when user first tries to hit the loadbalancer IP from browser, I want to open a web page which will ask him to bind some domains (e.g. a.yourdomain.com and b.yourdomain.com) with the loadbalancer IP and once he does that, he will click on "verify" button and at that time I want to check on the server side if the domains are correctly pointing to the loadbalancer IP or not.</p>

<p>Now the problem is <em>how can I get the loadbalancer external IP inside the nginx pod so that I can ping the domains and check if they are poining to the loadbalancer IP or not.</em></p>

<p><strong>Edit</strong></p>

<p>Note: I would like to avoid using kubectl because I do not want to install this extra utility for one time job.</p>

Yogeshwar Singh
<p>I have found a solution, tested and it's working.</p>

<p>To find ExternalIP associated with nginx service of type LoadBalancer you want to create a service account:</p>

<pre><code>kubectl create serviceaccount hello
</code></pre>

<p>and also create Role and RoleBindind like folllowing:</p>

<pre><code>apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: read-services
rules:
- apiGroups: [""]
  resources: ["services"]
  verbs: ["get", "watch", "list"]

---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: read-services
  namespace: default
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: read-services
subjects:
- kind: ServiceAccount
  name: hello
  namespace: default
</code></pre>

<p>Then you create your pod with <code>serviceAccount: hello</code></p>

<p>and now you can make a curl request to api-server <a href="https://kubernetes.io/docs/tasks/administer-cluster/access-cluster-api/#without-using-a-proxy" rel="nofollow noreferrer">like shown in k8s documentation</a>:</p>

<pre><code>APISERVER=https://kubernetes.default.svc
SERVICEACCOUNT=/var/run/secrets/kubernetes.io/serviceaccount
NAMESPACE=$(cat ${SERVICEACCOUNT}/namespace)
TOKEN=$(cat ${SERVICEACCOUNT}/token)
CACERT=${SERVICEACCOUNT}/ca.crt

curl --cacert ${CACERT} --header "Authorization: Bearer ${TOKEN}" -X GET ${APISERVER}/api/v1/namespaces/$NAMESPACE/services/nginx/
</code></pre>

<p>under <code>.status.loadBalancer.ingress[0].ip</code> should be IP you are looking for.</p>

<p>Let me know if it was helpful.</p>
