Kubernetes CLI plugin for syncing and executing local files in Pod on Kubernetes
kubectl (Kubernetes CLI) plugin which is like
kubectl runwith
rsync.
It creates temporary Pod and synchronises your local files to the desired container and executes any command.
Sometimes you need to develop/execute your code in Kubernetes, because access to database, insufficient resources locally, need access to some specific device, use specific architecture, etc. The full build image, push, deploy cycle is way too slow for real development.
This can be used for example to build and run your local project in Kubernetes where's more resources, required architecture, etc. while using your prefed editor locally.
kubectl cp- Does full file copying, which is slow if a lot of files
kubectl warpis basically just combination of, simplified and modified version of
kubectl run,
sshd-rsynccontainer and
kubectl port-forwardto access the container.
First the
warpgenerates temporary SSH key pair and and starts a temporary Pod with desired image and
sshd-rsynccontainer with the temporary public SSH public key as authorized key.
The
sshd-rsyncis just container with
sshddaemon running in port 22 and
rsyncbinary installed so the local
rsynccan sync the files to the shared volume over the SSH. The Pod have the
sshd-rsynccontainer defined twice, as init-container to make the initial sync before the actual container to start, and as a sidecar for the actual container to keep the files in-sync. The init-container waits one
rsyncexecution and completes after succesfully so the actual containers can start.
To sync the files with
rsyncover the SSH,
warpopens port forwarding from random local port to the Pod port 22, what the
sshd-rsyncinit- and sidecar-container listen.
At first, the Pod is in init state, and only the
sshd-rsyncis running and waiting for single sync execution. When the initial sync is done, the container completes succesfully so the Pod starts the actual containers.
The initial sync is needed so that we can start the actual container with any command. E.g. if we have shell script
test.shand when the container start with./test.shas the command, the file must be there available before the execution.
When the initial sync is done, the actual container start with
sshd-rsyncas a sidecar. The
warpcommand continuously run
rsynccommand locally to update the files in the Pod.
Install Krew, then run the following commands:
krew update krew install warp
brew install rsync ernoaapa/kubectl-plugins/warp
kubectl-warpbinary from releases
PATH
When the plugin binary is found from
PATHyou can just execute it through
kubectlCLI
shell kubectl warp --help
# Start bash in ubuntu image. Files in current directory will be synced to the container kubectl warp -i -t --image ubuntu testing -- /bin/bashStart nodejs project in node container
cd examples/nodejs kubectl warp -i -t --image node testing-node -- npm run watch
Sometimes some directories are too unnecessary to sync so you can speed up the initial sync with
--excludeand
--includeflags, those gets passed to the
rsynccommand, for more info see rsync manual ```shell
cd examples/nodejs kubectl warp -i -t --image node testing-node --exclude="node_modules/***" -- npm install && npm run watch ```
There's some examples with different languages in examples directory
go run ./main.go --image alpine -- ls -laSyncs your local files to Kubernetes and list the files
go install .Now you can use
kubectl
kubectl warp --help