<p>I'm having some trouble getting the Nginx ingress controller working in my Minikube cluster. It's likely to be some faults in Ingress configuration but I cannot pick it out.</p>
<p>First, I deployed a service and it worked well without ingress.</p>
<pre><code>kind: Service
apiVersion: v1
metadata:
  name: online
  labels:
    app: online
spec:
  selector:
    app: online
  ports:
  - protocol: TCP
    port: 8080
    targetPort: 5001
  type: LoadBalancer

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: online
  labels:
    app: online
spec:
  replicas: 1
  selector:
    matchLabels:
      app: online
  template:
    metadata:
      labels:
        app: online
      annotations:
        dapr.io/enabled: &quot;true&quot;
        dapr.io/app-id: &quot;online&quot;
        dapr.io/app-port: &quot;5001&quot;
        dapr.io/log-level: &quot;debug&quot;
        dapr.io/sidecar-liveness-probe-threshold: &quot;300&quot;
        dapr.io/sidecar-readiness-probe-threshold: &quot;300&quot;
    spec:
      containers:
      - name: online
        image: online:latest
        ports:
        - containerPort: 5001
        env:
        - name: ADDRESS
          value: &quot;:5001&quot;
        - name: DAPR_HTTP_PORT
          value: &quot;8080&quot;
        imagePullPolicy: Never
</code></pre>
<p>Then check its url</p>
<pre><code>minikube service online --url
http://192.168.49.2:32323

</code></pre>
<p>It looks ok for requests.</p>
<pre><code>curl http://192.168.49.2:32323/userOnline
OK
</code></pre>
<p>After that I tried to apply nginx ingress offered by minikube.
I installed ingress and run an example by referring to <a href="https://kubernetes.io/docs/tasks/access-application-cluster/ingress-minikube/" rel="nofollow noreferrer">this</a> and it's all ok.</p>
<p>Lastly, I configured my Ingress.</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: online-ingress
  annotations:
spec:
  rules:
    - host: online
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: online
                port:
                  number: 8080
</code></pre>
<p>And changed /etc/hosts by adding line</p>
<pre><code>192.168.49.2    online
</code></pre>
<p>And Test:</p>
<pre><code>curl online/userOnline
502 Bad Gateway
</code></pre>
<p>The logs are like this:</p>
<pre><code>192.168.49.1 - - [26/Aug/2021:09:45:56 +0000] &quot;GET /userOnline HTTP/1.1&quot; 502 150 &quot;-&quot; &quot;curl/7.68.0&quot; 80 0.002 [default-online-8080] [] 172.17.0.5:5001, 172.17.0.5:5001, 172.17.0.5:5001 0, 0, 0 0.004, 0.000, 0.000 502, 502, 502 578ea1b1471ac973a2ac45ec4c35d927
2021/08/26 09:45:56 [error] 2514#2514: *426717 upstream prematurely closed connection while reading response header from upstream, client: 192.168.49.1, server: online, request: &quot;GET /userOnline HTTP/1.1&quot;, upstream: &quot;http://172.17.0.5:5001/userOnline&quot;, host: &quot;online&quot;
2021/08/26 09:45:56 [error] 2514#2514: *426717 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.49.1, server: online, request: &quot;GET /userOnline HTTP/1.1&quot;, upstream: &quot;http://172.17.0.5:5001/userOnline&quot;, host: &quot;online&quot;
2021/08/26 09:45:56 [error] 2514#2514: *426717 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.49.1, server: online, request: &quot;GET /userOnline HTTP/1.1&quot;, upstream: &quot;http://172.17.0.5:5001/userOnline&quot;, host: &quot;online&quot;
W0826 09:45:56.918446       7 controller.go:977] Service &quot;default/online&quot; does not have any active Endpoint.
I0826 09:46:21.345177       7 status.go:281] &quot;updating Ingress status&quot; namespace=&quot;default&quot; ingress=&quot;online-ingress&quot; currentValue=[] newValue=[{IP:192.168.49.2 Hostname: Ports:[]}]
I0826 09:46:21.349078       7 event.go:282] Event(v1.ObjectReference{Kind:&quot;Ingress&quot;, Namespace:&quot;default&quot;, Name:&quot;online-ingress&quot;, UID:&quot;b69e2976-09e9-4cfc-a8e8-7acb51799d6d&quot;, APIVersion:&quot;networking.k8s.io/v1beta1&quot;, ResourceVersion:&quot;23100&quot;, FieldPath:&quot;&quot;}): type: 'Normal' reason: 'Sync' Scheduled for sync

</code></pre>
<p>I found the error is very about annotations of Ingress. If I changed it to:</p>
<pre><code>  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$1
</code></pre>
<p>The error would be:</p>
<pre><code>404 page not found
</code></pre>
<p>and logs:</p>
<pre><code>I0826 09:59:21.342251       7 status.go:281] &quot;updating Ingress status&quot; namespace=&quot;default&quot; ingress=&quot;online-ingress&quot; currentValue=[] newValue=[{IP:192.168.49.2 Hostname: Ports:[]}]
I0826 09:59:21.347860       7 event.go:282] Event(v1.ObjectReference{Kind:&quot;Ingress&quot;, Namespace:&quot;default&quot;, Name:&quot;online-ingress&quot;, UID:&quot;8ba6fe97-315d-4f00-82a6-17132095fab4&quot;, APIVersion:&quot;networking.k8s.io/v1beta1&quot;, ResourceVersion:&quot;23760&quot;, FieldPath:&quot;&quot;}): type: 'Normal' reason: 'Sync' Scheduled for sync
192.168.49.1 - - [26/Aug/2021:09:59:32 +0000] &quot;GET /userOnline HTTP/1.1&quot; 404 19 &quot;-&quot; &quot;curl/7.68.0&quot; 80 0.002 [default-online-8080] [] 172.17.0.5:5001 19 0.000 404 856ddd3224bbe2bde9d7144b857168e0
</code></pre>
<p>Other infos.</p>
<pre><code>NAME     TYPE           CLUSTER-IP     EXTERNAL-IP   PORT(S)          AGE
online   LoadBalancer   10.111.34.87   &lt;pending&gt;     8080:32323/TCP   6h54m
</code></pre>
<p>The example I mentioned above is a <code>NodePort</code> service and mine is a <code>LoadBalancer</code>, that's the biggest difference. But I don't know why it does not work for me.</p>

tanxin
<p>Moving this out of comments so it will be visible.</p>
<hr />
<p><strong>Ingress</strong></p>
<p>Main issue was with <code>path</code> in ingress rule since application serves traffic on <code>online/userOnline</code>. If requests go to <code>online</code> then ingress returns <code>404</code>.</p>
<p>Rewrite annotation is not needed in this case as well.</p>
<p><code>ingress.yaml</code> should look like:</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: online-ingress
#  annotations:
spec:
  rules:
    - host: online
      http:
        paths:
          - path: /userOnline
            pathType: Prefix
            backend:
              service:
                name: online
                port:
                  number: 8080
</code></pre>
<p>More details about <a href="https://kubernetes.io/docs/concepts/services-networking/ingress/" rel="nofollow noreferrer">ingress</a></p>
<hr />
<p><strong>LoadBalancer on Minikube</strong></p>
<p>Since minikube is considered as <code>bare metal</code> installation, to get <code>external IP</code> for service/ingress, it's necessary to use specially designed <code>metallb</code> solution.</p>
<p><a href="https://metallb.universe.tf/" rel="nofollow noreferrer">MetalLB</a> is a load-balancer implementation for bare metal Kubernetes clusters, using standard routing protocols.</p>
<p>It ships as add-on for <code>minikube</code> and can be enabled with:</p>
<pre><code>minikube addons enable metallb
</code></pre>
<p>And it needs to create a <code>configMap</code> with setup. Please refer to <a href="https://metallb.universe.tf/configuration/" rel="nofollow noreferrer">metallb configuration</a></p>
