java - Kubernetes nginx 入口未访问外部 API
问题描述
我想从 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
解决方案
• 发现和负载平衡/入口仪表板中显示的 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/
推荐阅读
- java - Spring boot:启动 ApplicationContext 时出错。要显示条件报告,请在启用“调试”的情况下重新运行您的应用程序
- javascript - 表格的列和行重新排序,拖放也可以在 React js 中编辑表格单元格
- android - 在 CoroutineScope 中下载多个图像
- c# - 验证是否调用了基类方法
- ios - 如何更改文本字段标题颜色?
- c - 为什么这个 C 代码会导致不稳定的运动?
- jenkins - 保存并应用后,Jenkins JDK安装消失
- node.js - Nodejs 在 ubuntu 上安装 node-canvas 不起作用。错误:“内部/模块/cjs/loader.js:1122”
- postgresql - 如何通过 Terraform 在 gcp 上的 postgresql 数据库实例中创建表?
- multidimensional-array - 需要帮助在 php 中创建多维数组并按键排序