Difference between revisions of "Pv-migrate"
Jump to navigation
Jump to search
(Created page with "# pv-migrate https://github.com/utkuozdemir/pv-migrate https://github.com/utkuozdemir/pv-migrate/blob/master/USAGE.md # Add ``` #!/bin/sh set -eu curl -LO https://github.co...") |
|||
(4 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
# pv-migrate | # pv-migrate | ||
+ | |||
+ | https://devopstales.github.io/home/k8s-migrate-pv/ | ||
https://github.com/utkuozdemir/pv-migrate | https://github.com/utkuozdemir/pv-migrate | ||
Line 13: | Line 15: | ||
sudo mv pv-migrate /usr/local/bin/ | sudo mv pv-migrate /usr/local/bin/ | ||
pv-migrate --version | pv-migrate --version | ||
+ | ``` | ||
+ | |||
+ | |||
+ | # Backup to ceph-rbd | ||
+ | |||
+ | wordpress.tmp.pvc.yaml | ||
+ | ``` | ||
+ | --- | ||
+ | apiVersion: v1 | ||
+ | kind: PersistentVolumeClaim | ||
+ | metadata: | ||
+ | name: data-wordpress-mariadb-0-a | ||
+ | spec: | ||
+ | accessModes: | ||
+ | - ReadWriteOnce | ||
+ | storageClassName: ceph-rbd | ||
+ | resources: | ||
+ | requests: | ||
+ | storage: 8Gi | ||
+ | --- | ||
+ | apiVersion: v1 | ||
+ | kind: PersistentVolumeClaim | ||
+ | metadata: | ||
+ | name: wordpress-a | ||
+ | spec: | ||
+ | accessModes: | ||
+ | - ReadWriteOnce | ||
+ | storageClassName: ceph-rbd | ||
+ | resources: | ||
+ | requests: | ||
+ | storage: 10Gi | ||
+ | ``` | ||
+ | |||
+ | ``` | ||
+ | kubectl apply -f wordpress.tmp.pvc.yaml | ||
+ | ``` | ||
+ | |||
+ | ## Migrate to temporary backup pvcs | ||
+ | |||
+ | ``` | ||
+ | kubectl scale deployment wordpress --replicas=0 | ||
+ | kubectl scale statefulset wordpress-mariadb --replicas=0 | ||
+ | |||
+ | sleep 5 | ||
+ | |||
+ | pv-migrate migrate \ | ||
+ | data-wordpress-mariadb-0 data-wordpress-mariadb-0-a | ||
+ | |||
+ | pv-migrate migrate \ | ||
+ | wordpress wordpress-a | ||
+ | ``` | ||
+ | |||
+ | Scale | ||
+ | ``` | ||
+ | #!/bin/bash | ||
+ | set -eu | ||
+ | kubectl scale deployment wordpress --replicas=0 | ||
+ | kubectl scale statefulset wordpress-mariadb --replicas=0 | ||
+ | |||
+ | sleep 5 | ||
+ | pv-migrate migrate \ | ||
+ | data-wordpress-mariadb-0-a data-wordpress-mariadb-0 | ||
+ | |||
+ | pv-migrate migrate \ | ||
+ | wordpress-a wordpress | ||
+ | |||
+ | kubectl scale deployment wordpress --replicas=1 | ||
+ | kubectl scale statefulset wordpress-mariadb --replicas=1 | ||
+ | |||
+ | exit | ||
+ | ``` | ||
+ | |||
+ | |||
+ | # Example helm wordpress | ||
+ | |||
+ | cm.yaml | ||
+ | ``` | ||
+ | apiVersion: v1 | ||
+ | kind: ConfigMap | ||
+ | metadata: | ||
+ | name: php-ini | ||
+ | labels: | ||
+ | app.kubernetes.io/name: wordpress | ||
+ | data: | ||
+ | php-custom.ini: | | ||
+ | upload_max_filesize = 2256M | ||
+ | post_max_size = 2256M | ||
+ | max_execution_time = 360 | ||
+ | max_input_time = 360 | ||
+ | memory_limit = 2512M | ||
+ | ``` | ||
+ | |||
+ | main.sh | ||
+ | ``` | ||
+ | #!/bin/bash | ||
+ | set -eu | ||
+ | |||
+ | kubectl_apply "-f cm.yaml" | ||
+ | helm upgrade --install wordpress bitnami/wordpress | ||
+ | # if custom values | ||
+ | # envsubst < values.yaml.envsubst > values.yaml | ||
+ | # helm upgrade --install wordpress bitnami/wordpress values.yaml | ||
+ | ``` | ||
+ | |||
+ | ## Run | ||
+ | ``` | ||
+ | ./main.sh | ||
``` | ``` |
Latest revision as of 20:25, 2 December 2023
pv-migrate
https://devopstales.github.io/home/k8s-migrate-pv/
https://github.com/utkuozdemir/pv-migrate
https://github.com/utkuozdemir/pv-migrate/blob/master/USAGE.md
Add
#!/bin/sh set -eu curl -LO https://github.com/utkuozdemir/pv-migrate/releases/download/v1.7.1/pv-migrate_v1.7.1_linux_x86_64.tar.gz tar xf pv-migrate_v1.7.1_linux_x86_64.tar.gz sudo mv pv-migrate /usr/local/bin/ pv-migrate --version
Backup to ceph-rbd
wordpress.tmp.pvc.yaml
--- apiVersion: v1 kind: PersistentVolumeClaim metadata: name: data-wordpress-mariadb-0-a spec: accessModes: - ReadWriteOnce storageClassName: ceph-rbd resources: requests: storage: 8Gi --- apiVersion: v1 kind: PersistentVolumeClaim metadata: name: wordpress-a spec: accessModes: - ReadWriteOnce storageClassName: ceph-rbd resources: requests: storage: 10Gi
kubectl apply -f wordpress.tmp.pvc.yaml
Migrate to temporary backup pvcs
kubectl scale deployment wordpress --replicas=0 kubectl scale statefulset wordpress-mariadb --replicas=0 sleep 5 pv-migrate migrate \ data-wordpress-mariadb-0 data-wordpress-mariadb-0-a pv-migrate migrate \ wordpress wordpress-a
Scale
#!/bin/bash set -eu kubectl scale deployment wordpress --replicas=0 kubectl scale statefulset wordpress-mariadb --replicas=0 sleep 5 pv-migrate migrate \ data-wordpress-mariadb-0-a data-wordpress-mariadb-0 pv-migrate migrate \ wordpress-a wordpress kubectl scale deployment wordpress --replicas=1 kubectl scale statefulset wordpress-mariadb --replicas=1 exit
Example helm wordpress
cm.yaml
apiVersion: v1 kind: ConfigMap metadata: name: php-ini labels: app.kubernetes.io/name: wordpress data: php-custom.ini: | upload_max_filesize = 2256M post_max_size = 2256M max_execution_time = 360 max_input_time = 360 memory_limit = 2512M
main.sh
#!/bin/bash set -eu kubectl_apply "-f cm.yaml" helm upgrade --install wordpress bitnami/wordpress # if custom values # envsubst < values.yaml.envsubst > values.yaml # helm upgrade --install wordpress bitnami/wordpress values.yaml
Run
./main.sh