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

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

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

<h3>Note:</h3>

<p>I try to modify the cluster's configs by calling:</p>

<pre><code>kubectl apply -f some-resource.yaml
</code></pre>

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

<pre><code>kubectl edit service/resource
</code></pre>

<p>Or setting properties from command line <code>kubectl</code> calls.</p>

<p>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.</p>

<pre><code>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
    )' &gt;&gt; "./my-cluster.json"
  fi
done
</code></pre>

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