• copy —— docker cp & kubectl cp


    1. 从 doker copy 到本机:

    docker cp [pod-name]:/[path]/[file].log ./

    kubectl cp {namespace}/{podname}:/{podpath} {localdir}

     kubectl cp alpha/pl****-deployment-cf5fcc6c8-vw7r7:/var/log/*****ls.log test.log

    原文:https://www.cnblogs.com/liucx/p/13273632.html

    kubectl cp -c cloud-loan-gate uat/cloud-786d84c554-p7jz7:app/logs/app/cloud.log cloud.log
    注:
    uat:为namespace
    -c :指定容器(因pod中有多个container,默认从第一个,有可能报错找不到文件和目录)
    源目录参数时,:后只能跟文件名,不能是以“/”开头的路径(eg:app/logs/cloud.log)
    目标参数时,必须为文件不能是一个目录(eg:cloud.log)

    kubectl cp 命令使用

    kubectl cp --help
    Copy files and directories to and from containers.
    Examples:
    # !!!Important Note!!!
    # Requires that the 'tar' binary is present in your container
    # image. If 'tar' is not present, 'kubectl cp' will fail.

    # Copy /tmp/foo_dir local directory to /tmp/bar_dir in a remote pod in the default namespace
    kubectl cp /tmp/foo_dir <some-pod>:/tmp/bar_dir

    # Copy /tmp/foo local file to /tmp/bar in a remote pod in a specific container
    kubectl cp /tmp/foo <some-pod>:/tmp/bar -c <specific-container>

    # Copy /tmp/foo local file to /tmp/bar in a remote pod in namespace <some-namespace>
    kubectl cp /tmp/foo <some-namespace>/<some-pod>:/tmp/bar

    # Copy /tmp/foo from a remote pod to /tmp/bar locally
    kubectl cp <some-namespace>/<some-pod>:/tmp/foo /tmp/bar

    Options:
    -c, --container='': Container name. If omitted, the first container in the pod will be chosen
    --no-preserve=false: The copied file/directory's ownership and permissions will not be preserved in the container

    Usage:
    kubectl cp <file-spec-src> <file-spec-dest> [options]

    出处:https://www.cnblogs.com/liucx/

    前提:在容器里需要安装tar命令:
    [root@k8s-master ~]# kubectl exec -it cloud-786d84c554-p7jz7 /bin/bash
    bash-4.2# yum -y install tar

    从Pod容器中copy文件至本地

    kubectl cp -c cloud-loan-gate uat/cloud-786d84c554-p7jz7:app/logs/app/cloud.log cloud.log
    注:
    uat:为namespace
    -c :指定容器(因pod中有多个container,默认从第一个,有可能报错找不到文件和目录)
    源目录参数时,:后只能跟文件名,不能是以“/”开头的路径(eg:app/logs/cloud.log)
    目标参数时,必须为文件不能是一个目录(eg:cloud.log)

  • 相关阅读:
    敏捷开发流程的8个步骤
    PingCode Wiki ——国内最顶级的产研团队知识库产品介绍
    国内外最知名的9大工作任务管理软件盘点
    国内外最好用的18个协同办公系统盘点
    知识库的作用
    国内外好用的OKR管理工具有哪些?
    敏捷宣言及完整解读
    如何在敏捷中管理和减少技术负债?
    敏捷开发框架都有哪些
    PingCode与Jira 敏捷开发管理能力的对比
  • 原文地址:https://www.cnblogs.com/panpanwelcome/p/14850661.html
Copyright © 2020-2023  润新知