<p>Using Kubernetes is there a way from other pods to get the <code>ingress.spec.tls.hosts</code> value without using <code>kubectl</code> <em>(DNS, ENVVAR, OTHER)</em>?</p>

<p>I know I can do:</p>

<pre><code># in other pod
dig +short my-app.default.svc.cluster.local
172.20.203.19

echo $MY_APP_SERVICE_HOST
172.20.203.19

echo $MY_APP_SERVICE_PORT
3000
</code></pre>

<p>Or:</p>

<pre><code># in other pod
dig +short SRV my-app.default.svc.cluster.local
0 100 3000 my-app.default.svc.cluster.local.
</code></pre>

<p>But I actually want to connect to the external load balancer of <code>my-app</code> which has an ingress definition of:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: my-app-ingress
  annotations:
    kubernetes.io/ingress.class: "traefik"
    kubernetes.io/tls-acme: "true"
spec:
  tls:
  - hosts:
    - myapp.mydomain.com
  rules:
  - host: myapp.mydomain.com
    http:
      paths:
      - path: /
        backend:
          serviceName: my-app
          servicePort: http
</code></pre>

<p>So, I want to dynamically get <code>myapp.mydomain.com</code> from pods.</p>

Justin
<p>Use the kubernetes api to get an ingress resource. Create a role, associate it with a service account, then list your ingresses using curl for instance. An example below for the default namespace and service account:</p>

<pre><code>---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: ingress-clusterrole
  namespace: default
rules:
- apiGroups: ["*"] # "" indicates the core API group
  resources: ["ingresses"]
  verbs: ["*"]

---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: ingress-clusterrolebinding
  namespace: default
roleRef:
  name: ingress-clusterrole
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
subjects:
  - name: default
    namespace: default
    kind: ServiceAccount
</code></pre>

<pre class="lang-sh prettyprint-override"><code>curl --cacert /var/run/secrets/kubernetes.io/serviceaccount/ca.crt -H "Authorization: Bearer $(cat /var/run/secrets/kubernet
es.io/serviceaccount/token)" -H "Accept: application/json" -H "Content-Type: application/json" https://kubernetes.default.svc/ap
is/extensions/v1beta1/namespaces/default/ingresses | jq '.items'
</code></pre>
