@andresnator/k8s-clone
v1.2.0
Published
A CLI tool to clone and migrate Kubernetes resources across namespaces
Maintainers
Readme
K8s Migrator
A CLI tool to clone and migrate Kubernetes resources across namespaces.
Features
- Granular selection of resources (Services, Deployments, ConfigMaps, Secrets, PVCs).
- PVC data migration (copies volume contents).
- Friendly interactive interface.
- Automatic update notifications - displays when a newer version is available on npm.
- Custom Apps - Group and deploy related Kubernetes resources as configurable applications (see CUSTOM_APPS.md).
Requirements
- Node.js (Tested on v20.x and v22.x)
kubectlinstalled and available in your PATH.- Access to a Kubernetes cluster (current context in
~/.kube/config).
Installation
Global Installation (Recommended)
Install k8s-clone globally from npm:
npm install -g @andresnator/k8s-cloneThen run:
k8s-cloneLocal Development
git clone https://github.com/andresnator/k8s-clone.git
cd k8s-clone
npm install
npm run buildConfiguration
k8s-clone uses an optional configuration file at ~/.k8s-clone/config.yaml to store default cluster and namespace settings.
Setup: Run npm run setup to create the configuration directory and file automatically.
Custom Location: Set K8S_CLONE_CONFIG environment variable to use a different path.
Behavior: When empty, the tool auto-detects clusters from ~/.kube/config and fetches resources via Kubernetes API. When populated, it uses pre-configured values. See config.example.yaml for structure details.
Environment Variables
K8S_CLONE_CONFIG: Set a custom path for the configuration file (default:~/.k8s-clone/config.yaml)K8S_CLONE_SKIP_VERSION_CHECK: Set to any truthy value (true,1,yes, or any non-empty string) to skip version update checks (useful for CI/CD environments)
Usage
If installed globally:
k8s-cloneIf running locally:
npm startFollow the on‑screen prompts to choose the source namespace, the destination namespace, and the resources you wish to migrate.
Command-Line Options
--version, -v: Display the current version number--help, -h: Display help information
Custom Apps
The Custom Apps feature allows you to group related Kubernetes resources into logical applications and deploy them as a unit with optional spec overrides.
Key Features:
- Define applications once in config, deploy multiple times
- Override resource specs per environment (e.g., replica counts, storage sizes)
- Support for deep nesting in overwrite-spec
- Duplicate resource detection and warnings
For complete documentation, examples, and troubleshooting, see CUSTOM_APPS.md.
Demo
Want to see it in action? We have prepared a comprehensive Demo Guide that walks you through a realistic migration scenario.
The demo uses a full-stack application (Frontend + Backend + Database) with persistent storage to showcase:
- Stateful Migration: Moving PVCs with actual data.
- Configuration Handling: Migrating ConfigMaps and Secrets.
- Networking: Preserving Services and Ingress rules.
Check out DEMO.md for step-by-step instructions on how to deploy the test app and run the migration.
Multi-Cluster Setup
For testing with Minikube profiles, see the detailed Demo Guide which includes multi-cluster migration scenarios.
How It Works
- Select Contexts & Namespaces: Choose source/destination clusters and namespaces
- Select Resources: Interactive prompts let you choose which resources to migrate
- Clean Metadata: System-generated fields are automatically removed
- Migrate Data: PVC data is transferred using temporary pods and
tarstreaming - Create Resources: All selected resources are recreated in the destination namespace
Project Structure
src/index.ts- CLI entry point and user interaction flowsrc/migrator.ts- Core migration logicsrc/cleaner.ts- Resource cleanup logicsrc/k8s.ts- Kubernetes API client wrappersrc/ui.ts- Interactive UI componentssrc/config.ts- Configuration managementsrc/metadata-cleaner.ts- Metadata cleaning utilitiessrc/resource-handlers.ts- Resource-specific handling logicsrc/types.ts- TypeScript type definitionssrc/Banner.tsx- Banner componentscripts/setup.sh- Configuration setup scriptdemo/demo.yaml- Complete demo application manifest
Testing
To run the unit tests:
npm testContributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines on how to contribute, including our commit message conventions and automated release process.
License
This project is licensed under the MIT License — see the LICENSE file for details.
SPDX-License-Identifier: MIT
