我在命名空间(Google Kubernetes Engine)中使用带有外部IP的nginx入口。现在,我想使用Nginx入口内部服务从VPC网络内的群集外部调用该服务。
请建议我如何实现这一目标。

请您参考如下方法:

假设您使用ingress-nginx,则可以按照其Installation Guide page上的步骤进行操作

您需要先将kubectl上下文指向您的集群(通过遵循此guide进行设置),然后才能执行以下命令:

  • 使用以下命令将您的用户初始化为cluster-admin
    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 
    
  • 使用带批注LoadBalancercloud.google.com/load-balancer-type: "Internal"服务。这将在您的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 
    

  • 应用此服务 list 后,您的ILB内部IP将在几分钟后可用


    评论关闭
    IT序号网

    微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!