rancher-cli的使用


Rancher CLI工具可用於與Rancher進行交互,使用此工具,可以使用命令行而不是GUI來操作Rancher並管理其下的資源。

1、下載rancher-cli工具

Rancher CLI二進制文件可以直接從Rancher UI下載,下載鏈接可以從Rancher UI右下角找到。還可以從rancher的中文文檔中的文件下載頁面進行下載。我這里獲取到下載鏈接之后,直接用wget下載。

[root@jenkins ~]# wget https://releases.rancher.com/cli2/v2.3.2/rancher-linux-amd64-v2.3.2.tar.gz [root@jenkins ~]# tar -zxf rancher-linux-amd64-v2.3.2.tar.gz 
  • 1
  • 2

2、配置到環境變量中

[root@jenkins ~]# mv rancher-v2.3.2/rancher /usr/bin/rancher [root@jenkins ~]# rm -rf rancher-v2.3.2/ 
  • 1
  • 2

3、登錄測試

新建用戶獲取token:
在這里插入圖片描述

點擊右上角的添加Key創建一個永不過期的API Key
在這里插入圖片描述

注意:創建好之后,把這些信息復制到自己文本上,因為根據下面的提示,關閉之后,就看不到這些信息了!!!

然后使用下面的命令進行登錄:

[root@jenkins ~]# rancher login https://my.rancher.com/v3 --token token-8hf5t:vjg54wv88lqvl5vvr6njz8zdj47g8wd4btnv7gg2cmv5mpc74v4vhs 
  • 1

注意:這里的測試主機需要能夠訪問my.rancher.com,因為我是在內網環境中,所以就直接把域名解析寫到/etc/hosts中。

4、驗證功能

因為我們需要操作Rancher來執行kubecel命令,所以還需要在這台測試機中安裝kubectl命令,否則執行相關操作的時候會報如下錯誤:

FATA[0000] kubectl is required to be set in your path to use this command. See https://kubernetes.io/docs/tasks/tools/install-kubectl/ for more info. Error: exec: "kubectl": executable file not found in $PATH 
  • 1

下面執行兩條命令來驗證一下:

[root@jenkins ~]# rancher kubectl get node NAME STATUS ROLES AGE VERSION 192.168.0.51 Ready controlplane,etcd,worker 41h v1.17.2 192.168.0.52 Ready controlplane,etcd,worker 41h v1.17.2 192.168.0.53 Ready controlplane,etcd,worker 41h v1.17.2 [root@jenkins ~]# rancher kubectl get pod --all-namespaces NAMESPACE NAME READY STATUS RESTARTS AGE cattle-system cattle-cluster-agent-74484cb88c-26zm5 1/1 Running 16 39h cattle-system cattle-node-agent-m77cf 1/1 Running 17 39h cattle-system cattle-node-agent-tzkxl 1/1 Running 16 39h cattle-system cattle-node-agent-v9tcz 1/1 Running 17 39h cattle-system rancher-58b6b8cfd-fx9pg 1/1 Running 7 40h cattle-system rancher-58b6b8cfd-mnv4k 1/1 Running 8 39h cattle-system rancher-58b6b8cfd-twmfl 1/1 Running 8 40h demo demo-7745d445bc-dpj49 1/1 Running 1 16h ingress-nginx default-http-backend-67cf578fc4-lb9g9 1/1 Running 3 41h ingress-nginx nginx-ingress-controller-8cg62 1/1 Running 12 41h ingress-nginx nginx-ingress-controller-r5s6p 1/1 Running 128 41h ingress-nginx nginx-ingress-controller-sqccm 1/1 Running 12 41h kube-system canal-ddm6r 2/2 Running 8 41h kube-system canal-v7b4z 2/2 Running 10 41h kube-system canal-zdkj6 2/2 Running 8 41h kube-system coredns-7c5566588d-64d6l 1/1 Running 4 40h kube-system coredns-7c5566588d-8z4wm 1/1 Running 4 41h kube-system coredns-autoscaler-65bfc8d47d-bgppk 1/1 Running 4 41h kube-system metrics-server-6b55c64f86-b8qhq 1/1 Running 7 41h kube-system rke-coredns-addon-deploy-job-lxnkn 0/1 Completed 0 41h kube-system rke-ingress-controller-deploy-job-gq7vj 0/1 Completed 0 41h kube-system rke-metrics-addon-deploy-job-j66qn 0/1 Completed 0 41h kube-system rke-network-plugin-deploy-job-tlscj 0/1 Completed 0 41h nfs-provisioner nfs-provisioner-0 1/1 Running 4 17h 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33

好了,這樣就成功的實現了通過Rancher CLI來操作rancher了,在后面的Jenkins配置中會用到這個功能。

參考文章:
http://www.eryajf.net/2734.html


免責聲明!

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



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