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.
- package/.jsii +361 -225
- package/docs/java.md +115898 -10131
- package/docs/plus/volume.md +46 -0
- package/docs/python.md +124669 -11033
- package/docs/typescript.md +108486 -7854
- package/lib/api-resource.js +2 -2
- package/lib/base.js +2 -2
- package/lib/config-map.js +1 -1
- package/lib/container.js +6 -6
- package/lib/cron-job.js +1 -1
- package/lib/daemon-set.js +1 -1
- package/lib/deployment.js +3 -3
- package/lib/handler.js +1 -1
- package/lib/horizontal-pod-autoscaler.js +4 -4
- package/lib/imports/k8s.js +154 -154
- package/lib/ingress.js +2 -2
- package/lib/job.js +1 -1
- package/lib/namespace.js +2 -2
- package/lib/network-policy.js +3 -3
- package/lib/pod.d.ts +4 -4
- package/lib/pod.js +22 -18
- package/lib/probe.js +1 -1
- package/lib/pv.js +4 -4
- package/lib/pvc.js +1 -1
- package/lib/role-binding.js +4 -4
- package/lib/role.js +2 -2
- package/lib/secret.js +6 -6
- package/lib/service-account.js +1 -1
- package/lib/service.js +1 -1
- package/lib/stateful-set.d.ts +53 -16
- package/lib/stateful-set.js +78 -8
- package/lib/volume.d.ts +6 -2
- package/lib/volume.js +9 -3
- package/lib/workload.js +2 -2
- package/package.json +8 -9
package/docs/plus/volume.md
CHANGED
|
@@ -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.
|