<p>I am fairly new to <code>Kubernetes</code> and have just deployed my first cluster to <code>IBM Cloud</code>. When I created the cluster, I get a dedicated ingress subdomain, which I will be referring to as <code>&lt;long-k8subdomain&gt;.cloud</code> for the scope of this post. Now, this subdomain works for my app. For example: <code>&lt;long-k8subdomain&gt;.cloud/ping</code> works from my browser/curl just fine- I get the expected JSON response back. But, if I add this subdomain to a CNAME record on my domain provider's DNS settings (I have used <code>Bluehost</code> and <code>IBM Cloud's Internet Services</code>), I get a <code>404</code> response back from all routes. However this response is the default <code>nginx</code> 404 response (it says &quot;nginx&quot; under &quot;404 Not Found&quot;). I believe this means that this means the ingress load balancer is being reached, but the request does not get routed right. I am using <code>Kubernetes version 1.20.12_1561 on VPC gen 2</code> and this is my ingress-config.yaml file:</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: my-ingress-resource
  annotations:
    kubernetes.io/ingress.class: &quot;public-iks-k8s-nginx&quot;
    nginx.ingress.kubernetes.io/configuration-snippet: |
      more_set_headers &quot;Host: &lt;long-k8subdomain&gt;.cloud&quot;;
spec:
  rules:
  - host: &lt;long-k8subdomain&gt;.cloud
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: my-service-name
            port:
              number: 80
</code></pre>
<p>I am pretty sure this problem is due to the annotations. Maybe I am using the wrong ones or I do not have enough. Ideally, I would like something like this: api..com/ to route correctly. I have also read a little bit about default backends, but I have not dove too much into that just yet. Any help would be greatly appreciated, as I have spent multiple hours trying to fix this.</p>
<p>Some sources I have used:</p>
<ul>
<li><a href="https://cloud.ibm.com/docs/containers?topic=containers-cs_network_planning" rel="nofollow noreferrer">https://cloud.ibm.com/docs/containers?topic=containers-cs_network_planning</a></li>
<li><a href="https://cloud.ibm.com/docs/containers?topic=containers-ingress-types" rel="nofollow noreferrer">https://cloud.ibm.com/docs/containers?topic=containers-ingress-types</a></li>
<li><a href="https://cloud.ibm.com/docs/containers?topic=containers-comm-ingress-annotations#annotations" rel="nofollow noreferrer">https://cloud.ibm.com/docs/containers?topic=containers-comm-ingress-annotations#annotations</a></li>
</ul>
<p><strong>Note</strong>: The reason why I have the second annotation is because for some reason, requests without that header were not being routed directly. So that was part of my debugging process and I just ended up leaving it as I am not sure if that annotation solves that, so I left it for now.</p>

<p>For the NGINX ingress controller to route requests for your own domain's CNAME record to the service instead of the IBM Cloud one, you need a rule in the ingress where the <code>host</code> identifies your domain.</p>
<p>For instance, if your domain's DNS entry is <code>api.example.com</code>, then change the resource YAML to:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: my-ingress-resource
  annotations:
    kubernetes.io/ingress.class: &quot;public-iks-k8s-nginx&quot;
spec:
  rules:
  - host: api.example.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: my-service-name
            port:
              number: 80
</code></pre>
<p>You should not need the second annotation for this to work.</p>
<p>If you want both of the hosts to work, then you could add a second rule instead of replacing host in the existing one.</p>
