<p>I'm trying a simple microservices app on a cloud Kubernetes cluster. This is the Ingress yaml:</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-nginx-nginx-ingress
  namespace: default
  annotations:
    kubernetes.io/ingress.class: nginx  
spec:
  defaultBackend:
    service:
      name: auth-svc
      port:
        number: 5000
  rules:
  - host: &quot;somehostname.xyz&quot;
    http:
      paths:
      - path: &quot;/&quot;
        pathType: Prefix
        backend:
          service:
            name: auth-svc
            port:
              number: 5000
</code></pre>
<p><strong>The problem:</strong><br />
When I use this URL, I'm able to access the auth service: <code>http://somehostname.xyz:31840</code>. However, if I use <code>http://somehostname.xyz</code>, I get a <em>&quot;This site can’t be reached somehostname.xyz refused to connect.&quot;</em> error.<br />
The auth service sends GET requests to other services too, and I'm able to see the response from those services if I use:<br />
<code>http://somehostname.xyz:31840/go</code> or <code>http://somehostname.xyz:31840/express</code>. But again, these work only if the nodeport <code>31840</code> is used.</p>
<p><strong>My questions:</strong></p>
<ul>
<li><p>What typically causes such a problem, where I can access the service
using the hostname and nodeport, but it won't work without supplying the
nodeport?</p>
</li>
<li><p>Is there a method to test this in a different way to figure out where
the problem is?</p>
</li>
<li><p>Is it a problem with the Ingress or Auth namespace? Is it a problem
with the hostname in Flask? Is it a problem with the Ingress
controller? How do I debug this?</p>
</li>
</ul>
<p>These are the results of <code>kubectl get all</code> and other commands.</p>
<pre><code>NAME                                               READY   STATUS     RESTARTS
pod/auth-flask-58ccd5c94c-g257t                    1/1     Running    0          
pod/ingress-nginx-nginx-ingress-6677d54459-gtr42   1/1     Running    0  




NAME                                  TYPE           EXTERNAL-IP      PORT(S)             
service/auth-svc                      ClusterIP      &lt;none&gt;           5000/TCP            
service/ingress-nginx-nginx-ingress   LoadBalancer   172.xxx.xx.130   80:31840/TCP,443:30550/TCP 



NAME                                          READY   UP-TO-DATE   AVAILABLE 
deployment.apps/auth-flask                    1/1     1            1          
deployment.apps/ingress-nginx-nginx-ingress   1/1     1            1  

    


NAME                                                     DESIRED   CURRENT   READY 
replicaset.apps/auth-flask-58ccd5c94c                    1         1         1    
replicaset.apps/ingress-nginx-nginx-ingress-6677d54459   1         1         1 




NAME                          CLASS    HOSTS                   ADDRESS          PORTS   
ingress-nginx-nginx-ingress   &lt;none&gt;   somehostname.xyz   172.xxx.xx.130   80 
</code></pre>
<p>Describing ingress also seems normal.</p>
<pre><code>kubectl describe ingress ingress-nginx-nginx-ingress
Name:             ingress-nginx-nginx-ingress
Namespace:        default
Address:          172.xxx.xx.130
Default backend:  auth-svc:5000 (10.x.xx.xxx:5000)
Rules:
  Host                   Path  Backends
  ----                   ----  --------
  somehostname.xyz  
                         /   auth-svc:5000 (10.x.xx.xxx:5000)
Annotations:             kubernetes.io/ingress.class: nginx
</code></pre>
<p>This is the code of Auth.</p>
<pre><code>import requests
from flask import Flask

app = Flask(__name__)

@app.route('/')
def indexPage():
    return '  &lt;!DOCTYPE html&gt;&lt;html&gt;&lt;head&gt;&lt;meta charset=&quot;UTF-8&quot; /&gt;\
    &lt;title&gt;Microservice&lt;/title&gt;&lt;/head&gt; \
    &lt;body&gt;&lt;div style=&quot;text-align: center;&quot;&gt;Welcome to the Auth page&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;'
       
@app.route('/go')
def getGoJson():
    return requests.get('http://analytics-svc:8082/info').content
    
@app.route('/express')
def getNodeResponse():
    return requests.get('http://node-svc:8085/express').content

if __name__ == '__main__':
    app.run(debug=True, host=&quot;0.0.0.0&quot;)
</code></pre>
<p>and Auth's Dockerfile:</p>
<pre><code>FROM python:3.8-slim-buster
WORKDIR /usr/src/app
ENV FLASK_APP=app.py
ENV FLASK_RUN_HOST=0.0.0.0
ENV FLASK_ENV=development 
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
COPY . .
CMD [&quot;flask&quot;, &quot;run&quot;] 
</code></pre>
<p>The part of docker-compose yaml for auth:</p>
<pre><code>version: &quot;3.3&quot;
services:
  auth:
    build: ./auth/
    image: nav9/auth-flask:v1 
    ports:
    - &quot;5000:5000&quot;
</code></pre>
<p>Auth's Kubernetes manifest:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: auth-flask
spec:
  selector:
    matchLabels:
      any-name: auth-flask
  template:
    metadata:
      labels:
        any-name: auth-flask
    spec:
      containers:
        - name: auth-name
          image: nav9/auth-flask:v1
          imagePullPolicy: Always
          ports:
            - containerPort: 5000
---
apiVersion: v1
kind: Service
metadata:
  name: auth-svc
spec:
#  type: ClusterIP
  ports:
    - targetPort: 5000
      port: 5000
  selector:
    any-name: auth-flask
</code></pre>

Nav
<p>The solution has three parts:</p>
<ol>
<li><p>Use <code>kubectl get all</code> to find out the running ingress service:</p>
<pre><code>NAME                                 TYPE           EXTERNAL-IP     PORT(S)
service/ingress-nginx-nginx-ingress  LoadBalancer   172.xxx.xx.130  80:31840/TCP,443:30550/TCP
</code></pre>
</li>
</ol>
<p>Copy the EXTERNAL-IP of the service (in this case 172.xxx.xx.130).</p>
<ol start="2">
<li><p>Add a DNS A record named <code>*.somehostname.xyz</code> for the cloud cluster, and use the IP address <code>172.xxx.xx.130</code>.</p>
</li>
<li><p>When accessing the hostname via the browser, make sure that <code>http</code> is used instead of <code>https</code>.</p>
</li>
</ol>
