<p>We have defined our internal Load Balancer.</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: ads-aks-test
  annotations:
    service.beta.kubernetes.io/azure-load-balancer-internal: &quot;true&quot;
spec:
  type: LoadBalancer
  ports:
  - protocol: TCP
    port: 9000
  selector:
    app: ads-aks-test
</code></pre>
<p>It has its IP and External IP. We want to access this service from VM in another Virtual Network.
We need to know it's <strong>DNS name</strong> - fully qualified name in advance because we are deploying multiple applications from deployment platform and we want to know based on its Service Name how we can access it once it is being successfully deployed and not to wait for IP address to be determined (either manually or automatically). So for example that is our APP1, and after that automatically we install application APP2 which needs to reach this service.
So for that reason we would like to avoid using the IP information.</p>
<p>How we can determine what is the service &quot;hostname&quot; by which we will access it from the second application?</p>
<p>Only information in docs which I found is: &quot;If your service is using a dynamic or static public IP address, you can use the service annotation service.beta.kubernetes.io/azure-dns-label-name to set a public-facing DNS label.&quot; - but this is for public load balancer which we do not want!</p>

<p>Set up <a href="https://github.com/kubernetes-sigs/external-dns" rel="nofollow noreferrer">ExternalDNS</a> in your K8s cluster. Here is a guide for <a href="https://github.com/kubernetes-sigs/external-dns/blob/master/docs/tutorials/azure-private-dns.md" rel="nofollow noreferrer">Azure Private DNS</a>. This will allow you to update the DNS record for any hostname you pick for the service, dynamically via Kubernetes resources.</p>
<p>Sample config looks like this (excerpted from <a href="https://github.com/kubernetes-sigs/external-dns/blob/master/docs/tutorials/azure-private-dns.md" rel="nofollow noreferrer">Azure Private DNS</a> guide)</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: externaldns
spec:
  selector:
    matchLabels:
      app: externaldns
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: externaldns
    spec:
      containers:
      - name: externaldns
        image: k8s.gcr.io/external-dns/external-dns:v0.7.3
        args:
        - --source=service
        - --source=ingress
        - --domain-filter=example.com
        - --provider=azure-private-dns
        - --azure-resource-group=externaldns
        - --azure-subscription-id=&lt;use the id of your subscription&gt;
        volumeMounts:
        - name: azure-config-file
          mountPath: /etc/kubernetes
          readOnly: true
      volumes:
      - name: azure-config-file
        secret:
          secretName: azure-config-file
</code></pre>
