|
| 1 | +# Migrate to Kubernetes |
| 2 | + |
| 3 | +In September / October 2021, codeforphilly.org was migrated from being hosted on a legacy Emergence VM (`poplar.phl.io`) at DigitalOcean to the `cfp-live-cluster` hosted at Linode. |
| 4 | + |
| 5 | +## Procedure |
| 6 | + |
| 7 | +1. Configure `KUBECONFIG` to access `cfp-live-cluster`: |
| 8 | + |
| 9 | + ```bash |
| 10 | + export KUBECONFIG=~/.kube/cfp-live-cluster-kubeconfig.yaml |
| 11 | + ``` |
| 12 | + |
| 13 | +2. Find production Pod and store name in shell variable: |
| 14 | + |
| 15 | + ```bash |
| 16 | + pod_name=$(kubectl -n code-for-philly get pod \ |
| 17 | + -l app.kubernetes.io/name=code-for-philly \ |
| 18 | + -l app.kubernetes.io/instance=code-for-philly \ |
| 19 | + --field-selector=status.phase==Running \ |
| 20 | + -o jsonpath='{.items[0].metadata.name}' |
| 21 | + ) |
| 22 | + ``` |
| 23 | + |
| 24 | +3. Get authenticated SQL dump url from <https://codeforphilly.org/site-admin> and store in a shell variable: |
| 25 | + |
| 26 | + ```bash |
| 27 | + sql_url='https://codeforphilly.org/site-admin/database/dump.sql?_session=abcdef1234567890' |
| 28 | + ``` |
| 29 | + |
| 30 | +4. Load database into Kubernetes host: |
| 31 | + |
| 32 | + ```bash |
| 33 | + kubectl -n code-for-philly exec "${pod_name}" -- \ |
| 34 | + hab pkg exec codeforphilly/site-composite \ |
| 35 | + bash -c \ |
| 36 | + "curl '${sql_url}' | mysql" |
| 37 | + ``` |
| 38 | + |
| 39 | +5. Install rsync and openssh into running Kubernetes host: |
| 40 | + |
| 41 | + ```bash |
| 42 | + kubectl -n code-for-philly exec "${pod_name}" -- \ |
| 43 | + hab pkg install --binlink --force core/rsync core/openssh |
| 44 | + ``` |
| 45 | + |
| 46 | +6. Copy SSH key into Kubernetes host that can connect to legacy VM: |
| 47 | + |
| 48 | + ```bash |
| 49 | + kubectl -n code-for-philly cp .scratch/id_rsa "${pod_name}:/root/" |
| 50 | + ``` |
| 51 | + |
| 52 | +7. User rsync to synchronize data files from legacy VM to Kubernetes host: |
| 53 | + |
| 54 | + ```bash |
| 55 | + kubectl -n code-for-philly exec "${pod_name}" -- \ |
| 56 | + rsync \ |
| 57 | + -e 'ssh -i /root/id_rsa -o "StrictHostKeyChecking no"' \ |
| 58 | + -av \ |
| 59 | + --chown hab:hab \ |
| 60 | + --exclude '*.log' \ |
| 61 | + --exclude 'git/' \ |
| 62 | + --exclude 'media/*x*/' \ |
| 63 | + '[email protected]:/emergence/sites/code-for-philly/site-data/' \ |
| 64 | + '/hab/svc/site/data/' |
| 65 | + ``` |
0 commit comments