kube-copy 0.1.0

A lightweight CLI utility to automatically synchronize local files into Kubernetes pods
# ๐Ÿ”„ kube-copy: Kubernetes Pod File Syncer

`kube-copy` is a lightweight CLI utility to automatically synchronize local files into Kubernetes pods using `kubectl cp`. It watches your file system and Kubernetes pod lifecycle, keeping your app files up to date in development environments.

---

## ๐Ÿš€ Features

- โšก๏ธ Real-time file sync to running pods
- ๐Ÿง  Sync on pod restarts (via label selectors)
- ๐Ÿ“ Sync only on changes, with debounce
- โœ… Smart pod readiness check (all containers must be `Ready`)
- ๐Ÿ“Ÿ Optional post-sync command (e.g. `touch` a file or trigger reload)
- ๐Ÿ“ฆ Simple JSON configuration
- ๐Ÿงช Designed for rapid local dev with K8s

---

## ๐Ÿ“ฆ Installation

### Manual
```bash
cargo build --release
cp target/release/kube-copy /usr/local/bin
```

---

## ๐Ÿ“„ Configuration: `watcher.json`

```json
[
  {
    "name": "sync-common",
    "kube_context": "minikube",
    "namespace": "default",
    "label_selectors": ["app=my-app"],
    "paths": [
      { "src": "./local/path", "dest": "/app/dest" }
    ],
    "post_sync_command": "touch /app/.reload"
  }
]
```

### ๐Ÿ” `post_sync_command` (optional)
If provided, this shell command is executed **inside each pod** via `kubectl exec` after each successful sync.

Use it to:
- Trigger live-reload scripts
- Touch a watched file (e.g. for `nodemon`)
- Run arbitrary shell hooks in your container

---

## ๐Ÿงฐ Usage

```bash
kube-copy --config watcher.json
```

### Options

| Option            | Description                                   |
|-------------------|-----------------------------------------------|
| `--config`        | Path to config file (default: `watcher.json`) |
| `--sync-on-start` | Trigger sync to all ready pods at startup     |

---

## ๐Ÿ›  How it works

- Uses `notify` to track file changes
- Uses `kube` + `kube-runtime` to track pod events
- On trigger, uses `kubectl cp` to sync file/directory
- Ensures pods are `Ready` before syncing
- Optionally executes `post_sync_command` in pod via `kubectl exec`

---

## ๐Ÿ“Œ When to Use

This tool is ideal for:

- Local development inside Kubernetes
- Replacing bind mounts / volumes in dev
- Hot reload / live update setups with fast iteration cycles

---

## ๐Ÿ’ก Why not `ksync`, `telepresence`, or `skaffold`?

Those tools are powerful, but often:

- Heavier in dependencies
- Require sidecars or privileged Daemons
- Use custom CRDs / controllers

`kube-copy` is zero-cluster-dependency: it's just you, your files, and your pods.

---

## ๐Ÿ“ƒ License

MIT ยฉ 2025 Dmitry Rusov