zoukankan      html  css  js  c++  java
  • Windows下Rancher复制Pod内文件到本地

    Rancher 未提供直接获取 Pod 内文件的工具(如果有请评论告知下,蟹蟹),但提供了 Rancher 的 CLI 客户端,通过 CLI 可以调用 k8s 的 CLI (kubectl) 命令来操作集群及复制文件。

    为简化操作,本文将 rancher.exe 和 kubectl.exe 都复制到了 系统环境变量Path下,比如在 C盘建了个usrbin目录。

    复制rancher与 k8s 的客户端到 Path

    rancher.exe可以通过官网,也可以通过Rancher UI 右下角下载;

    kubectl.exe 下载地址,需有技巧地上网。

    下载完成复制到 C:/usrbin 下。至于想放到其他地方也可以,把其他目录添加到 当前用户或全局 Path下即可。

    添加环境变量

    验证CLI可用性

    打开GitBash执行如下命令:

    rancher --version
    kubectl version
    

    创建API & Keys

    Scope千万不要选,如果指定集群后,会无法CLI登录。

    创建CLI存储登录信息目录

    创建目录 C:Users当前用户名.rancher

    配置CLI存储登录信息环境变量

    新建用户环境变量 RANCHER_CONFIG_DIR,值为 C:Users当前用户名.rancher,即上节创建的目录绝对路径

    使用CLI登录

    新启一个cmd,执行命令登录

    rancher login https://<SERVER_URL> --token <BEARER_TOKEN>
    

    示例:

    $ rancher login https://xxx.xxx.com.cn --token token-xzgj2:5t4kjp2gvhgs52n68fjwfzpxk8g7rjz5s92kdm8ldhnpkrb2hq477s
    The authenticity of server 'https://xxx.xxx.com.cn' can't be established.
    Cert chain is : [Certificate:
        Data:
            Version: 3 (0x2)
            Serial Number: 11600916281625505644 (0xa0febbe4d3556f6c)
        Signature Algorithm: SHA256-RSA
            Issuer: C=CN,CN=localhost
            Validity
    ...省略自签证书提示
    Do you want to continue connecting (yes/no)? yes #自签证书需要显式连接确认
    NUMBER    CLUSTER NAME   PROJECT ID        PROJECT NAME   PROJECT DESCRIPTION
    1         cwgx           c-txpcb:p-2vpxb   fssc_std
    2         cwgx           c-txpcb:p-x76h6   fssc_demo
    Select a Project:1 #输入项目编号
    time="2021-09-07T11:42:37+08:00" level=info msg="Saving config to C:\Users\hellxz\.rancher\cli2.json"
    
    

    通过rancher CLI使用kubectl命令

    rancher限制了用户可以访问的命名空间,需要指明在哪个命名空间操作

    命令格式:

    #查看命名空间
    rancher namespaces
    #执行kubectl命令,需指定命名空间
    rancher kubectl <具体命令> -n <命名空间>
    #查看指定命名空间下Pod列表
    rancher kubectl get po -n <命名空间名>
    

    示例:

    $ rancher namespaces
    ID         NAME       STATE     PROJECT           DESCRIPTION
    fssc-std   fssc-std   active    c-txpcb:p-2vpxb
    $ rancher kubectl get po -n fssc-std
    NAME                                READY   STATUS    RESTARTS   AGE
    bud-nvwa-server-5d756595df-5nv8g    1/1     Running   0          3d20h
    fssc-nros-7bb6776cd9-f5hln          1/1     Running   0          4d13h
    fssc-nvwa-server-5d76dfc695-qvqkr   1/1     Running   0          3d20h
    gateway-787c4777f9-bt72b            1/1     Running   1          32d
    

    复制Pod名称取出容器内文件

    rancher kubectl cp <Pod名称>:<绝对路径> <当前相对路径> -n <命名空间名>
    

    比如取 bud-nvwa-server-6768b4859-kmhk6 容器内的 /app/logs 目录到 我的桌面(注意相对路径)

    到此文件已经拷到本地了。

    更多CLI命令参考

    CSDN博客园同步更新

  • 相关阅读:
    c#自动更新+安装程序的制作
    VS2013项目受源代码管理向源代码管理注册此项目时出错
    WinDbg配置和使用基础
    InstallShield Limited Edition for Visual Studio 2013 图文教程(教你如何打包.NET程序)
    PowerDesigner 如何生成数据库更新脚本
    用户故事(User Story)
    Troubleshooting Record and Playback issues in Coded UI Test
    Coded UI
    compare two oracle database schemas
    How to: Use Schema Compare to Compare Different Database Definitions
  • 原文地址:https://www.cnblogs.com/hellxz/p/copy-pod-files-by-rancher-cli.html
Copyright © 2011-2022 走看看