|
| 1 | +# Kustomization Quickstart |
| 2 | + |
| 3 | +This is a quickstart so you can test how this migration tool works. |
| 4 | + |
| 5 | +# Setup Flux |
| 6 | + |
| 7 | +If you already have Flux running, you can skip ahead. If not, you'll need to install/bootstrap Flux on to your Kubernetes cluster. |
| 8 | + |
| 9 | +You'll need |
| 10 | + |
| 11 | +* [Flux CLI](https://github.com/fluxcd/flux2/releases) |
| 12 | +* A GitHub token |
| 13 | +* Kubernetes Cluster |
| 14 | + |
| 15 | +Easiest way to test is with a [KIND cluster](https://github.com/kubernetes-sigs/kind) |
| 16 | + |
| 17 | +```shell |
| 18 | +kind create cluster |
| 19 | +``` |
| 20 | + |
| 21 | +## Bootstrapping |
| 22 | + |
| 23 | +The easiest way to get Flux up and running is to use the CLI to bootstrap. Best to use the [official documentation](https://fluxcd.io/docs/get-started/). But in Short: |
| 24 | + |
| 25 | +Export your GitHub Token |
| 26 | + |
| 27 | +```shell |
| 28 | +export GITHUB_TOKEN=123abc456def789 |
| 29 | +``` |
| 30 | + |
| 31 | +Install/Configure Flux on the cluster |
| 32 | + |
| 33 | +> *NOTE* replace the username with your GitHub username |
| 34 | +
|
| 35 | +```shell |
| 36 | +flux bootstrap github --owner christianh814 --private --personal --repository flux-demo |
| 37 | +``` |
| 38 | + |
| 39 | +## Add Applications |
| 40 | + |
| 41 | +To test the migration, add some applications. |
| 42 | + |
| 43 | +First, clone the repo from GitHub and `cd` into that repo's directory. |
| 44 | + |
| 45 | +> *NOTE* Again, replace the username with your GitHub username |
| 46 | +
|
| 47 | +```shell |
| 48 | +git clone git@github.com:christianh814/flux-demo.git |
| 49 | +cd flux-demo |
| 50 | +``` |
| 51 | + |
| 52 | +Add some applications (you can probably copy/paste this) |
| 53 | + |
| 54 | +```shell |
| 55 | +mkdir welcome-php |
| 56 | +cd welcome-php |
| 57 | +kubectl create ns welcome-php --dry-run=client -o yaml > welcome-php-ns.yaml |
| 58 | +kubectl create deployment welcome-php -n welcome-php --image=quay.io/redhatworkshops/welcome-php:latest --dry-run=client -o yaml > welcome-php-deployment.yaml |
| 59 | +kubectl create service clusterip welcome-php -n welcome-php --tcp=8080:8080 -o yaml --dry-run=client > welcome-php-service.yaml |
| 60 | +kustomize create --autodetect --recursive --namespace welcome-php |
| 61 | + |
| 62 | +cd ../ |
| 63 | + |
| 64 | +mkdir bgd |
| 65 | +cd bgd |
| 66 | +kubectl create deployment --image=quay.io/redhatworkshops/bgd:latest bgd -n bgd --dry-run=client -o yaml > bgd-deployment.yaml |
| 67 | +kubectl create service clusterip bgd -n bgd --tcp=8080:8080 -o yaml --dry-run=client > bgd-service.yaml |
| 68 | +kubectl create ns bgd --dry-run=client -o yaml > bgd-namespace.yaml |
| 69 | +kustomize create --autodetect --recursive --namespace bgd |
| 70 | + |
| 71 | +cd ../ |
| 72 | +``` |
| 73 | + |
| 74 | +You should have 3 directories. Two with the apps you've just created and one for the flux system. |
| 75 | + |
| 76 | +```shell |
| 77 | +$ tree -d . |
| 78 | +. |
| 79 | +├── bgd |
| 80 | +├── flux-system |
| 81 | +└── welcome-php |
| 82 | +``` |
| 83 | + |
| 84 | +Commit and push |
| 85 | + |
| 86 | +```shell |
| 87 | +git add . |
| 88 | +git commit -am "added test applications" |
| 89 | +git push |
| 90 | +``` |
| 91 | + |
| 92 | +Reconcile the changes |
| 93 | + |
| 94 | +```shell |
| 95 | +flux reconcile source git flux-system |
| 96 | +``` |
| 97 | + |
| 98 | +# Migrate |
| 99 | + |
| 100 | +Migration happens via an ApplicationSet. To see what will be created, just run the migration tool. |
| 101 | + |
| 102 | +> *NOTE* If youre Kustomizations are in a different namespace or named differnt, use `--namespace` and `--name` respectively. |
| 103 | +
|
| 104 | +```shell |
| 105 | +mta kustomization |
| 106 | +``` |
| 107 | + |
| 108 | +You can redirect this to a file or pipe it directly into `kubectl apply`. |
| 109 | + |
| 110 | +First make sure Argo CD is installed |
| 111 | + |
| 112 | +```shell |
| 113 | +kubectl create namespace argocd |
| 114 | +kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml |
| 115 | +``` |
| 116 | + |
| 117 | +Then pipe it into `kubectl apply` |
| 118 | + |
| 119 | +```shell |
| 120 | +mta kustomization | kubectl apply -n argocd -f - |
| 121 | +``` |
| 122 | + |
| 123 | +This should create an ApplicationSet with two Applications (discarding the `flux-system` directory) |
| 124 | + |
| 125 | +```shell |
| 126 | +$ kubectl get appsets,apps -n argocd |
| 127 | +NAME AGE |
| 128 | +applicationset.argoproj.io/mta-migration 53s |
| 129 | + |
| 130 | +NAME SYNC STATUS HEALTH STATUS |
| 131 | +application.argoproj.io/bgd Synced Healthy |
| 132 | +application.argoproj.io/welcome-php Synced Healthy |
| 133 | +``` |
| 134 | + |
| 135 | +Now suspend reconciliation on Flux |
| 136 | + |
| 137 | +```shell |
| 138 | +flux suspend kustomization --namespace flux-system flux-system |
| 139 | +``` |
| 140 | + |
| 141 | +Once suspended, you can safely delete the Kustomization |
| 142 | + |
| 143 | +```shell |
| 144 | +flux delete kustomization flux-system -s |
| 145 | +``` |
| 146 | + |
| 147 | +It is now safe to delete Flux |
| 148 | + |
| 149 | +```shell |
| 150 | +flux uninstall -s |
| 151 | +``` |
| 152 | + |
| 153 | +The applications should still be running |
| 154 | + |
| 155 | +```shell |
| 156 | +kubectl get pods,svc,deploy -A | egrep 'bgd|welcome-php' |
| 157 | +``` |
0 commit comments