在 GCE/GKE 上启用 HTTPS

2024-07-03

我正在 Google Cloud 上使用 Kubernetes 运行网站。目前,一切都运行良好 - 通过 http。但我需要https。我有几项服务,其中一项是暴露给外界的,我们称之为网络。据我所知,这是唯一需要修改的服务。我尝试在 GCP 的网络部分创建静态 IP 和 TCP/SSL 负载均衡器 ssl-LB,并在我创建的 web.yaml 中使用该 LB。创建服务时遇到以下问题:

Error creating load balancer (will retry): Failed to create load 
balancer for service default/web: requested ip <IP> is 
neither static nor assigned to LB
aff3a4e1f487f11e787cc42010a84016(default/web): <nil>

然而,根据 GCP,我的 IP 是静态的。我在任何地方都找不到散列 LB,无论如何它都应该分配给 ssl-LB。我如何正确分配这个?

更多细节:

这是web.yaml的内容

apiVersion: v1
kind: Service
metadata:
name: web
labels:
  ...
spec:
  type: LoadBalancer
  loadBalancerIP: <RESERVED STATIC IP> 
ports:
- port: 443
  targetPort: 7770
selector:
  ...
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: web
spec:
  replicas: 1
  template:
    metadata:
      labels:
        ...
  spec:
    containers:
    - name: web
      image: gcr.io/<PROJECT>/<IMAGE NAME>
      ports:
      - containerPort: 7770

由于您还没有提到这一点,我只是假设您正在使用 Google Container Engine (GKE) 进行 Kubernetes 设置。

在服务资源清单中,如果您设置Type to LoadBalancer https://kubernetes.io/docs/concepts/services-networking/service/#type-loadbalancer,GKE 上的 Kubernetes 使用 GCE 自动设置网络负载均衡(L4 负载均衡器)。您必须使用自己的自定义服务器或类似的东西来终止 Pod 中的连接nginx/apache.

如果您的目标是设置一个 (HTTP/HTTPS) L7 负载均衡器(看起来确实如此),那么使用IngressKubernetes 中的资源 https://kubernetes.io/docs/concepts/services-networking/ingress/(从...开始v1.1)。 GKE 通过此设置自动设置 GCE HTTP/HTTPS L7 负载平衡。

您将能够添加 TLS 证书,该证书将由 GKE 自动在 GCE 负载均衡器上配置。

这种设置有以下优点:

  1. 指定每个 URL 路径和端口的服务(它使用URL Maps https://cloud.google.com/compute/docs/load-balancing/http/url-map从 GCE 来配置它)。
  2. 在 GCE 负载均衡器上设置和终止 SSL/TLS(它使用Target proxies https://cloud.google.com/compute/docs/load-balancing/http/target-proxies从 GCE 来配置它)。
  3. GKE 也会自动配置 GCEhealth checks https://cloud.google.com/compute/docs/load-balancing/health-checks为您服务。

您的职责是处理后端服务逻辑以处理 Pod 中的请求。

更多信息可在有关设置 HTTP 负载平衡的 GKE 页面 https://cloud.google.com/container-engine/docs/tutorials/http-balancer.

请记住,使用 GKE 时,它会自动使用可用的 GCE 负载均衡器支持上述两种用例,您无需手动设置GCE负载均衡 https://cloud.google.com/compute/docs/load-balancing/.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 GCE/GKE 上启用 HTTPS 的相关文章

随机推荐