Skip to content

Commit 654879a

Browse files
committed
feat(k8s): add tutorial for multi-az pvc migration
1 parent a7970fa commit 654879a

File tree

1 file changed

+186
-0
lines changed
  • tutorials/migrate-k8s-persistent-volumes-to-multi-az

1 file changed

+186
-0
lines changed
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
---
2+
meta:
3+
title: Migrating persistent volumes in a multi-zone Scaleway Kapsule cluster
4+
description: This tutorial provides information about how to migrate existing Persistent Volumes in a Scaleway Kapsule multi-zone cluster to enhance availability and fault tolerance.
5+
content:
6+
h1: Migrating persistent volumes in a multi-zone Scaleway Kapsul cluster
7+
paragraph: This tutorial provides information about how to migrate existing Persistent Volumes in a Scaleway Kapsule multi-zone cluster to enhance availability and fault tolerance.
8+
tags: kapsule elastic-metal migration persistent-volumes
9+
categories:
10+
- kubernetes
11+
dates:
12+
validation: 2025-01-30
13+
posted: 2025-01-30
14+
---
15+
16+
Historically, Scaleway Kapsule clusters were single-zone, meaning workloads and their associated storage were confined to a single location. With the introduction of multi-zone support, distributing workloads across multiple zones can enhance availability and fault tolerance.
17+
18+
This tutorial provides a generalized approach to migrating Persistent Volumes (PVs) from one zone to another in a Scaleway Kapsule multi-zone cluster, applicable to various applications.
19+
20+
<Macro id="requirements" />
21+
22+
- A Scaleway account logged into the [console](https://console.scaleway.com)
23+
- [Owner](/iam/concepts/#owner) status or [IAM permissions](/iam/concepts/#permission) allowing you to perform actions in the intended Organization
24+
- [Created a Kapsule cluster](/kubernetes/how-to/create-cluster/) with multi-zone support enabled
25+
- An existing `StatefulSet` using **Persistent Volumes** in a single-zone cluster.
26+
- [kubectl](/kubernetes/how-to/connect-cluster-kubectl/) installed and configured to interact with your Kubernetes cluster
27+
- [Scaleway CLI](/scaleway-cli/quickstart/) installed and configured
28+
- Familiarity with Kubernetes Persistent Volumes, `StatefulSets`, and Storage Classes.
29+
30+
<Message type="important">
31+
**Backing up your data is crucial before making any changes.**
32+
Ensure you have a backup strategy in place. You can use tools like Velero for Kubernetes backups or manually copy data to another storage solution. Always verify the integrity of your backups before proceeding.
33+
</Message>
34+
35+
## Identify existing Persistent Volumes
36+
37+
1. Use `kubectl` to interact with your cluster and list the Persistent Volumes in your cluster:
38+
```sh
39+
kubectl get pv
40+
```
41+
42+
2. Identify the volumes attached to your StatefulSet and note their `PersistentVolumeClaim` (PVC) names and `StorageClass`.
43+
Example output:
44+
```plaintext
45+
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS ZONE
46+
pvc-123abc 10Gi RWO Retain Bound default/my-app-pvc scw-bssd fr-par-1
47+
```
48+
To find the `VOLUME_ID`, correlate this with the scw command output:
49+
```
50+
scw instance volume list
51+
```
52+
53+
## Create snapshots of your existing Persistent Volumes
54+
55+
Use the Scaleway CLI to create snapshots of your volumes.
56+
57+
1. Retrieve the volume ID associated with the Persistent Volume:
58+
```sh
59+
scw instance volume list
60+
```
61+
62+
2. Create a snapshot for each volume:
63+
```sh
64+
scw instance snapshot create volume-id=<VOLUME_ID> name=my-app-snapshot
65+
```
66+
67+
3. Verify snapshot creation:
68+
```sh
69+
scw instance snapshot list
70+
```
71+
72+
## Create multi-zone Persistent Volumes
73+
74+
Once the snapshots are available, create new volumes in different zones:
75+
76+
```sh
77+
scw instance volume create name=my-app-volume-new size=10GB type=bssd snapshot-id=<SNAPSHOT_ID> zone=fr-par-2
78+
```
79+
80+
Repeat this for each zone required.
81+
82+
<Meessage type="tip">
83+
Choose zones based on your distribution strategy. Check Scaleway's [zone availability](/account/reference-content/products-availability/) for optimal placement.
84+
</Message>
85+
86+
## Update Persistent Volume Claims (PVCs)
87+
88+
<Message type="important">
89+
Deleting a PVC can lead to data loss if not managed correctly. Ensure your application is scaled down or data is backed up.
90+
</Message>
91+
92+
Modify your `PersistentVolumeClaims` to reference the newly created volumes.
93+
94+
1. Delete the existing PVC (PVCs are immutable and cannot be updated directly):
95+
```sh
96+
kubectl delete pvc my-app-pvc
97+
```
98+
99+
2. Create a new PVC with a multi-zone compatible `StorageClass`:
100+
```yaml
101+
apiVersion: v1
102+
kind: PersistentVolumeClaim
103+
metadata:
104+
name: my-app-pvc
105+
spec:
106+
accessModes:
107+
- ReadWriteOnce
108+
storageClassName: "scw-bssd-multi-zone"
109+
resources:
110+
requests:
111+
storage: 10Gi
112+
```
113+
114+
3. Apply the updated PVCs:
115+
```sh
116+
kubectl apply -f my-app-pvc.yaml
117+
```
118+
119+
## Reconfigure the StatefulSet to use multi-zone volumes
120+
121+
1. Edit the `StatefulSet` definition to use the newly created Persistent Volume Claims.
122+
Example `StatefulSet` configuration:
123+
124+
```yaml
125+
apiVersion: apps/v1
126+
kind: StatefulSet
127+
metadata:
128+
name: my-app
129+
spec:
130+
volumeClaimTemplates:
131+
- metadata:
132+
name: my-app-pvc
133+
spec:
134+
storageClassName: "scw-bssd-multi-zone"
135+
accessModes:
136+
- ReadWriteOnce
137+
resources:
138+
requests:
139+
storage: 10Gi
140+
```
141+
142+
2. Apply the `StatefulSet` changes:
143+
```sh
144+
kubectl apply -f my-app-statefulset.yaml
145+
```
146+
147+
## Verify migration
148+
149+
1. Check that the `StatefulSet` pods are running in multiple zones:
150+
```sh
151+
kubectl get pods -o wide
152+
```
153+
154+
2. Ensure that the new Persistent Volumes are bound and correctly distributed across the zones:
155+
```sh
156+
kubectl get pv
157+
```
158+
159+
## Considerations for volume expansion
160+
161+
If you need to **resize the Persistent Volume**, ensure that the `StorageClass` supports volume expansion.
162+
163+
1. Check if the feature is enabled:
164+
```sh
165+
kubectl get storageclass scw-bssd-multi-zone -o yaml | grep allowVolumeExpansion
166+
```
167+
168+
2. If `allowVolumeExpansion: true` is present, you can modify your PVC:
169+
```yaml
170+
spec:
171+
resources:
172+
requests:
173+
storage: 20Gi
174+
```
175+
176+
3. Then apply the change:
177+
```sh
178+
kubectl apply -f my-app-pvc.yaml
179+
```
180+
181+
## Conclusion
182+
183+
You have successfully migrated your Persistent Volumes to a multi-zone Kapsule setup. Your `StatefulSet` is now distributed across multiple zones, improving resilience and availability.
184+
185+
For further optimization, consider implementing [Pod anti-affinity](https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#affinity-and-anti-affinity) rules to ensure an even distribution of workloads across zones.
186+

0 commit comments

Comments
 (0)