Minikube with Ingress local image configuration

12/5/2019

When I use my NodePort service I can get to my app. But when I try to hit it by Ingress I always get HTTP 404. That not happen with test image gcr.io/google-samples/hello-app:1.0 from this image I have response. This is my Deployment:

apiVersion: apps/v1
kind: Deployment
metadata:
 name: app-backend-deployment
 labels:
  app: app-backend
spec:
 replicas: 1
 selector:
    matchLabels:
      app: app-backend
 template:
    metadata:
      labels:
        app: app-backend
    spec:
     containers:
     - name: app-backend
       image: go-app-backend
       ports:
       - containerPort: 8100
       imagePullPolicy: Never

My NodePort Service :

apiVersion: v1
kind: Service
metadata:
 labels:
  app: app-backend-deployment
 name: app-backend-svc-nodeport
spec:
 type: NodePort
 ports:
 - port: 8020
   protocol: TCP
   targetPort: 8100
 selector:
  app: app-backend

In that point when I call $ minikube service church-backend-svc-nodeport --url I get address where my app works.

But when I try to configure my app to get the route on Ingress it didn't work:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
 annotations:
  nginx.ingress.kubernetes.io/rewrite-target: /$1
 name: app-backend-ingress
spec:
 rules:
 - host: app-backend.io
   http:
     paths:
       - backend:
          serviceName: app-backend-svc-nodeport
          servicePort: 8020
         path: /backend

But when I do a configuration with example hello word app (https://kubernetes.io/docs/tasks/access-application-cluster/ingress-minikube/) and replace everything in ingress.yml everything works great. Can anyone look at this and tell me what am I doing wrong?

-- Adriano
kubernetes-ingress
minikube

1 Answer

12/5/2019

If I'm not mistaken, you need to put in ingress under backend path: /backend(/|$)(.*) and in metadata nginx.ingress.kubernetes.io/rewrite-target: /$2

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$2
  name: app-backend-ingress
spec:
  rules:
  - host: app-backend.io
    http:
      paths:
      - backend:
        serviceName: app-backend-svc-nodeport
        servicePort: 8020
        path: /backend(/|$)(.*)
-- Milan Jaric
Source: StackOverflow