前提:安裝rancher之前需要給系統(tǒng)安裝docker
centos系統(tǒng)請(qǐng)參考博客
ubuntu系統(tǒng)請(qǐng)參考博客
1. 安裝rancher2.7.0
docker run -d --name rancher --restart=unless-stopped --privileged -p 80:80 -p 443:443 -v /var/lib/rancher:/var/lib/rancher/ -v /var/log/rancher/auditlog:/var/log/auditlog rancher/rancher:v2.7.0
#安裝rancher最新版
docker run -d --name rancher --restart=unless-stopped --privileged -p 80:80 -p 443:443 -v /var/lib/rancher:/var/lib/rancher/ -v /var/log/rancher/auditlog:/var/log/auditlog rancher/rancher
2.瀏覽器登錄
2.1 利用默認(rèn)賬號(hào)登錄
默認(rèn)用戶是admin
[root@k8s-master ~]# docker ps -a|grep rancher #查看容器id
8df8025ff9a9 rancher/rancher:v2.7.0 "entrypoint.sh" About an hour ago Up 33 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 8df8025ff9a9 2>&1 | grep "Bootstrap Password:" #查看密碼
2023/07/14 10:18:06 [INFO] Bootstrap Password: ssv7dp6gm29k69rbwqz9cmgrm6t7b8pthk2tmwdcwxrv86jktxhm9c
[root@k8s-master ~]#
2.2 登錄地址是 rancher機(jī)器IP
瀏覽器打開(kāi):https://IP:443 回車后就出現(xiàn)了如下圖利用剛才查到的密碼登錄
登錄后直接修改密碼,點(diǎn)擊繼續(xù)。上圖就是進(jìn)入后的默認(rèn)頁(yè)面
不同版本調(diào)整中文的頁(yè)面不一樣,具體請(qǐng)根據(jù)自己的版本可以百度或者去官網(wǎng)查看。
2.3 設(shè)置管理員賬號(hào)
利用新賬號(hào),也就是管理員賬號(hào)登錄。
第一種方法 rancher導(dǎo)入已經(jīng)安裝好的K8S集群
3. rancher2.7.0導(dǎo)入集群
#######復(fù)制在內(nèi)容在master上執(zhí)行
[root@k8s-master ~]# curl --insecure -sfL https://192.168.186.128/v3/import/wg9vkxjm94skp872zpm9nxmqz6rz8jjrn88prcvwvvdjkrwk6bhln9_c-m-5jcxgvql.yaml | kubectl apply -f -
clusterrole.rbac.authorization.k8s.io/proxy-clusterrole-kubeapiserver created
clusterrolebinding.rbac.authorization.k8s.io/proxy-role-binding-kubernetes-master created
namespace/cattle-system created
serviceaccount/cattle created
clusterrolebinding.rbac.authorization.k8s.io/cattle-admin-binding created
secret/cattle-credentials-c3272ae created
clusterrole.rbac.authorization.k8s.io/cattle-admin created
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 created
[root@k8s-master ~]#
4.驗(yàn)證rancher管理集群成功
5.利用rancher部署一個(gè)nginx服務(wù)
6.驗(yàn)證nginx 容器是否可以訪問(wèn)
###########用命令查看是否一致
[root@k8s-master ~]# kubectl get pods,svc
NAME READY STATUS RESTARTS AGE
pod/nginx-5f7bd866f7-gk6vc 1/1 Running 0 3m51s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 39d
service/nginx ClusterIP 10.99.120.118 <none> 80/TCP 3m51s
service/nginx-nodeport NodePort 10.104.209.103 <none> 80:30905/TCP 3m51s
[root@k8s-master ~]#
[root@k8s-master ~]# kubectl get nodes -o wide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
k8s-master Ready control-plane,master 39d v1.23.8 192.168.186.128 <none> CentOS Linux 7 (Core) 3.10.0-1160.el7.x86_64 docker://24.0.2
k8s-node1 Ready <none> 39d v1.23.8 192.168.186.129 <none> CentOS Linux 7 (Core) 3.10.0-1160.el7.x86_64 docker://24.0.2
[root@k8s-master ~]#
利用集群的任何一個(gè)IP:30905,在瀏覽器中是可以訪問(wèn)的 即 192.168.186.128:30905 192.168.186.129:30905
第二種方法 rancher安裝K8S集群
復(fù)制上圖中的命令在你要決定安裝的節(jié)點(diǎn)上運(yùn)行,我這里選擇的是3個(gè)服務(wù)都安裝,當(dāng)作是master節(jié)點(diǎn)文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-677761.html
文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-677761.html
到這里就安裝成功了,歡迎大家有問(wèn)題留言。
到了這里,關(guān)于安裝部署rancher2.7.0,然后導(dǎo)入K8S集群,管理集群的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!