Correct way for adding ceph storage class to kubernetes?

Hi!

Is there an easier way (or maybe a correct way) for creating a storage class via juju inside Kubernetes?

Currently we create a pool via:
juju run-action ceph-mon/0 create-pool name=test-pool replicas=3 --wait

and add manually a yaml for the storage class:
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: ceph-test
selfLink: “/apis/storage.k8s.io/v1/storageclasses/ceph-test”
labels:
cdk-addons: ‘true’

Is there a better way?

I had the reply below typed out and then on reading your post again, I realise you are probably asking about adding storage to a Charmed Kubernetes deployment? If so, @tvansteenburgh or one of the CK people can help there.

But I’ll leave my reply as well in case it’s useful to someone. I guess you could avoid creating the storage class YAML if you are using Juju to deploy k8s workloads to your CK.

You can create a storage pool in the Juju model with the relevant k8s storage provisioning parameters and Juju will set that up when you deploy a charm and specify storage. There some information here.

In summary, create a Juju storage pool

juju create-storage-pool <pool name> kubernetes \
     storage-class=<storage class name> storage-provisioner=<provisioner> \
     parameters.type=<paramters>

eg to create a storage pool for GCE persistent disks

juju create-storage-pool my-storage kubernetes \
    storage-class=juju-storage \
    storage-provisioner=kubernetes.io/gce-pd \
    parameters.type=pd-standard

(you don’t need to do this in practice as Juju will do it automatically on k8s backed by GCE, it’s just an example).

Then when you deploy your charm:

juju deploy some-charm --storage database=my-storage,1G

Thank you! I’ll give it a try.

Yes it is a CDK with Ceph storage in a vsphere cloud.

Hi @panda,

You’re doing it the right way. If you use one of the default pools that are created by the master charm when it’s related to Ceph, the k8s StorageClass is created for you. But if you create your own pool, you must also create the StorageClass.

I’ve filed https://github.com/charmed-kubernetes/kubernetes-docs/issues/355 to make this more clear in our docs.

Also note that you can use the apply-manifest action on kubernetes-worker to apply the yaml, rather than using kubectl directly. Not required but can be useful is some situations.

1 Like