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
2.浏览器登录
2.1 利用默认账号登录
默认用户是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机器IP
2.3 设置管理员账号
具体操作忽略,是点击右上角的头像,然后点击 账号API密钥,在里面添加账号和密码,选择管理员就可以了。
3. rancher2.7.0导入集群
#######复制在内容在master上执行
[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.验证rancher管理集群成功
5.利用rancher部署一个nginx服务
6.验证nginx 容器是否可以访问
###########用命令查看是否一致
[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 ~]#
利用集群的任何一个IP:30905,在浏览器中是可以访问的 即 192.168.186.128:30905 192.168.186.129:30905