Ninja Docs Help

Namespace migration between clusters w/ FluxCD

Revision

Date

Description

1.0

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

  1. Access to source Kubernetes cluster:

    1. Kubernetes API (cluster-admin).

    2. FluxCD cluster configuration repository (developer/maintainer).

    3. FluxCD namespace configuration repository (maintainer).

  2. Access to destination Kubernetes cluster:

    1. Kubernetes API (cluster-admin).

    2. FluxCD cluster configuration repository (developer / maintainer).

    3. FluxCD namespace configuration repository (maintainer).

  3. Some IDE installed on workstation.

  4. Known changes between clusters (e.g. new apiVersion of resources, etc.).

Instructions

To migrate namespace between Kubernetes Clusters you need to:

  1. Create new Namespace on destination Kubernetes Cluster base on existing Namespace on source Kubernetes Cluster:

    1. Go into FluxCD cluster configuration repository for source Cluster.

    2. Find directory with YAML manifests for Namespace, its configuration and other resources ( e.g. Roles, RoleBindings, Secret, etc.).

    3. Copy directory with all content.

    4. Go into FluxCD cluster configuration for destination Cluster.

    5. Paste all copied files.

    6. (optional) If you will need to update apiVersions in resources, change repository branch in GitRepository resource to not override YAML manifests on source Kubernetes clusters.

    7. Add new namespace dir to main kustomization.yaml.

    8. Commit and push your changes to remote.

  2. Verify if Namespace was created on Kubernetes Cluster by FluxCD.

  3. Verify if workload (apps) was deployed in Namespace by FluxCD.

  4. Contact with dev team to verify that apps works properly.

  5. Pass network traffic to pods on new Kubernetes Cluster (this step depends on Dev Team - work with them).

  6. Cleanup:

    1. Stop Kustomize reconciliation on old Namespace:

    flux suspend kustomization <name> -n <namespace>
    1. 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>
    1. Delete YAML manifests for namespace you migrated from Flux repository.

    2. Verify that Namespace is terminated on cluster.

    3. (optional) If you created new branch for new cluster, you may change its name to proper ( like: prd-newprd), so:

      1. merge changes from your working branch into new one.

      2. change repository branch in GitRepository (flux need to switch to new branch).

Last modified: 17 February 2025