|
| 1 | +# Migrating Kubespray clusters from Calico to Cilium CNI |
| 2 | + |
| 3 | +> [!NOTE] |
| 4 | +> Clusters will be migrated one at a time depending on the environment variable `TARGET_CLUSTER`. |
| 5 | +> |
| 6 | +> It does not matter which cluster is migrated first, but it is recommended to start the migration with the _service_ cluster. |
| 7 | +> |
| 8 | +> It's also worth mentioning that full network connectivity is maintained between the Calico and Cilium subnets during the migration. |
| 9 | +> |
| 10 | +> For reference, it takes about 5 minutes to complete the disruptive parts of this guide, on a cluster with 5 nodes. |
| 11 | +
|
| 12 | +> [!IMPORTANT] |
| 13 | +> This guide assumes all commands are run from the `migration/calico-to-cilium` directory of the `compliantkubernetes-kubespray` repository. |
| 14 | +
|
| 15 | +> [!IMPORTANT] |
| 16 | +> The Cilium pod subnet is preconfigured to `10.235.64.0/18`, in accordance with the recommended value from the official documentation. |
| 17 | +> |
| 18 | +> This should prevent any overlaps with the Calico subnet, assumed to have the `10.233.0.0/16` prefix. |
| 19 | +
|
| 20 | +## Prerequisites |
| 21 | + |
| 22 | +The migration uses the Cilium CLI for status checks, as well as the `evict` plugin for `kubectl`. |
| 23 | + |
| 24 | +You will need to install the following on your system: |
| 25 | + |
| 26 | +### Golang |
| 27 | + |
| 28 | +On Ubuntu: `sudo apt install golang-go` |
| 29 | + |
| 30 | +### The Cilium CLI |
| 31 | + |
| 32 | +Grab the binary from the [GitHub releases page](https://github.com/cilium/cilium-cli/releases) and put it somewhere in your `PATH`. |
| 33 | + |
| 34 | +To have it installed under `${HOME}/.local/bin`: |
| 35 | + |
| 36 | +```shell |
| 37 | +mkdir -p "${HOME}/.local/bin" |
| 38 | +curl -fsSL -o- https://github.com/cilium/cilium-cli/releases/download/v0.18.7/cilium-linux-amd64.tar.gz | tar -zxv -C "${HOME}/.local/bin" |
| 39 | +mv "${HOME}/.local/bin/cilium" "${HOME}/.local/bin/cilium-cli" |
| 40 | +``` |
| 41 | + |
| 42 | +> [!NOTE] |
| 43 | +> This assumes that the `${HOME}/.local/bin` directory is within your `PATH`. If that's not the case: |
| 44 | +> `export PATH="$PATH:$HOME/.local/bin"` |
| 45 | +
|
| 46 | +> [!IMPORTANT] |
| 47 | +> The migration scripts assume the executable name for the Cilium CLI is `cilium-cli` and _NOT_ `cilium`. |
| 48 | +
|
| 49 | +### The `evict` plugin for `kubectl` |
| 50 | + |
| 51 | +```shell |
| 52 | +go install github.com/ueokande/kubectl-evict@latest |
| 53 | +``` |
| 54 | + |
| 55 | +## Prepare |
| 56 | + |
| 57 | +These steps can be performed without any disruption to the target cluster. |
| 58 | + |
| 59 | +- Prepare environment variables: |
| 60 | + |
| 61 | + ```bash |
| 62 | + export TARGET_CLUSTER="<sc|wc>" |
| 63 | + export CK8S_CONFIG_PATH="/path/to/cluster/config" |
| 64 | + export KUBECONFIG="${CK8S_CONFIG_PATH}/.state/kube_config_${TARGET_CLUSTER}.yaml" |
| 65 | + ``` |
| 66 | + |
| 67 | +- This guide includes a complete Kubespray run for the target cluster. For OpenStack clusters, credentials must be sourced: |
| 68 | + |
| 69 | + ```bash |
| 70 | + test -f ${CK8S_CONFIG_PATH}/openrc.sh && source ${CK8S_CONFIG_PATH}/openrc.sh |
| 71 | + test -f ${CK8S_CONFIG_PATH}/secret/openstack-app-credentials-for-kubespray.sh && source <(sops -d ${CK8S_CONFIG_PATH}/secret/openstack-app-credentials-for-kubespray.sh) |
| 72 | + ``` |
| 73 | + |
| 74 | +- Ensure that the checked out tag or commit in your Kubespray repository matches the version in the cluster: |
| 75 | + |
| 76 | + ```bash |
| 77 | + KUBESPRAY_REF="$(yq '.ck8sKubesprayVersion' ${CK8S_CONFIG_PATH}/${TARGET_CLUSTER}-config/group_vars/all/ck8s-kubespray-general.yaml)" |
| 78 | + git switch --detach "${KUBESPRAY_REF}" |
| 79 | + |
| 80 | + # update the kubespray submodule if needed |
| 81 | + git submodule sync |
| 82 | + git submodule update --init --recursive |
| 83 | + ``` |
| 84 | + |
| 85 | +- Switch `kube_owner` to `root` and apply the changes: |
| 86 | + |
| 87 | + ```bash |
| 88 | + yq -i '.kube_owner = "root"' "${CK8S_CONFIG_PATH}/${TARGET_CLUSTER}-config/group_vars/k8s_cluster/ck8s-k8s-cluster.yaml" |
| 89 | + ../../bin/ck8s-kubespray apply $TARGET_CLUSTER -b -e=ignore_assert_errors=true --skip-tags=multus |
| 90 | + ``` |
| 91 | + |
| 92 | +- Install Cilium using the values provided in the `cilium-chart-values` directory and wait for the `DaemonSet` rollout: |
| 93 | + |
| 94 | + ```bash |
| 95 | + cilium-cli install --version 1.17.5 -f cilium-chart-values/cilium-values.yaml -f cilium-chart-values/cilium-extra.yaml |
| 96 | + kubectl -n kube-system rollout status daemonset/cilium --watch |
| 97 | + ``` |
| 98 | + |
| 99 | +- Enable the [Per-node configuration](https://docs.cilium.io/en/v1.17/configuration/per-node-config/) feature: |
| 100 | + |
| 101 | + ```bash |
| 102 | + kubectl apply -f cilium-node-config/during-migration.yaml |
| 103 | + ``` |
| 104 | + |
| 105 | +## Execute |
| 106 | + |
| 107 | +These steps will cause disruption in the target cluster. |
| 108 | + |
| 109 | +### 1. Temporarily allow all traffic through Calico |
| 110 | + |
| 111 | +```bash |
| 112 | +kubectl apply -f policies/calico-allow-all.yaml |
| 113 | +``` |
| 114 | + |
| 115 | +### 2. Migrate worker nodes |
| 116 | + |
| 117 | +Get the list of worker nodes and migrate them one by one, passing the node name as argument to the `./20-migrate-node.sh` script. |
| 118 | + |
| 119 | +For example: |
| 120 | + |
| 121 | +```bash |
| 122 | +kubectl get nodes --no-headers -o custom-columns=":metadata.name" | |
| 123 | + grep -v 'control-plane' | |
| 124 | + xargs -rt -I{} --interactive ./20-migrate-node.sh {} |
| 125 | +``` |
| 126 | + |
| 127 | +> [!TIP] |
| 128 | +> To skip confirmation prompts for each node, remove the `--interactive` flag from `xargs`. |
| 129 | +
|
| 130 | +### 3. Migrate control plane nodes |
| 131 | + |
| 132 | +Get the list of control plane nodes and migrate them one by one, passing the node name as argument to the `./20-migrate-node.sh` script. |
| 133 | + |
| 134 | +For example: |
| 135 | + |
| 136 | +```bash |
| 137 | +kubectl get nodes --no-headers -o custom-columns=":metadata.name" | |
| 138 | + grep 'control-plane' | |
| 139 | + xargs -rt -I{} --interactive ./20-migrate-node.sh {} |
| 140 | +``` |
| 141 | + |
| 142 | +### 4. Switch the Kubespray configuration to Cilium |
| 143 | + |
| 144 | +```bash |
| 145 | +./80-switch-to-cilium.sh |
| 146 | +../../bin/ck8s-kubespray apply $TARGET_CLUSTER -b -e=ignore_assert_errors=true --tags="download,network" |
| 147 | +``` |
| 148 | + |
| 149 | +### 5. Cleanup |
| 150 | + |
| 151 | +- Remove the per-node Cilium configuration: |
| 152 | + |
| 153 | + ```bash |
| 154 | + kubectl -n kube-system delete ciliumnodeconfigs.cilium.io cilium-default |
| 155 | + ``` |
| 156 | + |
| 157 | +- Remove Calico remnants: |
| 158 | + |
| 159 | + ```bash |
| 160 | + ./90-cleanup-calico.sh |
| 161 | + ``` |
| 162 | + |
| 163 | +### 6. (Optional) Reconfigure Apps |
| 164 | + |
| 165 | +If Welkin Apps has been deployed in the environment, it will require a reconfiguration step: |
| 166 | + |
| 167 | +```bash |
| 168 | +export CK8S_APPS_REPOSITORY_PATH=/path/to/welkin-apps |
| 169 | + |
| 170 | +yq -i '.networkPlugin.type = "cilium"' "${CK8S_CONFIG_PATH}/common-config.yaml" |
| 171 | +yq -i '.networkPlugin.calico.calicoAccountant.enabled = false' "${CK8S_CONFIG_PATH}/common-config.yaml" |
| 172 | +yq -i '.networkPlugin.calico.calicoFelixMetrics.enabled = false' "${CK8S_CONFIG_PATH}/common-config.yaml" |
| 173 | + |
| 174 | +${CK8S_APPS_REPOSITORY_PATH}/bin/update-ips.bash both dry-run |
| 175 | +${CK8S_APPS_REPOSITORY_PATH}/bin/update-ips.bash both apply |
| 176 | + |
| 177 | +${CK8S_APPS_REPOSITORY_PATH}/bin/ck8s apply sc --concurrency=$(nproc) |
| 178 | +${CK8S_APPS_REPOSITORY_PATH}/bin/ck8s apply wc --concurrency=$(nproc) |
| 179 | +``` |
0 commit comments