从 pod 调用入口时连接被拒绝

时间:2021-07-22 20:04:05

标签: kubernetes kubernetes-ingress kubernetes-pod

我正在 Kubernetes 上运行 .NET 5 API 应用程序,并使用 Docker Desktop 在笔记本电脑上的单独 pod 中运行 Identity Server。这两个应用程序都可供使用 nginx 入口控制器的消费者使用。当我从集群外部调用浏览器中的入口时,它运行良好。此外,当我从 Visual Studio 运行 API 时,通过入口连接到 Identity Server 是成功的。

但是当我将 API 部署到 Kubernetes 时,运行 API 的 pod 无法连接到 ingress。 API 使用入口调用 Identity Server,因为它必须通过 https 发生。 SSL 由入口终止,并将流量通过 http 转发到 pod。 IdentityServer 的入口地址是 https://k8s-local.com/identityserver。从 API pod 中,DNS 是已知的;当我执行 ping 时,一切正常。当我从 pod 向这个地址执行 curl 命令时,我收到连接被拒绝错误:

curl: (7) Failed to connect to k8s-local.com port 443: Connection refused

如何使入口 DNS 对 Pod 可用?

这是我的 ingress.yml 的样子:

 apiVersion: networking.k8s.io/v1
 kind: Ingress
 metadata:
   name: my-ingress
 spec:
   tls:
   - hosts:
     - k8s-local.com
     secretName: local-tls
   rules:
   - host: k8s-local.com
     http:
       paths:
       - pathType: Prefix
         path: /identityserver/
         backend:
           service:
             name: identityserver-service
             port:
               number: 5000

       - pathType: Prefix
         path: /customer-api/
         backend:
           service:
             name: customer-api-service
             port:
               number: 5000

这是我运行 kubectl get services -n ingress-nginx 时得到的:

NAME                                 TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)                      AGE
ingress-nginx-controller             LoadBalancer   10.109.3.50     localhost     80:31964/TCP,443:32210/TCP   11d
ingress-nginx-controller-admission   ClusterIP      10.105.158.51   <none>        443/TCP                      11d

还有kubectl get ingress

NAME                     CLASS    HOSTS                          ADDRESS     PORTS     AGE
my-ingress               <none>   k8s-local.com                  localhost   80, 443   6d11h

0 个答案:

没有答案