Writing a Kubernetes charm

Hi, I’m trying to set a persistent volume in my charm for a k8s app. I’m having trouble setting the capacity of the volume requested. In my metadata.yml, I’ve put:

storage: 
    database:
        type: filesystem
        location: /var/opt/mydatabaseapp
        capacity: 8Gi

However the persistent volume is created with 1Gi only. Do you have an example of the right syntax to use?

Edit : found it :slight_smile: it needs to be minimum-size: 8G and not capacity!

1 Like

There is no “capacity” attribute for storage, but there is a “minimum-size”

storage: 
    database:
        type: filesystem
        location: /var/opt/mydatabaseapp
        minimum-size: 8Gi

At deploy time, the user can then (or is expected to in production scenarios) specify the actual storage configuration to be used, eg

$ juju deploy foo --storage database=100G

The default storage provisioned on k8s is a PV but you can also choose to use k8s emptyDir backed by either memory or disk for prototyping or testing etc, eg

$ juju deploy foo --storage database=tmpfs,1G

or

$ juju deploy foo --storage database=rootfs,1G

The above tmpfs and rootfs storage types map to generic Juju storage concepts applicable to any type of deployment, k8s or cloud.

See https://discourse.jujucharms.com/t/persistent-storage-and-kubernetes/1078 for more info.

Admitting some ignorance here, but one thing that has got me stuck a few times is figuring out how to tell Juju about which Docker image I want attached as a resource to local charms during development.

If I run docker pull redis, what commands do I need to execute to convert that image into a resource accepted by the deploy command?

Is it necessary to use juju attach-storage for local charms, e.g.:

  • docker pull redis:5
  • juju deploy /path/to/local/redis-charm-k8s
  • juju attach-resource oci-image=redis

Here’s a tutorial which explains what to do.

See the “Local Charms” section. TL;DR: docker image metadata is modelled as Charm Resources. So the standard --resource semantics are used. eg

juju deploy /path/to/mariadb-k8s-local --resource mysql_image=mariadb:latest
2 Likes

@wallyworld is this true now that operator framework is out?

@wallyworld is this true now that operator framework is out?

It is not.

1 Like