Namespace migration between clusters w/ FluxCD
Revision | Date | Description |
|---|---|---|
| 24.07.2024 | Init Changelog |
Introduction
This article show you how to migrate namespace w/ workload and configuration from one Kubernetes Cluster to another.
Requirements
Access to source Kubernetes cluster:
Kubernetes API (
cluster-admin).FluxCD cluster configuration repository (
developer/maintainer).FluxCD namespace configuration repository (
maintainer).
Access to destination Kubernetes cluster:
Kubernetes API (cluster-admin).
FluxCD cluster configuration repository (developer / maintainer).
FluxCD namespace configuration repository (maintainer).
Some IDE installed on workstation.
Known changes between clusters (e.g. new apiVersion of resources, etc.).
Instructions
To migrate namespace between Kubernetes Clusters you need to:
Create new
Namespaceon destination Kubernetes Cluster base on existingNamespaceon source Kubernetes Cluster:Go into FluxCD cluster configuration repository for source Cluster.
Find directory with YAML manifests for
Namespace, its configuration and other resources ( e.g.Roles,RoleBindings,Secret, etc.).Copy directory with all content.
Go into FluxCD cluster configuration for destination Cluster.
Paste all copied files.
(optional) If you will need to update
apiVersionsin resources, change repository branch inGitRepositoryresource to not override YAML manifests on source Kubernetes clusters.Add new namespace dir to main
kustomization.yaml.Commit and push your changes to remote.
Verify if
Namespacewas created on Kubernetes Cluster by FluxCD.Verify if workload (apps) was deployed in Namespace by FluxCD.
Contact with dev team to verify that apps works properly.
Pass network traffic to pods on new Kubernetes Cluster (this step depends on Dev Team - work with them).
Cleanup:
Stop Kustomize reconciliation on old
Namespace:
flux suspend kustomization <name> -n <namespace>Delete migrated workload from old cluster (one by one) - if you forgot about something (like Secret, CM, etc.) don’t worry - it will be destroyed when you delete Namespace:
kubectl delete <resource> <name> -n <namespace>Delete YAML manifests for namespace you migrated from Flux repository.
Verify that
Namespaceis terminated on cluster.(optional) If you created new branch for new cluster, you may change its name to proper ( like:
prd-new→prd), so:merge changes from your working branch into new one.
change repository branch in
GitRepository(flux need to switch to new branch).