|
| 1 | +## Here be dragons! |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | +### Moving from one cluster to another! |
| 6 | + |
| 7 | +Because all of our code and configuration is in git, we can easily move our whole continuous delivery stack to another OpenShift cluster. This is useful if you wanted to try out all the exercises at a later stage using the code from this run. |
| 8 | + |
| 9 | +As a prerequisite - you will need to have setup TL500 using the previous section [Tooling Installation](99-the-rise-of-the-cluster/1-tooling-installation). Lets cover the steps once you have a cluster and tooling installed to get going with your code. |
| 10 | + |
| 11 | +Lets take our code from `cluster-a` to `cluster-b`. |
| 12 | + |
| 13 | +#### Guided Steps |
| 14 | + |
| 15 | +> Here are the short series of steps to make this work. |
| 16 | +
|
| 17 | +1. You will need to git clone the `tech-exercise`, `pet-battle`, `pet-battle-api` repositories to your laptop for safe-keeping after taking this course. |
| 18 | + |
| 19 | +2. Use `vscode` IDE or similar to replace all the occurrances of `apps.cluster-a.com -> apps.cluster-b.com` in the code. |
| 20 | + |
| 21 | +3. Login to `gitlab` and create your ${TEAM_NAME} |
| 22 | + |
| 23 | +4. Let's push our code into the hosted `gitlab` instance in our new cluster: |
| 24 | + |
| 25 | + ```bash |
| 26 | + export GIT_SERVER=gitlab-ce.apps.cluster-b.com |
| 27 | + export TEAM_NAME=ateam |
| 28 | + ``` |
| 29 | + |
| 30 | + I'm assuming the code is in this folder locally on my laptop, adjust to suit. For each of the repos: |
| 31 | +
|
| 32 | + `Pet-Battle` |
| 33 | +
|
| 34 | + ```bash |
| 35 | + cd ~/git/tl500/pet-battle |
| 36 | + git remote set-url origin https://${GIT_SERVER}/${TEAM_NAME}/pet-battle.git |
| 37 | + git push -u origin main |
| 38 | + ``` |
| 39 | +
|
| 40 | + `Pet-Battle-API` |
| 41 | +
|
| 42 | + ```bash |
| 43 | + cd ~/git/tl500/pet-battle-api |
| 44 | + git remote set-url origin https://${GIT_SERVER}/${TEAM_NAME}/pet-battle-api.git |
| 45 | + git push -u origin main |
| 46 | + ``` |
| 47 | +
|
| 48 | + `Tech-Exercise` |
| 49 | +
|
| 50 | + ```bash |
| 51 | + cd ~/git/tl500/tech-exercise |
| 52 | + git remote set-url origin https://${GIT_SERVER}/${TEAM_NAME}/tech-exercise.git |
| 53 | + git push -u origin main |
| 54 | + ``` |
| 55 | +
|
| 56 | +5. Login to `gitlab` and make sure your newly created projects are set to **public** (they will be private by default). |
| 57 | +
|
| 58 | +6. Regenerate the `sealed-secrets` for this new cluster. This assumes we did _not_ migrate the secret master key to the new cluster when setting up (obviously skip this step if you did migrate it!). |
| 59 | +
|
| 60 | + Set `git-auth` |
| 61 | +
|
| 62 | + ```bash |
| 63 | + export GITLAB_USER=<user> |
| 64 | + export GITLAB_PASSWORD=<password> |
| 65 | +
|
| 66 | + cat << EOF > /tmp/git-auth.yaml |
| 67 | + kind: Secret |
| 68 | + apiVersion: v1 |
| 69 | + data: |
| 70 | + username: "$(echo -n ${GITLAB_USER} | base64 -w0)" |
| 71 | + password: "$(echo -n ${GITLAB_PASSWORD} | base64 -w0)" |
| 72 | + metadata: |
| 73 | + annotations: |
| 74 | + tekton.dev/git-0: https://${GIT_SERVER} |
| 75 | + labels: |
| 76 | + credential.sync.jenkins.openshift.io: "true" |
| 77 | + name: git-auth |
| 78 | + EOF |
| 79 | +
|
| 80 | + kubeseal < /tmp/git-auth.yaml > /tmp/sealed-git-auth.yaml \ |
| 81 | + -n ${TEAM_NAME}-ci-cd \ |
| 82 | + --controller-namespace tl500-shared \ |
| 83 | + --controller-name sealed-secrets \ |
| 84 | + -o yaml |
| 85 | + ``` |
| 86 | +
|
| 87 | + Set `sonarqube-auth` |
| 88 | +
|
| 89 | + ```bash |
| 90 | + cat << EOF > /tmp/sonarqube-auth.yaml |
| 91 | + apiVersion: v1 |
| 92 | + data: |
| 93 | + username: "$(echo -n admin | base64 -w0)" |
| 94 | + password: "$(echo -n admin123 | base64 -w0)" |
| 95 | + currentAdminPassword: "$(echo -n admin | base64 -w0)" |
| 96 | + kind: Secret |
| 97 | + metadata: |
| 98 | + labels: |
| 99 | + credential.sync.jenkins.openshift.io: "true" |
| 100 | + name: sonarqube-auth |
| 101 | + EOF |
| 102 | +
|
| 103 | + kubeseal < /tmp/sonarqube-auth.yaml > /tmp/sealed-sonarqube-auth.yaml \ |
| 104 | + -n ${TEAM_NAME}-ci-cd \ |
| 105 | + --controller-namespace tl500-shared \ |
| 106 | + --controller-name sealed-secrets \ |
| 107 | + -o yaml |
| 108 | +
|
| 109 | + cat /tmp/sealed-sonarqube-auth.yaml| grep -E 'username|password|currentAdminPassword' |
| 110 | + ``` |
| 111 | +
|
| 112 | + Set `allure-auth` |
| 113 | +
|
| 114 | + ```bash |
| 115 | + cat << EOF > /tmp/allure-auth.yaml |
| 116 | + apiVersion: v1 |
| 117 | + data: |
| 118 | + password: "$(echo -n password | base64 -w0)" |
| 119 | + username: "$(echo -n admin | base64 -w0)" |
| 120 | + kind: Secret |
| 121 | + metadata: |
| 122 | + name: allure-auth |
| 123 | + EOF |
| 124 | +
|
| 125 | + kubeseal < /tmp/allure-auth.yaml > /tmp/sealed-allure-auth.yaml \ |
| 126 | + -n ${TEAM_NAME}-ci-cd \ |
| 127 | + --controller-namespace tl500-shared \ |
| 128 | + --controller-name sealed-secrets \ |
| 129 | + -o yaml |
| 130 | +
|
| 131 | + cat /tmp/sealed-allure-auth.yaml| grep -E 'username|password' |
| 132 | + ``` |
| 133 | +
|
| 134 | + Set `rox-auth` |
| 135 | +
|
| 136 | + ```bash |
| 137 | + export ROX_API_TOKEN=$(oc -n stackrox get secret rox-api-token-tl500 -o go-template='{{index .data "token" | base64decode}}') |
| 138 | + export ROX_ENDPOINT=central-stackrox.apps.cluster-b.com |
| 139 | +
|
| 140 | + cat << EOF > /tmp/rox-auth.yaml |
| 141 | + apiVersion: v1 |
| 142 | + data: |
| 143 | + password: "$(echo -n ${ROX_API_TOKEN} | base64 -w0)" |
| 144 | + username: "$(echo -n ${ROX_ENDPOINT} | base64 -w0)" |
| 145 | + kind: Secret |
| 146 | + metadata: |
| 147 | + labels: |
| 148 | + credential.sync.jenkins.openshift.io: "true" |
| 149 | + name: rox-auth |
| 150 | + EOF |
| 151 | +
|
| 152 | + kubeseal < /tmp/rox-auth.yaml > /tmp/sealed-rox-auth.yaml \ |
| 153 | + -n ${TEAM_NAME}-ci-cd \ |
| 154 | + --controller-namespace tl500-shared \ |
| 155 | + --controller-name sealed-secrets \ |
| 156 | + -o yaml |
| 157 | +
|
| 158 | + cat /tmp/sealed-rox-auth.yaml | grep -E 'username|password' |
| 159 | + ``` |
| 160 | +
|
| 161 | +7. Run the basics |
| 162 | +
|
| 163 | + ```bash |
| 164 | + export TEAM_NAME="ateam" |
| 165 | + export CLUSTER_DOMAIN="apps.cluster-b.com" |
| 166 | + export GIT_SERVER="gitlab-ce.apps.cluster-b.com" |
| 167 | +
|
| 168 | + oc login --server=https://api.${CLUSTER_DOMAIN##apps.}:6443 -u mike |
| 169 | + ``` |
| 170 | +
|
| 171 | +8. Install ArgoCD |
| 172 | +
|
| 173 | + Add our namespace to the operator env.var: |
| 174 | +
|
| 175 | + ```bash |
| 176 | + run() |
| 177 | + { |
| 178 | + NS=$(oc get subscription/openshift-gitops-operator -n openshift-operators \ |
| 179 | + -o jsonpath='{.spec.config.env[?(@.name=="ARGOCD_CLUSTER_CONFIG_NAMESPACES")].value}') |
| 180 | + if [ -z $NS ]; then |
| 181 | + NS="${TEAM_NAME}-ci-cd" |
| 182 | + elif [[ "$NS" =~ .*"${TEAM_NAME}-ci-cd".* ]]; then |
| 183 | + echo "${TEAM_NAME}-ci-cd already added." |
| 184 | + return |
| 185 | + else |
| 186 | + NS="${TEAM_NAME}-ci-cd,${NS}" |
| 187 | + fi |
| 188 | + oc -n openshift-operators patch subscription/openshift-gitops-operator --type=json \ |
| 189 | + -p '[{"op":"replace","path":"/spec/config/env/1","value":{"name": "ARGOCD_CLUSTER_CONFIG_NAMESPACES", "value":"'${NS}'"}}]' |
| 190 | + echo "EnvVar set to: $(oc get subscription/openshift-gitops-operator -n openshift-operators \ |
| 191 | + -o jsonpath='{.spec.config.env[?(@.name=="ARGOCD_CLUSTER_CONFIG_NAMESPACES")].value}')" |
| 192 | + } |
| 193 | + run |
| 194 | + ``` |
| 195 | +
|
| 196 | + Deploy helm chart |
| 197 | +
|
| 198 | + ```bash |
| 199 | + oc new-project ${TEAM_NAME}-ci-cd |
| 200 | + helm repo add redhat-cop https://redhat-cop.github.io/helm-charts |
| 201 | +
|
| 202 | + helm upgrade --install argocd \ |
| 203 | + --namespace ${TEAM_NAME}-ci-cd \ |
| 204 | + -f tech-exercises/argocd-values.yaml \ |
| 205 | + redhat-cop/gitops-operator |
| 206 | + ``` |
| 207 | +
|
| 208 | +9. Install UJ |
| 209 | +
|
| 210 | + ```bash |
| 211 | + cd tech-exercises |
| 212 | + helm upgrade --install uj --namespace ${TEAM_NAME}-ci-cd . |
| 213 | + ``` |
| 214 | +
|
| 215 | +10. Add the integrations and web hooks to gitlab for `tech-exercise`, `pet-battle`, `pet-battle-api` git repos |
| 216 | +
|
| 217 | +11. Kick off builds, make sure they work, fix up and helm chart version mismatches etc. |
| 218 | +
|
| 219 | +12. 🎉🎉🎉 Celebrate a successful migration to a new cluster 🎉🎉🎉 |
0 commit comments