简体   繁体   English

Kubernetes NGINX-ingress 返回 404

[英]Kubernetes NGINX-ingress returns 404

I'm a k8s newbie and I am trying to expose a port from the cluster into the local network.我是 k8s 新手,我正在尝试将一个端口从集群公开到本地网络。 I've tried to do it with metallb config layer2 + load balancer controller and this runs ok.我试过用 metallb config layer2 + 负载平衡器控制器来做,这运行正常。

I have set up a 3-node environment with kubespray.我已经使用 kubespray 设置了一个 3 节点环境。 ((192.168.0.1[5,6,7])) ((192.168.0.1[5,6,7]))

However, I'm trying to expose an api with NodePort and NGINX-Ingress.但是,我正在尝试使用 NodePort 和 NGINX-Ingress 公开一个 api。 The nodeport api service is running ok (i can make successfull requests via NODE_IP:NODE_nodeport). nodeport api 服务运行正常(我可以通过 NODE_IP:NODE_nodeport 发出成功的请求)。 But if I try this ingress configuration it justs keeps telling me "connection refused":但是,如果我尝试此入口配置,它只会不断告诉我“连接被拒绝”:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-api
  annotations:
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
spec:
  rules:
  - host: "k8s.customhostname.com" # solves to 192.168.0.17 which has a running pod with the api.
    http:
      paths:
      - path: /test
        pathType: Prefix
        backend:
          service:
            name: svc-api
            port:
              number: 8080

Then i check the services:然后我检查服务:

Name:              svc-smouapimapes
Namespace:         smouapi
Labels:            app=apimapes
Annotations:       <none>
Selector:          app=apimapes
Type:              ClusterIP
IP:                10.233.26.225
Port:              springboot  8080/TCP
TargetPort:        8080/TCP
Endpoints:         10.233.90.4:8080,10.233.92.8:8080
Session Affinity:  None
Events:            <none>

And then check the ingress:然后检查入口:

Name:             ingress-smouapimapes
Namespace:        smouapi
Address:          192.168.0.17
Default backend:  default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
Rules:
  Host                     Path  Backends
  ----                     ----  --------
  k8s.nexusgeografics.com
                           /test   svc-smouapimapes:8080   10.233.90.4:8080,10.233.92.8:8080)
Annotations:               nginx.ingress.kubernetes.io/ssl-redirect: false
Events:                    <none>

Whenever i call :每当我打电话:

curl -I http://k8s.nexusgeografics.com/test
# CONNECTION REFUSED

What am I doing wrong?我究竟做错了什么? Thanks谢谢

Try adding the following in the Nginx config ingress-smouapimapes.尝试在 Nginx 配置 ingress-smouapimapes 中添加以下内容。 Add annotation :添加注释:

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

And instead of this path: /test add path: /test(/|$)(.*)而不是这个path: /test添加path: /test(/|$)(.*)

Enin,您应该将域k8s.nexusgeografics.com配置为解析为提供nginx-ingress 服务的ip,这样您就可以通过nginx-ingress 访问您的服务。

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

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