[英]How to use Nginx ingress service for internal and external in a single GKE cluster and namespace
我在命名空间(Google Kubernetes 引擎)中使用 nginx 入口和外部 IP。 现在,我想使用 nginx 入口内部服务从 VPC 网络内的集群外部调用该服务。 请建议我如何实现这一目标。
假设您使用ingress-nginx ,那么您可以按照他们的安装指南页面上的步骤进行操作
在执行以下命令之前,您需要将kubectl
上下文指向您的集群(按照本指南进行设置):
kubectl create clusterrolebinding cluster-admin-binding \ --clusterrole cluster-admin \ --user $(gcloud config get-value account)
使用以下步骤部署ingress-nginx
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-0.32.0/deploy/static/provider/cloud/deploy.yaml
使用带有注释cloud.google.com/load-balancer-type: "Internal"
的LoadBalancer
服务。 这将在您的 VPC 中生成一个内部 ILB
apiVersion: v1 kind: Service metadata: name: ingress-nginx-ilb-service namespace: ingress-nginx annotations: cloud.google.com/load-balancer-type: "Internal" labels: app.kubernetes.io/name: ingress-nginx app.kubernetes.io/instance: ingress-nginx app.kubernetes.io/component: controller spec: type: LoadBalancer selector: app.kubernetes.io/name: ingress-nginx app.kubernetes.io/instance: ingress-nginx app.kubernetes.io/component: controller ports: - name: http port: 80 protocol: TCP targetPort: http - name: https port: 443 protocol: TCP targetPort: https
您的 ILB 内部 IP 将在应用此服务清单后的几分钟内可用
正如 Christopher 所提到的,您只需将注释添加到服务中,它就会自动创建一个内部负载均衡器,而不是一个外部负载均衡器。 该服务将如下所示:
apiVersion: v1
kind: Service
metadata:
name: nginx-ingress
namespace: nginx-ingress
annotations:
cloud.google.com/load-balancer-type: "Internal"
spec:
externalTrafficPolicy: Local
type: LoadBalancer
ports:
- port: 80
targetPort: 80
protocol: TCP
name: http
- port: 443
targetPort: 443
protocol: TCP
name: https
selector:
app: nginx-ingress
保持对象的 rest 不变。 如果你想两者兼得; 外部和内部的,只需创建内部的(如下)。 它们都可以指向同一个入口 controller。
不幸的是,两位海报都误解了这个问题。 我正在寻找与 OP 做同样的事情。 Ingress-nginx 能够在同一实例中同时拥有内部和外部负载均衡器,但除了说它可用之外,它没有在任何地方记录。 所提供的答案都没有接近回答这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.