Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to restore rkestate state files

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article shows you how to restore the rkestate status file, the content is concise and easy to understand, can definitely brighten your eyes, through the detailed introduction of this article, I hope you can get something.

The Kubernetes cluster status consists of the cluster profile cluster.yml and the component certificate in the Kubernetes cluster. Generated by RKE, but the cluster state is saved differently depending on the version of RKE.

Prior to v0.2.0, RKE saved the Kubernetes cluster state as secret. When you update the status, RKE extracts the secret, updates / changes the state, and saves the new secret.

Starting with v0.2.0, RKE creates the cluster.rkestate file in the same directory as the cluster configuration file cluster.yml. The .rkconfigurations file contains the current status of the cluster, including the RKE configuration and certificates. You need to keep this file to update the cluster or do anything to the cluster through RKE.

Status file conversion

If you created a Kubernetes cluster with rke v0.2.0 or earlier, it is recommended that you upgrade the rke version to the latest version.

Prior to rke v0.2.0, component certificates were saved through pki.bundle.tar.gz. Rke v0.2.0 and later use .rkstores to save component certificates.

After rke has been upgraded to the latest version, a transition operation is required. With the original rke configuration file, rerunning rke up will automatically generate the .rkstores file.

Retrieve .rkhorse

If .rkhorse is inadvertently lost or corrupted, it can be restored through the configuration mapping file in the cluster.

Retrieved through the kubectl configuration file

If .rkhorse is missing, but kubecfg is not lost, kubectl can also connect to the cluster normally. You can run the following command to retrieve .rkhorse:

Note: when rke creates a cluster, it automatically creates .rkstores and kubecfg files. The naming rules for .rkstores and kubecfg files are related to the name of the rke configuration file. For example, if the rke configuration file is named cluster.yml, then the generated .rkhorse is cluster.rkestate and the generated kubecfg is kube_config_cluster.yml.

It can be summarized as follows:

1. Kubecfg naming rules: kube_config_.yml

2. Rkestate naming rules: .rkestate

# define the name of the rke configuration file. If it still exists, enter it according to the existing file name; if it does not exist, enter it casually, for example, the name is rancher-cluster, and the file suffix yaml/yml is not required.

Rke_config_name=rancher-cluster

Kubecfg=kube_config_cluster.yml

Kubectl-- kubeconfig=$ {kubecfg}-n kube-system\

Get configmap full-cluster-state-o json |\

Jq-r. Data.\ "full-cluster-state\" |\

Jq-r. > ${rke_config_name} .rkhorse

Retrieve it through the master node

If both the local .rkstores and kubecfg files are lost, you need to log in to the master node for recovery and run the following script on the master node:

If [[- f / etc/kubernetes/ssl/kubecfg-kube-node.yaml]]; then

Kubecfg=/etc/kubernetes/ssl/kubecfg-kube-node.yaml

Elif [[- f / etc/kubernetes/ssl/kubecfg-kube-node.yml]]; then

Kubecfg=/etc/kubernetes/ssl/kubecfg-kube-node.yml

Else

Echo 'kubecfg profile does not exist'

Exit 1

Fi

# obtain Rancher Agent image

RANCHER_IMAGE=$ (docker images-- filter=label=io.cattle.agent=true | grep 'v2.' |\

Grep-v-E'rc | alpha |'| head-n 1 | awk'{print $3}')

# define the name of the rke configuration file. If it still exists, enter it according to the existing file name; if it does not exist, enter it casually, for example, the name is rancher-cluster, and the file suffix yaml/yml is not required.

Rke_config_name=rancher-cluster

Docker run-rm-net=host\

-v $(docker inspect kubelet-- format\

'{{range .Mounts}} {{if eq .destination "/ etc/kubernetes"}} {{.Source}} {{end}} {{end}}) / ssl:/etc/kubernetes/ssl:ro\

-entrypoint bash ${RANCHER_IMAGE}\

-c 'kubectl-- kubeconfig=$ {kubecfg}\

-n kube-system get configmap full-cluster-state-o json |\

Jq-r. Data.\ "full-cluster-state\" |\

Jq-r.'> ${rke_config_name} .rkhorse

The above is how to restore rkestate status files. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report