Skip to content

Commit bffa510

Browse files
committed
Improved README
1 parent 1a6650b commit bffa510

File tree

2 files changed

+64
-8
lines changed

2 files changed

+64
-8
lines changed

README.md

+64-8
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,80 @@
1-
# kubectl warp
2-
kubectl (Kubernetes CLI) plugin to syncronize local files to _Pod_ and executing arbitary command.
1+
<p align="center"><img src="https://github.com/ernoaapa/kubectl-warp/blob/master/media/logo.png"></p>
32

4-
## Use cases
5-
This can be used for example to build and run your local project in Kubernetes while using your prefed editor locally.
3+
---
4+
kubectl (Kubernetes CLI) plugin which is like `kubectl run` with `rsync`.
5+
6+
It creates temporary _Pod_ and synchronises your local files to the desired container and executes any command.
7+
8+
### Why
9+
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.
10+
11+
### Use cases
12+
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.
13+
14+
### Alternatives
15+
- `kubectl cp` - Does full file copying, which is slow if a lot of files
16+
- NFS - requires a lot of extra installation and configuration
17+
18+
### Other similar
19+
- [telepresence](https://telepresence.io) - Executes locally and tunnels traffic from Kubernetes
20+
- [docker-sync](https://github.com/EugenMayer/docker-sync) - Only for Docker
21+
22+
## How it works
23+
`kubectl warp` is basically just combination of, simplified and modified version of `kubectl run`, `sshd-rsync` container and `kubectl port-forward` to access the container.
24+
25+
#### 1. Start the _Pod_
26+
First the `warp` generates temporary SSH key pair and and starts a temporary _Pod_ with desired image and `sshd-rsync` container with the temporary public SSH public key as authorized key.
27+
28+
The `sshd-rsync` is just container with `sshd` daemon running in port 22 and `rsync` binary installed so the local `rsync` can sync the files to the shared volume over the SSH.
29+
The _Pod_ have the `sshd-rsync` container 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 `rsync` execution and completes after succesfully so the actual containers can start.
30+
31+
#### 2. Open tunnel
32+
To sync the files with `rsync` over the SSH, `warp` opens port forwarding from random local port to the _Pod_ port 22, what the `sshd-rsync` init- and sidecar-container listen.
33+
34+
#### 3. Initial sync
35+
At first, the _Pod_ is in init state, and only the `sshd-rsync` is running and waiting for single sync execution. When the initial sync is done, the container completes succesfully so the _Pod_ starts the actual containers.
36+
37+
> The initial sync is needed so that we can start the actual container with any command. E.g. if we have shell script `test.sh` and when the container start with `./test.sh` as the command, the file must be there available before the execution.
38+
39+
#### 4. Continuous syncing
40+
When the initial sync is done, the actual container start with `sshd-rsync` as a sidecar. The `warp` command continuously run `rsync` command locally to update the files in the _Pod_.
641

742
## Install
43+
844
### MacOS with Brew
945
```shell
10-
brew install ernoaapa/kubectl-plugins/warp
46+
brew install rsync ernoaapa/kubectl-plugins/warp
1147
```
1248
### Linux / MacOS without Brew
13-
1. Download binary from [releases](https://github.com/ernoaapa/kubectl-warp/releases)
14-
2. Add it to your `PATH`
49+
1. Install rsync with your preferred package manager
50+
2. Download `kubectl-warp` binary from [releases](https://github.com/ernoaapa/kubectl-warp/releases)
51+
3. Add it to your `PATH`
1552

1653
## Usage
17-
When the plugin binary is found from `PATH` you can just execute it through `kubectl`
54+
When the plugin binary is found from `PATH` you can just execute it through `kubectl` CLI
1855
```shell
1956
kubectl warp --help
2057
```
2158

59+
### Basics
60+
```shell
61+
# Start bash in ubuntu image. Files in current directory will be synced to the container
62+
kubectl warp -i -t --image ubuntu testing -- /bin/bash
63+
64+
# Start nodejs project in node container
65+
cd examples/nodejs
66+
kubectl warp -i -t --image node testing-node -- npm run watch
67+
```
68+
69+
### Exclude / Include
70+
Sometimes some directories are too unnecessary to sync so you can speed up the initial sync with
71+
`--exclude` and `--include` flags, those gets passed to the `rsync` command, for more info see [rsync manual](http://man7.org/linux/man-pages/man1/rsync.1.html#INCLUDE/EXCLUDE_PATTERN_RULES)
72+
```shell
73+
# Do not sync local node_modules, because we fetch dependencies in the container as first command
74+
cd examples/nodejs
75+
kubectl warp -i -t --image node testing-node --exclude="node_modules/***" -- npm install && npm run watch
76+
```
77+
2278
### Examples
2379
There's some examples with different languages in [examples directory](examples/)
2480

media/logo.png

18.2 KB
Loading

0 commit comments

Comments
 (0)