当前位置: 首页 > 知识库问答 >
问题:

无法通过nginx-ingress-controller访问Kubernetes集群IP服务

陶智
2023-03-14

什么起作用了?

  1. 使用Helm(启用RBAC)部署入口控制器
  2. 集群IP服务部署

什么不起作用?

    null
[msekar@ebs kube-base]$ kubectl get services -n payment-gateway-7682352
NAME                            TYPE           CLUSTER-IP      EXTERNAL-IP      PORT(S)                      AGE
nginx-ingress-controller        LoadBalancer   10.35.241.255   35.188.161.171   80:31918/TCP,443:31360/TCP   6h
nginx-ingress-default-backend   ClusterIP      10.35.251.5     <none>           80/TCP                       6h
payment-gateway-dev             ClusterIP      10.35.254.167   <none>           5000/TCP                     6h
payment-gateway-qa              ClusterIP      10.35.253.94    <none>           5000/TCP                     6h

K8S入口

[msekar@ebs kube-base]$ kubectl get ing -n payment-gateway-7682352
NAME                HOSTS     ADDRESS          PORTS     AGE
pgw-nginx-ingress   *         104.198.78.169   80        6h

[msekar@ebs kube-base]$ kubectl describe ing pgw-nginx-ingress -n payment-gateway-7682352
Name:             pgw-nginx-ingress
Namespace:        payment-gateway-7682352
Address:          104.198.78.169
Default backend:  default-http-backend:80 (10.32.1.4:8080)
Rules:
  Host  Path  Backends
  ----  ----  --------
  *     
        /dev/   payment-gateway-dev:5000 (<none>)
        /qa/    payment-gateway-qa:5000 (<none>)
Annotations:
  kubectl.kubernetes.io/last-applied-configuration:  {"apiVersion":"extensions/v1beta1","kind":"Ingress","metadata":{"annotations":{"kubernetes.io/ingress.class":"nginx","nginx.ingress.kubernetes.io/ssl-redirect":"false"},"name":"pgw-nginx-ingress","namespace":"payment-gateway-7682352"},"spec":{"rules":[{"http":{"paths":[{"backend":{"serviceName":"payment-gateway-dev","servicePort":5000},"path":"/dev/"},{"backend":{"serviceName":"payment-gateway-qa","servicePort":5000},"path":"/qa/"}]}}]}}

  kubernetes.io/ingress.class:               nginx
  nginx.ingress.kubernetes.io/ssl-redirect:  false
Events:                                      <none>

注释中最后应用的配置(入口描述输出)显示入口资源清单。但是,我贴在下面作为参考

---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: pgw-nginx-ingress
  namespace: payment-gateway-7682352
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
spec:
  rules:
  - http:
      paths:
      - backend:
          serviceName: payment-gateway-dev
          servicePort: 5000
        path: /dev/
      - backend:
          serviceName: payment-gateway-qa
          servicePort: 5000
        path: /qa/

附加信息

    null

任何关于我可能做错了什么的建议或见解将非常感谢。

共有1个答案

锺离霖
2023-03-14

这个问题问得好,+1。

你的安排在我看来是对的。在您的解释中,我可以发现您的服务需要http://<>/PGW/v1/swagger-ui.html作为上下文。但是,在您的设置中,如果您的路由是/qa/,则提交给服务的路径将是http://<>/qa/PGW/v1/swagger-ui.html

要删除前缀,您需要做的是向入口添加rewrite规则:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: pgw-nginx-ingress
  namespace: payment-gateway-7682352
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
    nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
  rules:
  - http:
      paths:
      - backend:
          serviceName: payment-gateway-dev
          servicePort: 5000
        path: /dev/(.+)
      - backend:
          serviceName: payment-gateway-qa
          servicePort: 5000
        path: /qa/(.+)
    null
 类似资料:
  • 我使用此处的说明在 VirtualBox 上创建了一个 3 节点 kubernetes 集群(1 个主 2 个工作线程)。我正在使用法兰绒作为覆盖网络。 我在安装过程中在主服务器上设置了< code > sysctl-w net . bridge . bridge-nf-call-iptables = 1 和< code > sysctl-w net . bridge . bridge-nf-ca

  • 这很奇怪。我是不是在设置过程中漏掉了什么 我似乎无法从集群上的任何地方到达10.100.0.1地址。但是,其他一些clusterIP地址可以从节点访问 但是,如果我用另一个地址检查相同的路径,项将被重调

  • 我使用几个独立服务运行Kubernetes单节点dev集群--Nginx proxy(端口80)和elasticsearch(端口9200)。有没有办法用ingress公开这些服务,用一个LoadBalancer IP拥有入口点?(X.X.X.X:80和X.X.X:9200) 我读过关于入口限制,它只能用80和443端口访问。但是,也许,存在一些变通方法? 请Thx提供任何建议 但如果以后您想公开

  • 来自服务器的错误(InternalError):创建“stdin”时出错:出现内部错误:调用webhook“validate.nginx.ingress.kubernetes.io”失败:Post https://Ingress-nginx-controller-accemsion.Ingress-nginx.controller.svc:443/extensions/v1beta1/Ingres

  • Kong Ingress Controller for Kubernetes Use Kong for Kubernetes Ingress.Configure plugins, health checking,load balancing and more in Kongfor Kubernetes Services, all usingCustom Resource Definitions(C