Last active
May 28, 2024 22:09
-
-
Save mattmattox/d32b3fea4820075c08c6cc2f6d736702 to your computer and use it in GitHub Desktop.
Recovering cluster.yml and cluster.rkestate from kubeconfig
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, this works for me