简体   繁体   English

Minikube Ingress(Nginx 控制器)不工作

[英]Minikube Ingress (Nginx Controller) not working

I have a spring boot application deployed to minikube.我有一个部署到 minikube 的 Spring Boot 应用程序。 The application has a get mapping exposed as -该应用程序有一个公开的获取映射 -

@GetMapping("/ping")
    public String get(){
        return "Hello !!";
    }

Created and applied the deployment and the service.创建并应用部署和服务。 Both are fine and the demo-app container is also running in the cluster.两者都很好, demo-app容器也在集群中运行。

Deployment manifest部署清单

apiVersion: apps/v1
kind: Deployment
metadata:
  name: demo-app-deployment
  labels:
    app: demo-app
spec:
  selector:
    matchLabels:
      app: demo-app
  replicas: 1
  template:
    metadata:
      labels:
        app: demo-app
    spec:
      imagePullSecrets:
      - name: regcred
      containers:
      - name: demo-app
        image: <<image>>
        imagePullPolicy: Always
        ports:
        - containerPort: 8080

Service manifest服务清单

apiVersion: v1
kind: Service
metadata:
  name: demo-app-service
spec:
  selector:
    app: demo-app
  ports:
  - protocol: TCP
    port: 8080
    targetPort: 8080

As the last step -作为最后一步——

  1. Created the Ingress object in the minikube cluster using kubectl create -f ingress.yaml使用kubectl create -f ingress.yaml在 minikube 集群中创建 Ingress 对象
  2. And mapped the minikube ip to this ingress host demo.com in Windows hosts file并将minikube ip映射到 Windows 主机文件中的这个入口主机demo.com

Ingress manifest入口清单

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: demo-app-ingress
spec:
  rules:
    - host: demo.com
      http:
        paths:
          - path: /demo
            backend:
              serviceName: demo-app-service
              servicePort: 8080

While trying to access the app from browser, via http://demo.com/demo/ping it is giving whiteLabel Error Page在尝试从浏览器访问该应用程序时,通过http://demo.com/demo/ping它给出了 whiteLabel 错误页面在此处输入图片说明

Please help.请帮忙。

First what is happening: You specified that you wish to reach the service demo-app-service when you access the URI http://demo.com/demo .首先发生了什么:您指定在访问 URI http://demo.com/demo时希望访问服务 demo-app-service。 That part is working fine.那部分工作正常。 The question here is which path is called on the service?这里的问题是在服务上调用了哪条路径? Ie the URI http://demo.com/demo/ping would request the endpoint /demo/ping in your service.即 URI http://demo.com/demo/ping将请求您的服务中的端点 /demo/ping。 I guess your ping service is locally accessible via the endpoint http://localhost:8080/ping .我猜您的 ping 服务可以通过端点 http://localhost:8080/ping 在本地访问。 If that is the case all you need to do is add an annotation to the ingress to remove the /demo path from the request:如果是这种情况,您需要做的就是向入口添加注释以从请求中删除 /demo 路径:

nginx.ingress.kubernetes.io/rewrite-target: /

See here for reference: https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#rewrite请参阅此处以供参考: https : //kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#rewrite

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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