且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何克隆Google Container集群/Kubernetes集群?

更新时间:2022-11-30 14:16:11

我正在使用CoreOS团队的bash脚本,并进行了一些小的调整,效果很好.默认情况下,它不包括kube-system命名空间,但是您可以根据需要进行调整.您也可以添加或删除要复制的资源.

I'm using a bash script from CoreOS team, with small adjustments, that works pretty good. By default it's excluding the kube-system namespace, but you can adjust this if you need. Also you can add or remove the resources you want to copy.

for ns in $(kubectl get ns --no-headers | cut -d " " -f1); do
  if { [ "$ns" != "kube-system" ]; }; then
  kubectl --namespace="${ns}" get --export -o=json svc,rc,rs,deployments,cm,secrets,ds,statefulsets,ing | \
jq '.items[] |
    select(.type!="kubernetes.io/service-account-token") |
    del(
        .spec.clusterIP,
        .metadata.uid,
        .metadata.selfLink,
        .metadata.resourceVersion,
        .metadata.creationTimestamp,
        .metadata.generation,
        .status,
        .spec.template.spec.securityContext,
        .spec.template.spec.dnsPolicy,
        .spec.template.spec.terminationGracePeriodSeconds,
        .spec.template.spec.restartPolicy
    )' >> "./my-cluster.json"
  fi
done

要在另一个群集上还原它,必须执行kubectl create -f ./my-cluster.json

To restore it on another cluster, you have to execute kubectl create -f ./my-cluster.json