-
-
Save mattmattox/d32b3fea4820075c08c6cc2f6d736702 to your computer and use it in GitHub Desktop.
#!/bin/bash | |
echo "Building cluster_recovery.yml..." | |
echo "Working on Nodes..." | |
echo 'nodes:' > cluster_recovery.yml | |
kubectl --kubeconfig kube_config_cluster.yml -n kube-system get configmap full-cluster-state -o json | jq -r .data.\"full-cluster-state\" | jq -r .desiredState.rkeConfig.nodes | yq r - | sed 's/^/ /' | \ | |
sed -e 's/internalAddress/internal_address/g' | \ | |
sed -e 's/hostnameOverride/hostname_override/g' | \ | |
sed -e 's/sshKeyPath/ssh_key_path/g' >> cluster_recovery.yml | |
echo "" >> cluster_recovery.yml | |
echo "Working on services..." | |
echo 'services:' >> cluster_recovery.yml | |
kubectl --kubeconfig kube_config_cluster.yml -n kube-system get configmap full-cluster-state -o json | jq -r .data.\"full-cluster-state\" | jq -r .desiredState.rkeConfig.services | yq r - | sed 's/^/ /' >> cluster_recovery.yml | |
echo "" >> cluster_recovery.yml | |
echo "Working on network..." | |
echo 'network:' >> cluster_recovery.yml | |
kubectl --kubeconfig kube_config_cluster.yml -n kube-system get configmap full-cluster-state -o json | jq -r .data.\"full-cluster-state\" | jq -r .desiredState.rkeConfig.network | yq r - | sed 's/^/ /' >> cluster_recovery.yml | |
echo "" >> cluster_recovery.yml | |
echo "Working on authentication..." | |
echo 'authentication:' >> cluster_recovery.yml | |
kubectl --kubeconfig kube_config_cluster.yml -n kube-system get configmap full-cluster-state -o json | jq -r .data.\"full-cluster-state\" | jq -r .desiredState.rkeConfig.authentication | yq r - | sed 's/^/ /' >> cluster_recovery.yml | |
echo "" >> cluster_recovery.yml | |
echo "Working on systemImages..." | |
echo 'system_images:' >> cluster_recovery.yml | |
kubectl --kubeconfig kube_config_cluster.yml -n kube-system get configmap full-cluster-state -o json | jq -r .data.\"full-cluster-state\" | jq -r .desiredState.rkeConfig.systemImages | yq r - | sed 's/^/ /' >> cluster_recovery.yml | |
echo "" >> cluster_recovery.yml | |
echo "Building cluster_recovery.rkestate..." | |
kubectl --kubeconfig kube_config_cluster.yml -n kube-system get configmap full-cluster-state -o json | jq -r .data.\"full-cluster-state\" | jq -r . > cluster_recovery.rkestate | |
echo "Running rke up..." | |
rke up --config cluster_recovery.yml |
We are testing a new tool to fetch the kubconfig and rke state file from the cluster.
PR
git clone https://github.com/rancher/rke && cd rke && git fetch origin pull/2277/head:util && git checkout util && CROSS=true make build
NOTE: This is not for Production yet.
Hello, this is very good... but somehow it seems to retrieve only the informations about the master node of my single-master, three workers cluster.
Anyone noticed?
I must add that the original rke cluster installation (the one of which I lost cluster.yml file) had been performed via non-root user and non-standard SSH private key.
However, I was able to perform successfully an "rke etcd snapshot-save" using the output of the script as cluster.yml (amended for SSH connection parameters).
Thanks, this works for me
I needed to change
yq r -
into
yq -P
yq --version
yq (https://github.com/mikefarah/yq/) version 4.21.1
Thanks, this change worked for me.
I encounter the same issue. But in the first step there is no full-cluster-state in config map. crying...
I do not have full-cluster-state configmap in a working cluster, no idea also ? @litao3rd did you find another option?
@jrab66 You can run the command rke util get-state-file
now to pull the state file from a working cluster.
I do not have full-cluster-state configmap in a working cluster, no idea also ? @litao3rd did you find another option?
nop...I rebuild the cluster
This is a life saver! A note for all who will use this in the future: be aware that when running
rke up --config <file>.yml
rke will consider this as a new cluster unless you have akube_config_<file>.yml
in the local directory. In case you already ran this once, it might make sense to check this answer