Minikube Ingress shows 404

9/27/2017

I am following this tutorial: https://cloud.google.com/container-engine/docs/tutorials/http-balancer, but running it inside Minikube with yml files for each steps:

Step 1: Deploy an nginx server

production.yml:

kind: Deployment
apiVersion: extensions/v1beta1
metadata:
  name: pwa-app-production
  labels:
    app: MyApp
spec:
  replicas: 1
  template:
    metadata:
      name: app
      labels:
        app: MyApp
        env: production      
    spec:
      containers:
      - name: nginx
        image: nginx:alpine
        ports:
        - name: nginx
          containerPort: 80

Then:

$ kubectl apply -f production.yml

Step 2: Expose your nginx deployment as a service internally

service.yml:

kind: Service
apiVersion: v1
metadata:
  name: pwa-frontend
spec:
  type: NodePort
  selector:
    app: MyApp
  ports:
  - name: nginx
    port: 80
    protocol: TCP

Then:

$ kubectl apply -f service.yml

Verify the Service was created and a node port was allocated:

$ kubectl get service pwa-frontend

NAME           CLUSTER-IP   EXTERNAL-IP   PORT(S)        AGE
pwa-frontend   10.0.0.28    <nodes>       80:30781/TCP   26m

Step 3: Create an Ingress resource

ingress.yml:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: pwa-ingress
  annotations:
    ingress.kubernetes.io/rewrite-target: /
spec:
  backend:
    serviceName: pwa-frontend
    servicePort: 80

Then:

$ kubectl create -f ingress.yml

Step 4: Visit your application

Find out the external IP address of the load balancer serving your application by running:

$ kubectl describe ing pwa-ingress

Name:           pwa-ingress
Namespace:      default
Address:        192.168.99.100
Default backend:    pwa-frontend:80 (172.17.0.2:80)
Rules:
  Host  Path    Backends
  ----  ----    --------
  * *   pwa-frontend:80 (172.17.0.2:80)
Annotations:
  rewrite-target:   /

Every thing seems working well and all infos outputs seems to correspond to the tutorial. But now:

$ curl 192.168.99.100

default backend - 404
-- Ha Ja
google-cloud-platform
kubernetes

1 Answer

9/27/2017

I am assuming that you deployed the default nginx ingress controller by minikube addons enable ingress. The tutorial you followed is specifically for Google Container Engine, in those clusters there is a different ingress controller deployed which will create Google Cloud Load Balancers and is also capable of exposing plain TCP services. Your nginx ingress controller in minikube is only capable of processing HTTP ingresses like this:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: pwa-ingress
  annotations:
    ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - http:
      paths:
      - path: /
        backend:
          serviceName: pwa-frontend
          servicePort: 80

Use kubectl replace ingress.yml after you modified your file and try your request again.

-- Simon Tesar
Source: StackOverflow