首页 > 解决方案 > Kubernetes Ingress Controller GPC GKE 无法访问站点

问题描述

Kubernetes Ingress Controller 无法访问该站点

嗨,这是我第一次尝试使用 kubernetes 部署应用程序。我面临的问题是我希望能够将子域与我的 svc 链接,但是当我尝试导航到我得到的链接时

无法访问此站点

我将解释我为这些所做的步骤,可能是我出了点问题或遗漏了

  1. 我安装ingress-controller在谷歌云平台

  2. 在 GCP -> 网络服务 -> 云 DNS

    一个。我用谷歌 dns 指向 testcompany.com

    湾。我从上一步“ingress-nginx-controller”创建了一条指向公共 IP 的 A 记录

  3. 我的服务清单

    apiVersion: v1
    kind: Service
    metadata:
      namespace: staging
      name: testcompany-svc
      labels:
        app: testcompany-svc
    spec:
      type: NodePort
      ports:
        - name: test-http
          port: 80
          protocol: TCP
          targetPort: 3001
      selector:
        app: testcompany
    
  4. 我的入口清单

    apiVersion: networking.k8s.io/v1beta1
    
      - host: api.testcompany.com
        http:
          paths:
          - backend:
              serviceName: testcompany-svc
              servicePort: test-http
    

一切都是绿色的,它似乎正在工作,但是当我尝试访问该网址时,我得到了This site can’t be reached


更新 1

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  namespace: staging
  name: ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - host: front.stagingtestcompany.com
    http:
      paths:
      - backend:
          serviceName: testcompanyfront-svc
          servicePort: testcompanyfront-http

  - host: api.stagingtestcompanysrl.com
    http:
      paths:
      - backend:
          serviceName: testcompanynodeapi-svc
          servicePort: testcompanyapi-http

标签: google-cloud-platformgoogle-kubernetes-enginekubernetes-ingressnginx-ingressgke-networking

解决方案


您应该按以下顺序检查:

  1. 您的 Service、Pod、Ingress 在同一个命名空间中:kubectl get all -n staging
  2. 您的 Pod 正在侦听端口 3001:如果可以,请在本地运行它,或者使用kubectl port-forward pods/[pod-name] -n staging 3001:3001并在本地尝试使用http://localhost:3001/...
  3. 您的服务正确到达您的 Pod:使用kubectl port-forward service/testcompany-svc -n staging 3001:3001并在本地尝试http://localhost:3001/...
  4. 在您发布之前检查任何其他 Ingress 规范规则
  5. 检查您的 VPC 网络中的防火墙规则,它们应该允许来自 Google LB 的流量

推荐阅读