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
原文地址:https://www.cnblogs.com/xujunkai/p/14670827.html