我目前正在运行一个区域性 GKE 集群,并希望迁移到一个新的区域性集群。旧集群有一个带有公共(public) IP 的入口对象,使用谷歌托管证书来终止 HTTPS。
我的迁移计划是:
kubectl apply -f clusterConfig.yaml
. 最大的问题是,ManagedCertificates 至少需要 15 分钟。在 IP 移动以准备就绪后。这将使所有服务在此时间段内不可用。在新的 ManagedCertificates 准备好之前,有什么方法可以在新集群中使用旧的 ManagedCertificates 的 key ?
最佳答案
在我的实验室帐户中进行了一些研究和测试之后,我将解释如何在许多 LoadBalancer 中重用/重新分配当前的 ManagedCertificate。
如前所述here :
When your domain resolves to IP addresses of multiple load balancers (multiple Ingresses), you should create a single ManagedCertificate resource and attach it to all the Ingresses. If you instead create many ManagedCertificate resources and attach each of them to a separate Ingress, the Certificate Authority may not be able to verify the ownership of your domain and some of your certificates may not be provisioned
我正在区域集群(旧)上的 Kubernetes 1.17.4 中运行一个简单的应用程序,并希望使用 GKE kubernetes 1.17.5 移动到新的区域集群。
在旧集群中,我创建了一个
ManagedCertified
和一个入口。在新集群中,我将只创建一个重用先前
ManagedCertificate
的入口。 :让我们开始为 LoadBalancer 分配一个新的 IP 地址
gcloud compute addresses create newip --global
使用以下命令获取新 IP:
gcloud compute addresses describe newip --global
结果:
address: 34.107.xxx.xxx
...
对于这个例子,我使用了一个简单的
echo-server
部署:apiVersion: apps/v1
kind: Deployment
metadata:
name: echo
spec:
selector:
matchLabels:
app: echo
template:
metadata:
labels:
app: echo
spec:
containers:
- name: echo
image: mendhak/http-https-echo
ports:
- name: http
containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: echo-svc
spec:
type: NodePort
selector:
app: echo
ports:
- protocol: TCP
port: 80
targetPort: 80
您需要从键
ingress.gcp.kubernetes.io/pre-shared-cert
中获取值从旧入口 , 并配置注解 kubernetes.io/ingress.global-static-ip-name
与 新ip 名字的
您可以使用命令
kubectl get ing old-ingress -oyaml
获取上一个集群的 key 。为什么? 这是解释here :
Managed Certificates communicate with Ingress using the
kubernetes.io/pre-shared-cert
annotation.
和 here :
ingress.gcp.kubernetes.io/pre-shared-cert: Use this annotation to reference the certificates and keys
最终的 yaml 将如下所示:
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: my-new-ingress
annotations:
kubernetes.io/ingress.global-static-ip-name: newip #new ip name
ingress.gcp.kubernetes.io/pre-shared-cert: mcrt-a798051f-a50d-4b38-84b1-xxxxxxxxxxxx # from the old ingress
spec:
rules:
- http:
paths:
- backend:
serviceName: echo-svc
servicePort: 80
path: /
应用入口规范并等待负载均衡器配置...几分钟后使用
kubectl get ing
验证是否一切正常并尝试 curl ip(SSL 将不匹配,因为您正在使用 ip)curl -IL -k 34.107.xxx.xxx
HTTP/2 200
x-powered-by: Express
content-type: application/json; charset=utf-8
content-length: 647
etag: W/"287-qCxPIULxqrMga5xHN8AAKMHsUi4"
date: Wed, 20 May 2020 11:49:14 GMT
via: 1.1 google
alt-svc: clear
此时,我们有了一个使用从旧集群提供的 SSL 的入口功能应用程序。
要将所有流量从以前的集群移动到新集群,您只需使用新 ip 更改 DNS 记录。
根据您使用的 DNS 提供商,您可以使用新 ip 创建一个新的 dns 条目,并使用 dns 权重、循环等控制流量...
引用文献:
https://cloud.google.com/kubernetes-engine/docs/how-to/managed-certs
关于google-kubernetes-engine - 如何在不停机的情况下将 ManagedCertificates 从区域性 GKE 集群迁移到区域性 GKE 集群,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61794789/