How to clone Google Container Cluster / Kubernetes cluster?

守給你的承諾、 提交于 2019-12-21 20:29:54

问题


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

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?

Note:

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

Or setting properties from command line kubectl calls.


回答1:


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

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



来源:https://stackoverflow.com/questions/41609633/how-to-clone-google-container-cluster-kubernetes-cluster

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!