<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
<blockquote>
<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>
</blockquote>
<p>If the URL works when using the nodeport and not without the nodeport, then this means that the ingress is not configured properly for what you want to do.</p>
<blockquote>
<p>Is there a method to test this in a different way to figure out where the problem is?</p>
</blockquote>
<p>Steps for troubleshooting are:</p>
<ol>
<li>The first step is determine if the error is from the ingress or from your back-end service.</li>
</ol>
<p>In your case, the error <code>This site can’t be reached somehostname.xyz refused to connect</code>, sounds like the Ingress found the service to map to and used port 5000 to connect to it, and the connection was refused or nothing was listening on port 5000 for that service.</p>
<ol start="2">
<li>I'd next look at the auth-svc logs to see that that request came into the system and why it was refused.</li>
</ol>
<p>My guess is that the auth service is listening on port <code>31840</code> but your ingress says to connect to port <code>5000</code> based on the configuration.</p>
<p>You might try adding a port mapping from 80 to 31840 as a hack/test to see if you get a different error.</p>
<p>Something like:</p>
<pre><code>spec:
  rules:
  - host: &quot;somehostname.xyz&quot;
    http:
      paths:
      - path: &quot;/&quot;
        backend:
          service:
            port:
              number: 31840

</code></pre>
<p>I've only included the part needed to show the indentation properly.
So the other way to test this out is to create additional URLs that map to different ports, so for example:</p>
<pre><code>/try1 =&gt; auth-svc:5000
/try2 =&gt; auth-svc:31840
/try3 =&gt; auth-svc:443
</code></pre>
<p>The other part that I haven't played with that might be an issue is that you are using http and I don't know of any auth service that would use http, so simply trying to connect using http to an app that wants https will get a connection either refused or a strange error, so that might be related to the problem/error you are seeing.</p>
<p>Hope this gives you some ideas to try.</p>
