Code Monkey home page Code Monkey logo

kubectl-cpbase64's Introduction

kubectl-cpbase64 - an alternative to kubectl cp

install

manual install

  • Put script kubectl-cpbase64 into environment variable PATH.
mkdir -p ~/.local/bin
cp src/kubectl-cpbase64 ~/.local/bin
chmod u+x ~/.local/bin/kubectl-cpbase64
export PATH=~/.local/bin:${PATH}

kubectl cpbase64 help

install via krew plug-in manager

  • Install via krew.
# install latest release
kubectl krew install cpbase64

# use it
kubectl cpbase64 help
  • Install via krew using this repo URL.
kubectl krew index add cpbase64 'https://github.com/freeella/kubectl-cpbase64.git'
kubectl krew update
kubectl krew index list

# install latest release
kubectl krew install cpbase64/cpbase64

# install special version (example: cpbase64 v0.2.6)
kubectl krew install cpbase64/cpbase64-v0-2-6

# install pre-release version
kubectl krew install cpbase64/cpbase64-test

# use it
kubectl cpbase64 version
kubectl cpbase64 help

purpose

Rootless and distroless containers are very popular these days. This means that as less as possible command line tools are installed inside containers and no additional tools can be installed later. Distributions that do not ship busybox often do not ship tar by default.

Without tar command kubectl cp can't be used to copy debug data such as memory dumps from the container.

Because the command line tool base64 is still installed on many containers, kubectl cpbase64 tries to be an alternative to kubectl cp by falling back to base64 and trying to be in sync with command line syntax of kubectl cp.

Usage:  kubectl cpbase64 [from_location] [to_location] [-c container_name]
        kubectl cpbase64 [-l|--local] /tmp/foo.txt [-r|--remote] [NS/]some-pod:[.|/tmp/[bar.txt]] [-c container_name]
        kubectl cpbase64 [-r|--remote] [namespace/]some-pod:/tmp/foo.txt  [-l|--local] [.|/tmp/[bar.txt]] [-c container_name]

        'kubectl cpbase64' tries to be an alternative to 'kubectl cp'
        when 'tar' is not available. Command 'base64' is used instead.

        Command line syntax of 'kubectl cpbase64' is similar to 'kubectl cp'!

Command line examples:

        kubectl cpbase64 version - returns the version of this plugin
        kubectl cpbase64 help - returns this help screen

        # Copy /tmp/foo from a remote pod to /tmp/bar locally
        kubectl cpbase64 <some-pod>:/tmp/foo /tmp/bar
        kubectl cpbase64 <some-namespace>/<some-pod>:/tmp/foo /tmp/bar
        kubectl cpbase64 <some-namespace>/<some-pod>:/tmp/foo /tmp/bar -c <specific-container>
        kubectl cpbase64 <some-pod>:/tmp/foo /tmp/bar -c <specific-container>

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

        # cpbase64 specific:
        # Copy /tmp/foo from a remote pod to /tmp/foo locally
        kubectl cpbase64 <some-pod>:/tmp/foo /tmp/
        kubectl cpbase64 <some-pod>:/tmp/foo /tmp
        cd ~/tmp; kubectl cpbase64 <some-pod>:/tmp/foo .

        # Copy local /tmp/foo to a remote pod file /tmp/foo
        kubectl cpbase64 /tmp/foo <some-pod>:/tmp/
        # Copy local /tmp/foo to a remote pod file ~/foo
        kubectl cpbase64 /tmp/foo <some-pod>:.

        # Copy local /tmp/foo_2024-04-01_20:33:44 to some remote pod file /tmp/bar_2024-04-01_20:33:44
        kubectl cpbase64 -l /tmp/foo_2024-04-01_20:33:44 -r <some-pod>:/tmp/bar_2024-04-01_20:33:44
        kubectl cpbase64 --local /tmp/foo_2024-04-01_20:33:44 --remote <some-pod>:/tmp/bar_2024-04-01_20:33:44

        # Copy from some remote pod file /tmp/foo_2024-04-01_20:33:44 to a local file /tmp/bar_2024-04-01_20:33:44
        kubectl cpbase64 -r <some-pod>:/tmp/foo_2024-04-01_20:33:44 -l /tmp/bar_2024-04-01_20:33:44
        kubectl cpbase64 --remote <some-pod>:/tmp/foo_2024-04-01_20:33:44 --local /tmp/bar_2024-04-01_20:33:44

kubectl-cpbase64's People

Watchers

 avatar

kubectl-cpbase64's Issues

Have k3s based unit tests

It would be nice to have test that copying real files from and to test PODs

Maybe action-k3s-helm is worth a try.

https://github.com/jupyterhub/action-k3s-helm/tree/main
https://github.com/jupyterhub/action-k3s-helm/blob/main/.github/workflows/test_k3s.yml

name: Example workflow

on:
  pull_request:
  push:
  workflow_dispatch:

jobs:
  k8s-test:
    runs-on: ubuntu-22.04
    steps:
      # GitHub Action reference: https://github.com/jupyterhub/action-k3s-helm
      - name: Start a local k8s cluster
        uses: jupyterhub/action-k3s-helm@v4
        with:
          # See available:
          # - k3s release channels at https://github.com/k3s-io/k3s/blob/HEAD/channel.yaml
          # - k3s versions at https://github.com/k3s-io/k3s/tags
          # - helm versions at https://github.com/helm/helm/tags
          k3s-channel: latest
          # k3s-version: v1.29.0+k3s1
          # helm-version: v3.13.0

      - name: Verify function of k8s, kubectl, and helm
        run: |
          echo "kubeconfig: $KUBECONFIG"
          kubectl version
          kubectl get pods --all-namespaces

No file names with : supported

The current version does not support file names with : inside

  • fixing for the remote host parameter should be easy (using sed instead of split)
  • but how to implement it for the local file name?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.