By dynomite567
I want to deploy a Helm chart on my Kubernetes cluster, but I want the deployment attached to a block storage volume, mainly so data is protected from automatic upgrades. Is there any way to do this?
I tried reading the documentation but I do not understand how I can do this with Helm (kinda new to Kubernetes :/): https://www.digitalocean.com/docs/kubernetes/how-to/add-volumes/
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hi there,
When using Helm, you typically specify your desired configuration for the Kubernetes resources in a values.yaml file. To attach a block storage volume to a deployment, you would create a PVC in this file.
Here is a simplified example of how you might define a PVC in your values.yaml:
persistence:
enabled: true
storageClassName: do-block-storage
accessModes:
- ReadWriteOnce
size: 10Gi
In this example, do-block-storage would be the name of the StorageClass that represents block storage volumes on DigitalOcean. The accessModes field defines how the volume can be accessed from a single node: ReadWriteOnce means the volume can be mounted as read-write by a single node.
Then, in your Helm chart’s templates, you would include a PVC and reference the values from values.yaml. Here’s an example of how that might look:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: my-claim
spec:
storageClassName: {{ .Values.persistence.storageClassName }}
accessModes:
- {{ .Values.persistence.accessModes }}
resources:
requests:
storage: {{ .Values.persistence.size }}
In your Deployment or Pod specification, you would then mount this PVC to your pods. Here’s a simplified example:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-deployment
spec:
template:
spec:
containers:
- name: my-container
image: my-image
volumeMounts:
- mountPath: /path/to/mount
name: my-volume
volumes:
- name: my-volume
persistentVolumeClaim:
claimName: my-claim
In this example, the volume my-volume is backed by the PVC my-claim, and is mounted into the pod at /path/to/mount.
Please note that you need to replace the placeholders (my-claim, my-deployment, my-container, my-image, /path/to/mount, my-volume) with values that are appropriate for your use case.
Best,
Bobby
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.