Rancher-2-2-2学习笔记-rancher-cli的使用
文章发布较早,内容可能过时,阅读注意甄别。
Rancher CLI
是一个统一的工具,可用于与 Rancher 进行交互。借助于此工具,我们可以使用命令行来操作 Rancher 并管理其下的资源。
- 1、下载 rancher-cli 工具
可以通过官方的文件下载 (opens new window)页面进行下载,也可以直接在首页右下角的下载 cli 进行下载,这里直接通过命令方式进行下载。
[root@jenkins ~]$ wget https://releases.rancher.com/cli2/v2.2.0/rancher-linux-amd64-v2.2.0.tar.gz
[root@jenkins ~]$ tar xf rancher-linux-amd64-v2.2.0.tar.gz
1
2
2
- 2、配置进系统中
mv rancher-v2.2.0/rancher /usr/bin/rancher
rm -rf rancher-v2.2.0/
1
2
2
- 3、测试登录
新建用户获取 tonken:
创建一个永不过期的 token,以用于验证使用。
使用如下命令进行登陆:
[root@jenkins ~]$ rancher login https://rancher.com/v3 --token token-fkgj6:gd2z99wnfgc2zw9pw969rppgbnrfwg7l59l4gccqp5wmdc6vd27r5l
1
注意
:这里测试的主机需要能够访问rancher.com
,如果都在内网环境中,那么可以直接把域名对应解析写入到主机hosts
中。
注意,还需要安装 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.106.3 Ready controlplane,etcd,worker 32m v1.11.6
192.168.106.4 Ready controlplane,etcd,worker 32m v1.11.6
192.168.106.5 Ready controlplane,etcd,worker 32m v1.11.6
1
2
3
4
5
2
3
4
5
借此机会来个安装应用的定妆照!
[root@jenkins ~]$rancher kubectl get pod --all-namespaces
NAMESPACE NAME READY STATUS RESTARTSAGE
cattle-system cattle-cluster-agent-5c9d5cbb87-nlf8x 1/1 Running 016m
cattle-system cattle-node-agent-6ncnb 1/1 Running 016m
cattle-system cattle-node-agent-cdpww 1/1 Running 016m
cattle-system cattle-node-agent-l48m8 1/1 Running 016m
cattle-system rancher-bdf49fb9-7qhgp 1/1 Running 131m
cattle-system rancher-bdf49fb9-hf6tm 1/1 Running 031m
cattle-system rancher-bdf49fb9-xmbv7 1/1 Running 131m
ingress-nginx default-http-backend-797c5bc547-nnqzt 1/1 Running 034m
ingress-nginx nginx-ingress-controller-mn9jl 1/1 Running 034m
ingress-nginx nginx-ingress-controller-rrm8z 1/1 Running 034m
ingress-nginx nginx-ingress-controller-vt8lx 1/1 Running 034m
kube-system canal-9r7jt 3/3 Running 034m
kube-system canal-b86n6 3/3 Running 034m
kube-system canal-lqk8g 3/3 Running 034m
kube-system cert-manager-cert-manager-8f55cc84b-z84kw 2/2 Running 031m
kube-system kube-dns-7588d5b5f5-dnqk7 3/3 Running 034m
kube-system kube-dns-autoscaler-5db9bbb766-cfqcg 1/1 Running 034m
kube-system metrics-server-97bc649d5-lkn57 1/1 Running 034m
kube-system rke-ingress-controller-deploy-job-s5ss8 0/1 Completed 034m
kube-system rke-kubedns-addon-deploy-job-p2hjb 0/1 Completed 034m
kube-system rke-metrics-addon-deploy-job-fqvfm 0/1 Completed 034m
kube-system rke-network-plugin-deploy-job-7zr8v 0/1 Completed 034m
kube-system tiller-deploy-8cb5b5f5c-qzk5z 1/1 Running 032m
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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
OK,看到能够这样执行命令,就可以了,后边的流水线工作就不用发愁了。
上次更新: 2024/11/19, 23:11:42