cdk8s-team / cdk8s-plus

A software development framework that provides high level abstractions for authoring Kubernetes applications.
https://cdk8s.io/docs/latest/plus/
Apache License 2.0
133 stars 33 forks source link

Support PersistentVolumeClaimTemplate in STS #2249

Open gkaskonas opened 1 year ago

gkaskonas commented 1 year ago

Description of the feature or enhancement:

STS supports PVC templates and cdk8s should do

Use Case:

To deploy multiple pods with storage

Proposed Solution:

Update StatefulSetProps to allow PVC template

Other:


This is a :rocket: Feature Request

iliapolo commented 3 months ago

@gkaskonas A StatefulSet, like any workload resource, has access to its containers via sts.containers, and then the container has support for PVC via container.mount.

import * as kplus from 'cdk8s-plus-29';
import * as cdk8s from 'cdk8s';

const sts = new kplus.StatefulSet(chart, 'StatefulSet', { ... });
const container = sts.addContainer({ image: 'node' });

// create the storage request
const claim = new kplus.PersistentVolumeClaim(chart, 'Claim', {
  storage: cdk8s.Size.gibibytes(50),
});

// mount a volume based on the request to the container
// this will also add the volume itself to the pod spec.
container.mount('/data', kplus.Volume.fromPersistentVolumeClaim(claim));

Is that not sufficient? Or are you looking for more direct support via its properties?

rassie commented 2 months ago

@iliapolo That's not how StatefulSets are supposed to work. With STS you get a PVC per pod, so you'd give it a PVC template to manage and it will automatically assign and track storage identities for the pods. You can still assign volumes to pods, but it'll be a shared volume between all of the pods.

gkaskonas commented 2 months ago

What @rassie said. I want the template to be exposed. This means that your Statefulset construct is not in sync with Statefulset API

iliapolo commented 1 month ago

@rassie @gkaskonas thanks, I see now that we are indeed missing this feature.