How can I store and back up files and volumes in Kubernetes? Longhorn is our choice here at SREDevOps.org!
TL;DR
Tired of your Kubernetes volumes disappearing like your last vacation? 😩Longhorn 1.6 is here to save your data (and your sanity)! This bad boy brings persistent volumes to your Kubernetes cluster, making sure your apps stay fed with data, no matter what chaos the internet throws at them. We'll walk you through what's new and how to perform a basic setup. If you have doubts, feel free to comment and we'll help you!
Why Longhorn for Persistent Volumes?
Imagine this: you're running a stateful application on Kubernetes, like a database or a message queue. These bad boys need their data to stick around, even if a pod decides to take a nosedive. That's where persistent volumes come in, acting like trusty hard drives for your apps.
Longhorn steps up as your Kubernetes-native storage superhero, providing these awesome features:
- Easy peasy installation and management: No need for a PhD in storage sorcery! Longhorn is all about simplicity.
- High availability and disaster recovery: Replicate your volumes across multiple nodes, so your data laughs in the face of failures.
- Snappy snapshots and backups: Because sometimes, you need to rewind time (or at least your data).
- Blazing-fast performance: Built on a distributed block storage architecture, Longhorn keeps your apps running at warp speed.
New Goodies in Longhorn 1.6: What's the Hype About?
This release isn't just about bug fixes and performance tweaks (although there are plenty of those too!). Longhorn 1.6 is packing some seriously cool new features:
- Enhanced Monitoring and Alerting: Keep a watchful eye on your volumes with improved Prometheus metrics and alerting rules. No more surprises! Prometheus metrics endpoints now available.
- Beefed-Up Security: Rest easy knowing your data is even more secure with new security enhancements and vulnerability patches. Easily upgrade versions without disruptions, easily encrypt volumes.
- Improved Volume Expansion: Need more space? No problem! Expanding volumes just got smoother and more efficient. Just... increase the size of each replica. That's all.
- And a Whole Lot More: We're talking bug fixes, stability improvements, and a bunch of under-the-hood magic to make Longhorn even more awesome. Check out the release notes for all the juicy details.
Rolling Up Our Sleeves: Installing Longhorn 1.6
Alright, enough chit-chat! Let's get this storage party started. We'll assume you've got a Kubernetes cluster up and running. If not, go get one! We'll wait.... well, maybe. Hurry up.
Pre checks
Longhorn provides a script to check if you have all the requirements in your nodes before install anything. You can check and run the script with:
# Get the latest script from the official repo
wget https://github.com/longhorn/longhorn/blob/master/scripts/environment_check.sh
# Check what you are going to run with
nano ./environment_check.sh # Or vi, code, cat, whatever you like to edit
# Give execution permissions and run:
chmod +x ./environment_check.sh && ./environment_check.sh
Installing Longhorn
If we met the prerequisites, now we need to add the Longhorn chart repository (There is also other methods, but we suggest this one, because... reaasons.)
helm repo add longhorn https://charts.longhorn.io
helm repo update
Now, let's install Longhorn into the longhorn-system
namespace:
helm install longhorn longhorn/longhorn \
--namespace longhorn-system \
--create-namespace
That's it! Longhorn will work its magic, deploying all the necessary components in your cluster. You can check its status using:
kubectl get pods -n longhorn-system
Once all the pods are running happily in their "Running" state, you're good to go! You've got yourself a shiny new Longhorn setup, ready to handle all your persistent volume needs.
Creating Your First Longhorn Volume
Now for the fun part! Let's create a persistent volume using Longhorn. We'll do this by defining a PersistentVolumeClaim (PVC) in our Kubernetes YAML file. This tells Longhorn what kind of volume we need and how much storage space we're craving.
Here's a sample PVC definition:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: my-longhorn-volume
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
storageClassName: longhorn
In this example, we're asking for:
- A volume named "my-longhorn-volume"
- 1 Gigabyte of storage space
- Access mode set to "ReadWriteOnce" (meaning only one pod can access the volume at a time)
- And we're using the "longhorn" storage class, which tells Kubernetes to use Longhorn for provisioning this volume
Save this YAML file (let's call it `pvc.yaml`) and apply it to your cluster using:
kubectl apply -f pvc.yaml
Boom! 💥 You've just created a Longhorn volume. You can now use this PVC in your pod definitions to mount the volume and give your apps the persistent storage they deserve.
Wrapping Up
And there you have it! You've learned about Longhorn 1.6, its awesome features, how to install it, and how to create your first persistent volume. Go forth and build amazing stateful applications on Kubernetes with the confidence that your data is safe, secure, and always available with Longhorn!
Ready to Dive Deeper?
- 📚 Longhorn Documentation: https://longhorn.io/docs/
- Longhorn GitHub:
Repository: https://github.com/longhorn/longhorn
- Register with Email
- Login with LinkedIn
- Login with GitHub