Foreword:
rancher is a special open source kubernetes management tool, especially in that it is a simple kubernetes cluster named k3s, and the cluster is in the kubernetes cluster.
Rancher can also be deployed on a bare machine with only a docker environment, and then use this machine to bring other kubernetes clusters into rancher management (referred to as management), or quickly install a brand new one hosted by rancher on other nodes through this machine. Managed kubernetes cluster.
OK, this article will describe how to install rancher-2.6.4 through docker in the existing kubernetes-1.23.15 cluster on the centos7 server and debug it to an available state.
one,
Environment introduction
The general situation of the existing kubernetes cluster:
[root@k8s-master ~]# kubectl get no -owide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
k8s-master Ready control-plane,master 110d v1.23.15 192.168.123.11 <none> CentOS Linux 7 (Core) 5.4.228-1.el7.elrepo.x86_64 docker://20.10.7
k8s-node1 Ready <none> 110d v1.23.15 192.168.123.12 <none> CentOS Linux 7 (Core) 5.4.228-1.el7.elrepo.x86_64 docker://20.10.7
k8s-node2 Ready <none> 110d v1.23.15 192.168.123.13 <none> CentOS Linux 7 (Core) 5.4.228-1.el7.elrepo.x86_64 docker://20.10.7
[root@k8s-master ~]# kubectl get po -A
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system coredns-6d8c4cb4d-8fqvx 1/1 Running 1 (110d ago) 110d
kube-system coredns-6d8c4cb4d-wwmkf 1/1 Running 1 (110d ago) 110d
kube-system etcd-k8s-master 1/1 Running 2 (110d ago) 110d
kube-system kube-apiserver-k8s-master 1/1 Running 2 (110d ago) 110d
kube-system kube-controller-manager-k8s-master 1/1 Running 2 (110d ago) 110d
kube-system kube-flannel-ds-jhnhc 1/1 Running 1 (110d ago) 110d
kube-system kube-flannel-ds-v59k2 1/1 Running 1 (110d ago) 110d
kube-system kube-flannel-ds-vlrtj 1/1 Running 1 (110d ago) 110d
kube-system kube-proxy-2xlzz 1/1 Running 2 (110d ago) 110d
kube-system kube-proxy-pndtl 1/1 Running 2 (110d ago) 110d
kube-system kube-proxy-z4zdp 1/1 Running 2 (110d ago) 110d
kube-system kube-scheduler-k8s-master 1/1 Running 2 (110d ago) 110d
OK, the existing kubernetes cluster version is 1.23.15, and the IP address of the server is on it. The cluster is relatively clean, and there are not many pods installed.
two,
Install rancher using docker
Mirror download:
Link: https://pan.baidu.com/s/1DuP4ZGDES9EhTGGPLprZmQ?pwd=ranc
Extraction code: ranc
Note: The images of rancher are relatively large, mainly two images, one is the server image, and the other is the client image, both of which are about 1.5G in size. If you use the first command below, it is best to import it first The image is executing the docker start command
[root@k8s-master ~]# ls -alh |grep rancher
-rw-r--r-- 1 root root 1.4G Apr 23 05:59 rancher-2.6.4.tar.gz
-rw-r--r-- 1 root root 1.4G Apr 23 05:59 rancher-agent-2.6.4.tar.gz
The docker startup command is (execute this command on the master node, which is the 192.168.123.11 node):
docker run --privileged -d --name rancher --restart=unless-stopped -p 80:80 -p 443:443 -v /opt/rancher:/var/lib/rancher rancher/rancher:v2.6.4
This command can use the image of Alibaba Cloud. If it is the image of Alibaba Cloud, the command is:
docker run --privileged -d --name rancher \
--restart=unless-stopped -p 80:80 -p 443:443 -v /opt/rancher:/var/lib/rancher \
-e CATTLE_AGENT_IMAGE="registry.cn-hangzhou.aliyuncs.com/rancher/rancher-agent:v2.6.4" \
registry.cn-hangzhou.aliyuncs.com/rancher/rancher:v2.6.4
Wait for about 3 minutes, and then you can enter the rancher web interface:
three,
rancher settings
1. Obtain the password of the web interface
[root@k8s-master ~]# docker ps -a |grep rancher
c922a62d3c15 rancher/rancher:v2.6.4 "entrypoint.sh" 11 minutes ago Up 11 minutes 0.0.0.0:80->80/tcp, :::80->80/tcp, 0.0.0.0:443->443/tcp, :::443->443/tcp rancher
[root@k8s-master ~]# docker logs c922a 2>&1 | grep "Bootstrap Password:"
2023/04/22 22:09:56 [INFO] Bootstrap Password: rhs4j82d9bmqqqlqwfkprls5pmx6wmdqnwvjqgcmvkfklsdz9v5bwx
2. Log in to rancher and modify the random password obtained above:
Only hit the second √
3. The initial interface of rancher
It can be seen that there is now a k3s cluster named local, the version is quite high, it is 1.22.7, and the status is active, but these are not important. The important thing is that we need to import the existing kubernetes-1.23.15
4. Import an existing cluster
Note: all three nodes of rancher-agent-2.6.4.tar.gz should be imported
The output of this command is roughly as follows:
[root@k8s-master ~]# curl --insecure -sfL https://192.168.123.11/v3/import/ll2gkc5v4mwlxllw8dgld7zfkp2sdclxspmg8hvrkkxksf2zwzr8xg_c-m-vrmw68ql.yaml | kubectl apply -f -
clusterrole.rbac.authorization.k8s.io/proxy-clusterrole-kubeapiserver unchanged
clusterrolebinding.rbac.authorization.k8s.io/proxy-role-binding-kubernetes-master unchanged
namespace/cattle-system unchanged
serviceaccount/cattle unchanged
clusterrolebinding.rbac.authorization.k8s.io/cattle-admin-binding unchanged
secret/cattle-credentials-c4a8a0f created
clusterrole.rbac.authorization.k8s.io/cattle-admin unchanged
Warning: spec.template.spec.affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution.nodeSelectorTerms[0].matchExpressions[0].key: beta.kubernetes.io/os is deprecated since v1.14; use "kubernetes.io/os" instead
deployment.apps/cattle-cluster-agent created
service/cattle-cluster-agent unchanged
You can see that there are indeed three nodes:
OK, we have initially imported the existing cluster, but many functions are still unusable, because some plug-ins have not been deployed yet:
[root@k8s-master ~]# kubectl get po -A -owide
NAMESPACE NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
cattle-fleet-system fleet-agent-6b98dfb776-nqw5j 0/1 ImagePullBackOff 0 17m 10.244.2.4 k8s-node2 <none> <none>
cattle-system cattle-cluster-agent-8f9c97c59-bq57h 1/1 Running 0 5m3s 10.244.2.5 k8s-node2 <none> <none>
cattle-system cattle-cluster-agent-8f9c97c59-hxwfq 1/1 Running 0 17m 10.244.1.4 k8s-node1 <none> <none>
kube-system coredns-6d8c4cb4d-8fqvx 1/1 Running 1 (110d ago) 110d 10.244.0.4 k8s-master <none> <none>
In the end it should be four running:
[root@k8s-master ~]# kubectl get po -A -owide
NAMESPACE NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
cattle-fleet-system fleet-agent-55b948fdd7-lvrkx 1/1 Running 0 19m 10.244.1.7 k8s-node1 <none> <none>
cattle-system cattle-cluster-agent-8f9c97c59-bq57h 1/1 Running 0 26m 10.244.2.5 k8s-node2 <none> <none>
cattle-system cattle-cluster-agent-8f9c97c59-hxwfq 1/1 Running 0 38m 10.244.1.4 k8s-node1 <none> <none>
cattle-system dashboard-shell-xkpx6 2/2 Running 0 7s 10.244.2.9 k8s-node2 <none> <none>
About rancher's UI interface Sinicization:
The UI interface of rancher-2.6 is language selection, which can be easily switched to Chinese:
Four,
Create a new cluster based on rancher