cdk8s-plus-31 2.5.13 → 2.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -36,3 +36,49 @@ const redis = pod.addContainer({
36
36
  // mount to the redis container.
37
37
  redis.mount('/var/lib/redis', data);
38
38
  ```
39
+
40
+ ## Using PersistentVolumeClaim Templates with StatefulSets
41
+
42
+ When working with StatefulSets, you can use PersistentVolumeClaim templates to create stable storage for each pod in the StatefulSet. This allows each pod to have its own storage that persists even if the pod is rescheduled to a different node.
43
+
44
+ ```typescript
45
+ import * as kplus from 'cdk8s-plus-32';
46
+ import { Size } from 'cdk8s';
47
+
48
+ const dataVolume = Volume.fromName(chart, "pvc-template-data", "data-volume")
49
+
50
+ // Create a StatefulSet with a PVC template
51
+ const statefulSet = new kplus.StatefulSet(this, 'StatefulSet', {
52
+ containers: [{
53
+ image: 'nginx',
54
+ volumeMounts: [{
55
+ volume: dataVolume,
56
+ path: '/data',
57
+ }, {
58
+ volume: Volume.fromName(chart, "pvc-template-temp", "temp-volume"),
59
+ path: '/data',
60
+ }],
61
+ }],
62
+ // Define PVC templates during initialization
63
+ volumeClaimTemplates: [{
64
+ name: dataVolume.name,
65
+ storage: Size.gibibytes(10),
66
+ accessModes: [kplus.PersistentVolumeAccessMode.READ_WRITE_ONCE],
67
+ storageClassName: 'standard', // Optional: Specify the storage class
68
+ }, {
69
+ name: 'temp-volume', // Must match a volume mount name in a container
70
+ storage: Size.gibibytes(10),
71
+ accessModes: [kplus.PersistentVolumeAccessMode.READ_WRITE_ONCE],
72
+ storageClassName: 'standard', // Optional: Specify the storage class
73
+ }],
74
+ });
75
+
76
+ // Or add PVC templates after creation
77
+ statefulSet.addVolumeClaimTemplate({
78
+ name: 'logs-volume',
79
+ storage: Size.gibibytes(5),
80
+ accessModes: [kplus.PersistentVolumeAccessMode.READ_WRITE_ONCE],
81
+ });
82
+ ```
83
+
84
+ Each pod in the StatefulSet will get its own PVC instance based on these templates, with names like `data-volume-my-statefulset-0`, `data-volume-my-statefulset-1`, etc.