https://github.com/epolevov/k8s-migrate
Migrate Kubernetes namespaces and resources between clusters using kubectl in one command.
https://github.com/epolevov/k8s-migrate
devops devops-tools k8s kubernetes transfer-data
Last synced: about 1 month ago
JSON representation
Migrate Kubernetes namespaces and resources between clusters using kubectl in one command.
- Host: GitHub
- URL: https://github.com/epolevov/k8s-migrate
- Owner: epolevov
- License: mit
- Created: 2025-08-05T13:21:43.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2025-08-05T13:23:18.000Z (11 months ago)
- Last Synced: 2025-08-05T15:20:46.287Z (11 months ago)
- Topics: devops, devops-tools, k8s, kubernetes, transfer-data
- Language: Shell
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ๐ ๏ธ k8s-migrate
[](./LICENSE)
[](https://www.gnu.org/software/bash/)
[](https://kubernetes.io/)
A lightweight Bash CLI utility to **migrate a namespace's resources between Kubernetes clusters** (contexts) using `kubectl`.
---
## ๐ What This Tool Does
`k8s-migrate.sh` interactively exports and applies Kubernetes resources from a specified namespace between two kube-contexts โ allowing you to:
- Migrate applications from **dev โ prod**, **test โ staging**, etc.
- Sync environments quickly
- Prepare for cluster upgrades or provider migrations
It works using native `kubectl` commands and supports all common namespaced resources.
---
## ๐ Quick Start
### โ
Prerequisites
- `kubectl` installed and configured
- Both clusters defined in your `~/.kube/config`
- Access rights to export and apply resources
> Optional:
>
> - [`yq`](https://github.com/mikefarah/yq) for sanitizing exported YAML
> - `kubectl neat` for cleaning unnecessary fields
---
### ๐งช Demo
```bash
chmod +x k8s-migrate.sh
./k8s-migrate.sh [--dryRun]
```
```text
Enter namespace to migrate: my-app
Enter source K8S context (from-cluster): dev-cluster
Enter target K8S context (to-cluster): prod-cluster
Select resources to migrate (space-separated or 'all'):
Available: deployments services configmaps secrets ingresses pvc all
> all
๐ Migration Summary:
Namespace: my-app
Source cluster: dev-cluster
Target cluster: prod-cluster
Resources: deployments services configmaps secrets ingresses pvc
Dry Run Mode: true
Proceed with migration? (y/n): y
๐ค Exporting...
๐ฅ Importing...
โ
Migration complete (dry-run only).
```
---
## ๐ง Supported Resources
- `deployments`
- `services`
- `configmaps`
- `secrets` โ ๏ธ
- `ingresses`
- `pvc` (PersistentVolumeClaims)
You can select specific types or use `all` to migrate everything listed above.
---
## ๐ Secret Handling
Secrets are exported and applied as-is. Be careful:
- **Do not** migrate `service account tokens` or `cloud provider credentials` unless necessary.
- Consider sanitizing secrets before applying them to another cluster.
---
## ๐ Temporary Files
All exported resources are saved to a temporary working directory (via `mktemp -d`) and applied from there. This folder is **not deleted automatically**, so you can inspect or archive it if needed.
---
## ๐งฑ Advanced Ideas
Want to improve or extend this?
- โ
Add `--dryRun` support to preview changes before applying โ
- Sanitize YAML via `yq` or `kubectl neat`
- Support Helm releases or CRDs
- Use labels or selectors to filter resources
- Migrate RBAC (`RoleBinding`, `ServiceAccount`, etc.)
---
## ๐งโ๐ป Author
Created by [@epolevov](https://github.com/epolevov)\
Maintained by the engineering team at [EMD Labs](https://emd.one)
---
## ๐ License
This project is licensed under the [MIT License](./LICENSE).