<p>Azure kubernetes service allows me to assign only one IP address to one cluster. I have created two namespaces within this cluster and I would like to distinguish those two namespaces by url as environments.</p>
<p><strong>Namespaces</strong></p>
<ul>
<li>stage</li>
<li>dev</li>
</ul>
<p>Desired access to those namespaces would be something like <code>{namespace}.cloudapp.azure.com</code>.</p>
<p>When defining ingress controller in each namespace the same ip address is assigned. How in general should I achieve this separation but keeping the same cluster?</p>

<p>For your use case you only need a single ingress controller. I.e. <a href="https://kubernetes.github.io/ingress-nginx/" rel="nofollow noreferrer">https://kubernetes.github.io/ingress-nginx/</a></p>
<p>To achieve this you need to add DNS entries for the namespaces leading to the single cluster IP.
If you only want to access the two DNS names:</p>
<ul>
<li>stage.cloudapp.azure.com</li>
<li>dev.cloudapp.azure.com</li>
</ul>
<p>adding both entries is probably sufficient if you only want a single application in those namespaces. If you want to deploy multiple applications within the namespaces you should consider adding wildcard DNS entries for:</p>
<ul>
<li>*.stage.cloudapp.azure.com</li>
<li>*.dev.cloudapp.azure.com</li>
</ul>
<p>With this setup you can add ingresses of the following format:</p>
<pre><code>  apiVersion: networking.k8s.io/v1
  kind: Ingress
  metadata:
    name: ingress-example-with-hostname
    namespace: dev
  spec:
  rules:
  - host: dev.cloudapp.azure.com
    http:
      paths:
      - pathType: Prefix
        path: &quot;/&quot;
        backend:
          service:
            name: service
            port:
              number: 80
</code></pre>
<p>For further informations take a look at this documentation: <a href="https://kubernetes.io/docs/concepts/services-networking/ingress/#name-based-virtual-hosting" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/services-networking/ingress/#name-based-virtual-hosting</a></p>
