Background
Rancher may have some problems that make the UI interface inaccessible, and there is no way to deploy or update the service. In this case, we use the cluster’s kubeconfig file and use k8s to host the cluster. Even if the UI interface is inaccessible, we can deploy services, restart services, and other operations.
1. Backup the kubeconfig file of the cluster (important)
Click the kubeconfig file to copy it out and save it.
Note: Be sure to back up when the Rancher UI is accessed normally, otherwise it cannot be backed up when U crashes.
2. Install command line tools
2.1, kubernetes source configuration
cat > /etc/yum.repos.d/kubernetes.repo << EOF [kubernetes] name=Kubernetes baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64 enabled=1 gpgcheck=0 repo_gpgcheck=0 gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg EOF
2.2 Install kubelet and kubectl
yum install -y kubelet-1.18.0 kubeadm-1.18.0 kubectl-1.18.0
systemctl enable kubelet
2.3 Put the cluster files that need to be operated into the specified directory
2.3.1 Create a directory
mkdir -p $HOME/.kube
2.3.2 Moving files
The /tmp/admin.conf
file here is the kubeconfig
file of the cluster backed up above
sudo cp -i /tmp/admin.conf $HOME/.kube/config
2.4 Log in to the virtual machine, start kubectl, and use it to interact with the kubernetes cluster
Use the –kubeconfig flag to specify it like so:
kubectl --kubeconfig $HOME/.kube/config get pods
3. Update service
3.1 View the namespace of Pod
in the current cluster
View a pod
name, namespace and running node
kubectl get pod -A -o yaml |grep '^ n'|grep -v nodeSelector
View the namespace through Deployment
corresponding to Pod
kubectl get deployment -A
Choose one of the above two methods.
3.2 View Deployment
under a namespace
kubectl --kubeconfig $HOME/.kube/config get deployment -n default
3.3 Save the yaml
file of this Deployment
kubectl --kubeconfig $HOME/.kube/config get deployment mysql-5-7-34-binlog -n default -o yaml >> mysql.yaml
3.4 Modify the yaml
file to update the service, for example, we change the mirror version used by the service
Modify what is shown in the diagram:
The content shown in the following figure needs to be deleted:
3.5 Execute the following command to update the service
kubectl apply -f mysql.yaml
result:
Question:
This problem occurs because the configuration file is time-stamped, and the latest yaml
file needs to be used to re-execute the command.
4. Deployment service
4.1 Prepare the yaml
files required for deploying services
4.2 Execute command deployment service
kubectl apply -f base.yaml
5. Common commands
5.1 Get all Pod
in the current cluster
kubectl --kubeconfig $HOME/.kube/config get pods
5.2 Query the namespace of Pod
View a pod
name, namespace and running node
kubectl get pod -A -o yaml |grep '^ n'|grep -v nodeSelector
5.3 Check the namespace through Deployment
corresponding to Pod
kubectl get deployment -A
5.4 Get all Services
in the current cluster
kubectl --kubeconfig $HOME/.kube/config get svc
5.5 Get all Pod
in namespace mysql-clz
kubectl --kubeconfig $HOME/.kube/config get pods -n mysql-clz
5.6 View the description information of Pod
kubectl --kubeconfig $HOME/.kube/config describe pod mysql-clz-78b8cf6-nlwn6 -n mysql-clz
5.6 View yaml
file of Pod
kubectl --kubeconfig $HOME/.kube/config get deployment mysql-clz-78b8cf6-nlwn6 -n mysql-clz -o yaml
kubectl --kubeconfig $HOME/.kube/config get mysql-clz-78b8cf6-nlwn6 -o yaml
5.8 View Deployment
in namespace mysql-clz
kubectl --kubeconfig $HOME/.kube/config get deployment -n mysql-clz
5.9 View yaml
file of Deployment
kubectl --kubeconfig $HOME/.kube/config get deployment mysql-clz -n mysql-clz -o yaml
5.10 Use yaml
file to deploy services
kubectl --kubeconfig $HOME/.kube/config apply -f base.yaml