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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM