简体   繁体   中英

Minikube Ingress shows 404

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

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.

The Accepted answer is bit-old when it was in beta. Here is the updated one

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: pwa-ingress
  annotations:
    ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - http:
      paths:
      - path: /
        pathType: Prefix      
        backend:
          service:
            name: pwa-frontend
            port:
              number: 80

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM