Deploying Nextcloud in a Kubernetes Environment is a game-changer for businesses and individuals alike. Nextcloud can be deployed in a Kubernetes environment using a Helm chart.
With Kubernetes, you can easily manage and scale your Nextcloud deployment. This means you can add more resources as needed, without worrying about the underlying infrastructure.
To get started, you'll need to install Helm and add the Nextcloud chart repository. You can do this by running the command `helm repo add nextcloud https://nextcloud.github.io/charts`.
Once you've added the repository, you can install Nextcloud using the command `helm install nextcloud/nextcloud`. This will deploy Nextcloud to your Kubernetes cluster.
Preparation
To prepare for deploying Nextcloud into your Kubernetes cluster, you'll need a few things in place. You'll need administrative access to your Kubernetes cluster.
You'll also need to have Helm v3 installed. This will allow you to manage your Nextcloud deployment using a package manager.
To break out the deployment into different steps, you can use a series of files that deploy Nextcloud into your cluster. These files are for the three main components required for a Nextcloud installation: PostgreSQL Database, Redis, and Nextcloud.
Here are the three main components required for a Nextcloud installation:
- PostgreSQL Database
- Redis
- Nextcloud
You'll also need a secrets file, secrets.yml, that contains the secrets data for all three tools. This will be used to securely store sensitive information such as database credentials and API keys.
Prerequisites
To get started, you'll need to meet a few prerequisites.
You'll need administrative access to your Kubernetes cluster. This will give you the necessary permissions to install and manage Helm.
Helm v3 is also a must-have. This version provides a more streamlined and efficient experience.
Here are the specific requirements in a concise list:
- Administrative access to Kubernetes cluster.
- Helm v3.
Namespace
In preparation for deploying Nextcloud in your Kubernetes cluster, creating a namespace is a crucial step.
A namespace is a way to organize and isolate resources in your cluster.
To create a namespace for Nextcloud, follow the instructions from the article.
Create a namespace for Nextcloud in your Kubernetes cluster.
Software Components
Nextcloud is built upon three key software components. Persistent storage is used to save content, MariaDB for metadata storage, and the nextcloud webapp: PHP + Apache.
These components are deployed using Docker images, which are available for MariaDB and Nextcloud on Docker Hub. For persistent storage, DigitalOcean's persistent volumes are used.
Here are the key components listed:
- Persistent storage
- MariaDB
- Nextcloud webapp (PHP + Apache)
Software Components and Kubernetes Assets
Nextcloud is built on top of several software components, including Persistent storage to save content, MariaDB for metadata storage, and the nextcloud webapp: PHP + Apache.
The Persistent storage can be easily set up using the persistent volumes offered as a service by DigitalOcean.
There are official Docker images available for MariaDB and Nextcloud on Docker Hub.
To manage all Kubernetes manifests and ease the deployment, Kustomize can be used.
Here are the software components used in the example:
- Persistent storage
- MariaDB
- Nextcloud webapp (PHP + Apache)
These components are essential for setting up a Nextcloud deployment.
Helm Charts
Helm Charts are a package manager for Kubernetes that makes it easy to find, use, and maintain applications and tools in your Kubernetes cluster. They provide a consistent and predictable way to deploy and manage software components.
Helm Charts are built on top of Kubernetes' package management system, and they allow you to define a set of templates, values, and dependencies that can be used to deploy an application. This makes it easy to manage complex applications with many dependencies.
Helm Charts use a simple and intuitive syntax, making it easy for developers to create and manage their own Charts. They also provide a way to reuse and share Charts across different projects and teams.
The Chart repository, Helm Hub, contains a vast collection of pre-built Charts that can be easily installed and used in your Kubernetes cluster.
Database
Database setup is crucial for Nextcloud on Kubernetes. MariaDB is a popular choice, and we'll explore its configuration.
To create a MariaDB deployment, you'll need to define a manifest file, mariadb-deployment.yaml. This file will specify the MariaDB Docker image and its configuration.
The MariaDB Docker image allows you to create a database upon container creation. You can pass environment variables to adjust the configuration. Here are some key environment variables to note:
- MYSQL_ROOT_PASSWORD: specifies the password for the MariaDB root superuser account (mandatory)
- MYSQL_DATABASE: allows you to specify the name of a database to be created on image startup (optional)
- MYSQL_USER, MYSQL_PASSWORD: used in conjunction to create a new user and set that user’s password (optional)
For MariaDB to recreate the Nextcloud database, you'll need to delete the persistent volume, not just the container. Environment variables only work on the first startup.
A service is also needed to expose the MariaDB application as a network service. This is defined in a separate manifest file, mariadb-service.yaml.
Security
Security is a top priority in any cloud setup, and Nextcloud Kubernetes is no exception. Nextcloud Kubernetes uses a Kubernetes-based architecture to provide a highly available and scalable storage solution.
With Nextcloud Kubernetes, you can take advantage of built-in features like encryption at rest and encryption in transit, ensuring that your data is protected from unauthorized access. This is made possible by the use of SSL/TLS certificates and the Nextcloud encryption app.
In addition, Nextcloud Kubernetes provides robust access controls, including user authentication and authorization, to ensure that only authorized users can access your data. This is achieved through the use of Nextcloud's built-in user and group management system.
Secrets
Kubernetes Secrets are a way to store and manage sensitive information, like passwords, securely. They can be used for various applications, including mariadb and nextcloud deployments.
To create secrets, you'll need to define the sensitive information in a manifest file. This file should include placeholders for the actual values, which will be generated later.
Some common secrets needed for mariadb and nextcloud containers include:
- A MYSQL_DATABASE, which is set to "nextcloud" for both mariadb and nextcloud.
- A MYSQL_USER, also set to "nextcloud" for both mariadb and nextcloud.
- A MYSQL_PASSWORD, which is generated using a tool like pwgen and encoded as a base-64 string.
- A MYSQL_ROOT_PASSWORD, which can be set to the same value as the MYSQL_PASSWORD for simplicity.
These secrets are used to configure the mariadb and nextcloud containers securely. By storing them as secrets, you can keep the sensitive information separate from the rest of your code and configuration files.
TLS Overview
To enable internet access, Nextcloud requires an HTTPS connection. This setup assumes TLS termination is handled outside of Rancher and Kubernetes.
In my own setup, I use a separate computer with nginx and Let's Encrypt to handle TLS, which then forwards plain traffic to the rancher back-end.
Storage
To create persistent storage for your Nextcloud Kubernetes setup, you'll need to create Persistent Volumes (PVs) and Persistent Volume Claims (PVCs). A PVC is a request for storage by a user, while a PV is a piece of storage in the cluster that has been provisioned by an administrator or dynamically provisioned.
You can find the Volumes section on the Manage menu, where you can see the possibilities for creating a persistent volume with DigitalOcean. One PVC was already created for the monitoring tool.
To create a manifest for a persistent volume, you can follow the example in the How to Add Block Storage Volumes to Kubernetes Clusters tutorial. For example, you can create a 3GB block storage volume to persist end-user data managed by Nextcloud, using a YAML file like nextcloud-pvc.yaml.
You'll also need to create a separate volume for storing mariadb metadata, such as a 2GB PVC for storing Nextcloud metadata on mariadb, using a YAML file like mariadb-pvc.yaml.
Web App
The web app is the core of our Nextcloud deployment. We're using the nextcloud:apache image, which provides a solid foundation for our application.
This image references the db-secret map created earlier, which contains the database credentials needed for Nextcloud to function. The db-secret map is used to login to MariaDB, create the Nextcloud database, and access it for normal operations.
A persistent volume is also required to store content, and we've allocated a large volume to fit our needs.
The Web App
The web app is a crucial part of our setup, and we're using the nextcloud:apache image for it. This image references the db-secret map created earlier, which contains the database credentials.
We also need a persistent volume to store the content of our web app. The deployment uses a large persistent volume to fit all the content.
Nextcloud uses the database credentials in the Secrets map to login to MariaDB, create the nextcloud database, and then access the database for normal operations.
We create an Ingress that points to the nextcloud app service, which is using cloud.example.com. You should change this before proceeding, as it's not a real domain.
An Ingress is a Kubernetes object that manages external access to the cluster. It's like a gatekeeper that allows external traffic to reach our cluster.
The final component is cron, which uses the same nextcloud:apache image and needs access to the persistent storage of the web app.
HAProxy
Setting up HAProxy wasn't too difficult, but it did come with some issues.
I had to increase HA proxy timeouts from the standard 30000ms to 120000ms to avoid timeouts from HAProxy to the nextcloud application.
Normal page loads were nearly 38 seconds, which is garbage and nearly makes the app unusable.
Pointing the proxy at the LoadBalancerIP took a painstakingly slow amount of time, but it eventually worked.
The two issues I ran into with timeouts were 504 bad gateway and 503 server timeouts, which led me to believe it was a configuration issue.
Luckily, I had the internal IP up and it was working just fine.
Deployment
Deploying Nextcloud to Kubernetes is surprisingly easy thanks to Kustomize.
You can deploy 15+ Kubernetes clusters with just a few commands.
At the root of your project folder, simply run a command to deploy Nextcloud to Kubernetes.
Log into Rancher or use kubectl to check when the app is ready, then navigate to the ingress URL to load Nextcloud.
Backup and Commands
Backup and Commands are crucial for Nextcloud Kubernetes.
To ensure data protection, backup must be configured on the file cs-cron_scripts of the node that supports the data services.
You'll also need to run Nextcloud's occ commands, which is the command-line interface for Nextcloud.
To do this, open a terminal into the nextcloud pod and use the following wrapper to run commands.
Data Backup
Data backup is crucial to prevent data loss in case of system failures or other issues. To configure backup and data protection, you must edit the file cs-cron_scripts on the node that supports data services.
It's essential to ensure that backup and data protection is properly set up to safeguard your data. Backup & data protection must be configured on file cs-cron_scripts of the node that supports the data services.
I've seen firsthand how a well-configured backup system can save the day when disaster strikes. Proper configuration of backup and data protection is key to avoiding data loss and ensuring business continuity.
Nextcloud Commands
Nextcloud Commands are a powerful tool for managing your Nextcloud instance from the command line. Nextcloud's occ command, which originates from "ownCloud Console", is the command-line interface for Nextcloud.
To run occ commands, you'll need to open a terminal into your Nextcloud pod and use the following wrapper. This allows you to access a wide range of Nextcloud features and settings from the command line.
Frequently Asked Questions
How to install Nextcloud on Kubernetes?
To install Nextcloud on Kubernetes, follow a 7-step process that includes setting up the environment, creating a namespace, and deploying the application. Start by setting up your environment and following the steps to deploy Nextcloud successfully.
Can Nextcloud run in Docker?
Yes, Nextcloud can run in Docker, and for a seamless experience, use the official Nextcloud All-in-One docker container.
Is Kubernetes a cloud?
No, Kubernetes is not a cloud, but rather a platform that helps build and manage cloud-native applications. It's a foundation for application modernization, enabling faster app development.
Sources
- https://eramons.github.io/techblog/post/nextcloud/
- https://scottharwell.com/kubernetes/nextcloud/collabora/2023/02/11/deploying-nextcloud-in-kubernetes.html
- https://medium.com/@acheaito/nextcloud-on-kubernetes-19658785b565
- https://docs.cskylab.com/reference/kubernetes-templates/k8s-nextcloud
- https://jmoore53.com/system%20configuration/sysadmin/k8s/2021/03/02/nextcloud-on-k8s.html
Featured Images: pexels.com