Rancher加入k8s集群
Rancher+k8s
1.准备工作
ip | 主机名 | 配置 |
---|---|---|
172.16.215.130 | K8s-Master | 2U2G |
172.16.215.132 | K8s-Node01 | 1U2G |
172.16.215.133 | rancher | 2U2G |
2.安装Rancher
-
我们采用V2版本安装:
v1版本的dockerhub地址: https://hub.docker.com/r/rancher/server v2版本的dockerhub地址: https://hub.docker.com/r/rancher/rancher/
-
拉取镜像
docker pull rancher/rancher:stable
-
运行
docker run --privileged -d --restart=always --name rancher -p 80:80 -p 443:443 rancher/rancher:stable
注意:这里不加:--privileged会报错:ERROR: Rancher must be ran with the --privileged flag when running outside of Kubernetes
-
查看日志,待日志不输出启动完毕
docker logs -f rancher
-
这里是https访问Rancher
-
第一次访问会初始化密码
-
这里直接默认了,如果你需要使用域名方式,请根据实际情况更改
-
进入主页,右下角可以切换中文
3.添加k8s集群
3.1导入方式
-
添加k8s集群
-
选择导入
-
填写集群名称创建
-
这里选择最后一个,因为我是ip方式访问的,https访问是不受信任的。注意:自签证书,也是不受信任的。只有花钱购买的证书,才是受信任的,可以选择中间的那个。
-
登陆到
k8s Master
主机curl --insecure -sfL https://172.16.215.133/v3/import/jtlznlcjmdvp9rtvgk75mzzqxsw8bwfwhld7hwrgbcxt5vvjxc64cp_c-8kxk5.yaml | kubectl apply -f -
注意:这里可能出错:Server certificate is not valid, please check if the host has the correct time configured and if the server certificate has a notAfter date and time in the future. Certificate information is displayed above. error
#有可能是时间同步问题 各个主机执行同步时间: ntpdate cn.pool.ntp.org
-
等待几分钟,查看pod
kubectl get pods -n cattle-system
-
成功:
- 点击导航栏
主机
,可以看到1个Master, 1个Node
4.一些k8s命令
- 查看所有pod
kubectl get pods --all-namespaces -o wide
- 查看某个pod日志
kubectl logs cattle-cluster-agent-65b74b775c-b2q5l -n cattle-system
- k8s删除pod方式
# 获取pod
[root@k8s-master ~]# kubectl get pods -n cattle-system
NAME READY STATUS RESTARTS AGE
cattle-cluster-agent-6d9b5d97b9-fspbr 0/1 CrashLoopBackOff 7 13m
cattle-cluster-agent-d6d8d494-4vpfw 0/1 CrashLoopBackOff 9 27m
# 删除pod
kubectl delete pod cattle-cluster-agent-6d9b5d97b9-fspbr -n cattle-system
# 获取deployment
kubectl get deployment -n cattle-system
NAME READY UP-TO-DATE AVAILABLE AGE
cattle-cluster-agent 0/1 1 0 31m
# 删除deployment
kubectl delete deployment cattle-cluster-agent -n cattle-system
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库