本文介绍了如何克隆Google Container集群/Kubernetes集群?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与标题相同.我要克隆(创建现有集群的副本).

As in title. I want to clone (create a copy of existing cluster).

如果无法复制/克隆Google Container Engine集群,那么如何克隆Kubernetes集群?

If it's not possible to copy/clone Google Container Engine cluster, then how to clone Kubernetes cluster?

如果不可能,是否有办法转储整个群集配置?

If that's not possible, is there a way to dump the whole cluster config?

我尝试通过调用以下命令来修改集群的配置:

I try to modify the cluster's configs by calling:

kubectl apply -f some-resource.yaml

但是没有什么可以阻止我/其他员工通过运行以下命令来修改集群:

But nothing stops me/other employee modifying the cluster by running:

kubectl edit service/resource

或通过命令行kubectl调用设置属性.

Or setting properties from command line kubectl calls.

推荐答案

我正在使用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

这篇关于如何克隆Google Container集群/Kubernetes集群?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 22:55