zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    HTTP响应状态码
    跨域
    第一章-极限与函数
    离群点检测
    关联规则(初识)
    python分类预测模型的特点
    分类预测算法评价(初识)
    人工神经网络(初识)
    决策树(初识)
    挖掘建模
  • 原文地址:https://www.cnblogs.com/ExMan/p/13955582.html
Copyright © 2011-2022 走看看