1.安装
[root@node1 ~]# docker run -d --restart=unless-stopped -p 80:80 -p 443:443 --privileged rancher/rancher:latest Unable to find image 'rancher/rancher:latest' locally latest: Pulling from rancher/rancher 44d6dce21dd1: Pull complete 6a2a7789235e: Pull complete 61c35f94017a: Pull complete d718cb67a807: Pull complete f7209f494d65: Pull complete a9c3845977b8: Pull complete 9a71f6b74e42: Pull complete 2ee529d56a18: Pull complete 88117c01ef5b: Pull complete ad96aa145f81: Pull complete 4f3636a5d6de: Pull complete 4829aab3d05c: Pull complete b97bf4d88a1b: Pull complete 7139afa84690: Pull complete 39600e7290c5: Pull complete 031c7ea0c7e8: Pull complete 4618a18c8a4e: Pull complete 77fd786c9bea: Pull complete c9b5af9f31cc: Pull complete e386567b717d: Pull complete
2.查看
[root@node1 ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 088d47bff871 rancher/rancher:latest "entrypoint.sh" 12 seconds ago Up 11 seconds 0.0.0.0:80->80/tcp, :::80->80/tcp, 0.0.0.0:443->443/tcp, :::443->443/tcp loving_noyce
3.访问
通过https://ip:443访问rancher,默认用户名为admin,第一次访问时rancher会提示如何获取登录密码
[root@node1 ~]# docker logs 088d47bff871 2>&1 | grep "Bootstrap Password:" 2023/09/20 14:30:25 [INFO] Bootstrap Password: q8rz6fh89czwhr229xcrthglrslmjjlsclzhf984dc4vf8q9h5tsxm [root@node1 ~]#
输入名称:右下角创建就可以
在已有的k8s集群上执行下列命令,将其导入到rancher。通常我们使用的都是自签证书,只执行第二条命令就可以
在k8s集群的任一master节点上操作
[root@node1 ~]# curl --insecure -sfL https://192.168.31.138/v3/import/mdmq8vkzpbvczlsn5x6dhkgm8k4dgfzhhc8j7v88wxhnlfd59rwf68_c-m-tjkz2xwl.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-12fa00d created clusterrole.rbac.authorization.k8s.io/cattle-admin created deployment.apps/cattle-cluster-agent created service/cattle-cluster-agent created
查看pod
[root@node1 ~]# kubectl get pod -n cattle-system NAME READY STATUS RESTARTS AGE cattle-cluster-agent-549f98d885-phbdv 0/1 ContainerCreating 0 3m30s
再次检查可以发现k8s集群已被racher管理,且状态为active
点击集群详情,我们能看到pod、node、namespace等信息及监控数据,并且可以进行相应的管理操作。