1. 概览
EKS Elastic Kubernetes Service (EKS)是 AWS 提供的完全托管的 Kubernetes 服务。它是一种托管的 Kubernetes 服务,您无需维护或创建集群控制平面或底层基础设施。EKS 跨多个可用区运行集群控制平面,以确保其保持高可用性并自动替换运行状况不佳的实例。它与不同的 AWS 服务配合使用,为您的应用程序提供可扩展性和安全性。
本文将介绍利用 Kasten K10 迁移 EKS 应用的过程,在此我们使用了两个 EKS 集群,分别为 1.16 与 1.20 版本。两个集群都安装了 Kasten K10。其中一个集群安装了 WordPress,我们将使用这个集群作为源集群。我们将建立一个管道,获取 WordPress 的数据和配置备份并将它们存储在AWS S3 存储桶中。然后我们的目标集群将使用此备份并手动或按计划恢复来恢复应用程序。
在本文中,我们将在 EKS 集群中部署 WordPress 和 Kasten K10。为了演示灾难恢复和移动能力,我们将通过三个步骤:
- 配置 Kasten K10 对Amazon Web 服务 S3 存储桶的访问
- 创建策略以使用导出选项从源集群备份数据和应用程序配置
- 创建策略以在目标集群上导入和恢复这些备份
2. k10 的安装与部署
2.1 安装前的检查工作
❯ curl https://kasten-1257130361.cos.ap-chengdu.myqcloud.com/k10_primer.sh | bash
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 6025 100 6025 0 0 17878 0 --:--:-- --:--:-- --:--:-- 17878
Namespace option not provided, using default namespace
Checking for tools
--> Found kubectl
--> Found helm
Checking if the Kasten Helm repo is present
WARNING: Kubernetes configuration file is group-readable. This is insecure. Location: /Users/zhangcong/.kube/config
WARNING: Kubernetes configuration file is world-readable. This is insecure. Location: /Users/zhangcong/.kube/config
--> The Kasten Helm repo was found
Checking for required Helm version (>= v3.0.0)
WARNING: Kubernetes configuration file is group-readable. This is insecure. Location: /Users/zhangcong/.kube/config
WARNING: Kubernetes configuration file is world-readable. This is insecure. Location: /Users/zhangcong/.kube/config
WARNING: Kubernetes configuration file is group-readable. This is insecure. Location: /Users/zhangcong/.kube/config
WARNING: Kubernetes configuration file is world-readable. This is insecure. Location: /Users/zhangcong/.kube/config
--> No Tiller needed with Helm v3.6.1
K10Primer image
--> Using Image (ccr.ccs.tencentyun.com/kasten-k10/k10tools:4.0.5) to run test
Checking access to the Kubernetes context arn:aws-cn:eks:cn-north-1:535551854723:cluster/mars-k8s1
--> Able to access the default Kubernetes namespace
Running K10Primer Job in cluster with command-
./k10tools primer
serviceaccount/k10-primer created
clusterrolebinding.rbac.authorization.k8s.io/k10-primer created
job.batch/k10primer created
Waiting for pod k10primer-nt7t5 to be ready - ContainerCreating
Waiting for pod k10primer-nt7t5 to be ready - ContainerCreating
Waiting for pod k10primer-nt7t5 to be ready - ContainerCreating
Pod Ready!
Kubernetes Version Check:
Valid kubernetes version (v1.16.15-eks-e1a842) - OK
RBAC Check:
Kubernetes RBAC is enabled - OK
Aggregated Layer Check:
The Kubernetes Aggregated Layer is enabled - OK
CSI Capabilities Check:
Cluster isn't CSI capable
Validating Provisioners:
kubernetes.io/aws-ebs:
Storage Classes:
gp2
Valid Storage Class - OK
Validate Generic Volume Snapshot:
Pod Created successfully - OK
GVS Backup command executed successfully - OK
Pod deleted successfully - OK
serviceaccount "k10-primer" deleted
clusterrolebinding.rbac.authorization.k8s.io "k10-primer" deleted
job.batch "k10primer" deleted
2.2. K10 的安装
$ helm repo add kasten https://charts.kasten.io/
$ kubectl create namespace kasten-io
namespace/kasten-io created
$ helm repo update
$ helm fetch kasten/k10 --version=4.0.9
$ helm install k10 k10-4.0.9.tgz --namespace kasten-io --set global.airgapped.repository=registry.cn-beijing.aliyuncs.com/kasten-k10 \
--set secrets.awsAccessKeyId="AKIAXZMLAZCBX7QTU5CC" \
--set secrets.awsSecretAccessKey="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" \
--set externalGateway.create=true \
--set auth.tokenAuth.enabled=true \
--set metering.mode=airgap \
--set injectKanisterSidecar.enabled=true \
--set-string injectKanisterSidecar.namespaceSelector.matchLabels.k10/injectKanisterSidecar=true
2.3 登录 K10 控制台
收如下命令发现 web 入口和得到token之后,就可以通过如下链接,访问控制台
http://abe07bd0cb25b4499a551770a3cb441c-2033022465.cn-north-1.elb.amazonaws.com.cn/k10/#
# 发现 ingress
❯ kubectl get svc -n kasten-io |grep ext
gateway-ext LoadBalancer 10.100.28.165 abe07bd0cb25b4499a551770a3cb441c-2033022465.cn-north-1.elb.amazonaws.com.cn 80:30916/TCP 2m31s
# 获得 Token
❯ sa_secret=$(kubectl get serviceaccount k10-k10 -o jsonpath="{.secrets[0].name}" --namespace kasten-io) && \
kubectl get secret $sa_secret --namespace kasten-io -ojsonpath="{.data.token}{'\n'}" | base64 --decode
2.4 配置 S3 存储库
3. 应用程序备份
3.1 应用写入数据
找到 wordpress 应用入口
❯ kubectl get svc -n wordpress
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
wordpress LoadBalancer 10.100.22.136 a85210369444c43a09756f1096d36e44-1244415640.cn-north-1.elb.amazonaws.com.cn 80:32654/TCP 5h47m
wordpress-mysql ClusterIP None <none>
模拟写入新的数据
3.2 利用 K10 备份应用
3.2.1 建立备份策略
3.2.3 运行备份策略
4. 利用 K10 导出应用
创建并运行导出策略
记录数据导出的 config data
导出完成
5. 在目标导入应用
5.1 建立应用导入策略
发现策略已经导入完成
发现应用导入的时间点
5.2 还原应用
应用还原完成
5.3 查看应用迁移结果
检查应用还原后的样子
❯ kubectl get po -n marsblog
NAME READY STATUS RESTARTS AGE
wordpress-779bdf66cf-95srm 2/2 Running 0 32s
wordpress-mysql-77f9855f9c-59glx 2/2 Running 0 32s
❯ kubectl get svc -n marsblog
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
wordpress LoadBalancer 10.100.134.168 a85f7e9e335684d3b9c7e8656bbd3e40-732695488.cn-north-1.elb.amazonaws.com.cn 80:30591/TCP 3m7s
wordpress-mysql ClusterIP None <none>
6. 总结
在多种 K8S 集群之间灾备和迁移云原生的应用程序,同时又不影响现有集群内的容器与应用的正常工作有时是极具挑战性的。无论是有状态的应用灾备,或是由于平台升级、资源重组引发的迁移,虽然看上去任务并不困难,但随着应用程序之间的依赖性增加,以及操作过程中减少停机时间的要求,该操作可能会变得难以处理。利用 Kasten K10 我们可以轻松跨越云平台、K8S 分发版本进行迁移,给用户带来真正的收益。