【问题标题】:Kubernetes nginx ingress not accessing external APIKubernetes nginx 入口未访问外部 API
【发布时间】:2021-10-30 04:16:16
【问题描述】:

我想在 kubernetes 中从我的服务(site-api)访问外部 API,这个外部 API 只能通过 IP 白名单访问,所以我给出了我的入口的 IP(外部 IP),这个 ip 位于kubernetes 仪表板(发现和负载平衡/入口),但我仍然被拒绝访问,我必须提供的 ip 是否正确?入口 yaml 中缺少一些设置?

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: site-name
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$1
    nginx.ingress.kubernetes.io/backend-protocol: HTTPS
    nginx.ingress.kubernetes.io/proxy-body-size: "15m"
spec:
  tls:
  - hosts:
      - site-name
    secretName: aks-ingress-tls
  rules:
  - host: site-name
    http:
      paths:
      - path: /?(.*) 
        backend:
          serviceName: site-web
          servicePort: 443
      - path: /message/?(.*) 
        backend:
          serviceName: site-message
          servicePort: 3001
      - path: /api/?(.*) 
        backend:
          serviceName: site-api
          servicePort: 8443   

【问题讨论】:

  • 你好@Leonardo Calcagno,如果我的回答对你有帮助,你可以投票并接受它作为答案(点击答案旁边的复选标记,将其从灰色切换为填充。)。这对其他社区成员可能是有益的。谢谢

标签: java azure kubernetes devops


【解决方案1】:

• 发现和负载平衡/入口仪表板中显示的 IP 不是要列入白名单的 IP 地址。相反,尝试访问外部 IP 的服务对象 (site-api) 将暴露部署以及需要列入白名单的外部 IP。

• 因此,首先创建一个公开站点 API 部署的服务对象,并显示有关为公开部署而创建的该服务对象的信息。

• 一次,我们获取服务对象的简明信息,获取该服务对象的详细信息,这将显示站点 API 尝试访问的外部 IP 的详细信息。

• 因此,外部 IP 地址将被此服务对象公开,需要将其列入白名单。此外,记下通过端口和节点端口访问站点 API 的端点 IP 地址及其端口。然后就可以使用显示信息中的外部IP地址和端口访问site-api服务了。

• 请找到以下 Kubernetes 命令来执行上述步骤:-

kubectl expose deployment<site-api>--type=LoadBalancer --name=my-service  Service object creation for exposing the deployment

kubectl get services my-service  Display information about the service

kubectl describe services my-service  Display detailed information about the service

kubectl get pods --output=wide  Get endpoint information

curl http://<external-ip>:<port>  Access the site-api through external IP

更多信息请参考以下链接:-

https://kubernetes.io/docs/tutorials/stateless-application/expose-external-ip-address/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-08
    • 1970-01-01
    • 2021-05-18
    • 2021-07-05
    • 2018-12-28
    相关资源
    最近更新 更多