How to install Nextcloud on Kubernetes
To set up Nextcloud on Kubernetes, we recommend using S3 for a storage backend and MariaDB as the database. You can increase performance with a few changes to the configuration.
Nextcloud and Kubernetes is a rewarding combination
The combination of Nextcloud and Kubernetes with S3 for storage is a promising solution in the private and business sector. The non-commercial cloud software is suitable for working with local servers as well as external hosts and boasts an excellent security architecture compared to numerous Nextcloud alternatives. Kubernetes is an open-source management system for container applications and can be used for cloud computing in addition to local use. The system is considered to be flexible, highly scalable and fail-safe. Read on to find out how to set up Nextcloud on Kubernetes.
To use Nextcloud with Docker check out our comprehensive instructions in our Digital Guide. We’ve also covered the corresponding steps for installing Nextcloud on Ubuntu 22.04.
What conditions must be met?
Before you can start setting up Nextcloud on Kubernetes, a few conditions must be met. You need sufficient storage and should have already created a Kubernetes Cluster. You can choose to create this on your local machine or use cloud storage, depending on your available capacity. Additionally, ensure the Helm package manager is set up for Kubernetes. Once ready, you can proceed with the steps.
How to set up Nextcloud on Kubernetes step by step
Once you have the proper foundation, you can start setting up Nextcloud on Kubernetes. The key steps are summarised in the following sections.
Configure DNS
The first step is to create an A-Record for a subdomain that can point to your desired IP address. If you’re using the local solution, your public IP address is the correct destination; otherwise, enter the IP provided by your cloud service. Depending on the DNS provider, the steps required for this may differ slightly.
Add and update Helm
Kubernetes is deployed using the Helm package manager, which should be installed on your client. Additionally, ensure you have a connection to your Kubernetes cluster. If so, add the Helm repository and update it with the following commands:
helm repo add nextcloud https://nextcloud.github.io/helm/
helm repo updateshellCreate values.yaml
Now create the values.yaml file with the following command:
nano values.yamlshellThen add the following specifications to this file.
Set cronjobs
First define a time limit for cronjobs. On Unix-like operating systems, cronjobs are tasks that run automatically in the background at scheduled intervals. For Nextcloud on Kubernetes, these are primarily maintenance tasks. In this example, we set the cronjob to run every five minutes. For larger data volumes, more frequent maintenance might be advisable. Use the following code:
cronjob:
enabled: true
type: cronjob
cronjob:
annotations: {}
failedJobsHistoryLimit: 5
schedule: '*/5 * * * *'
successfulJobsHistoryLimit: 2yamlActivate HPA
Now, deactivate the Horizontal Pod Autoscaler (HPA), which automatically scales the number of pods. If you use ReadWriteOnce for Nextcloud and prefer to control the scaling manually, you should deactivate HPA and focus on one pod. This approach is more convenient if only a few users need access. The appropriate code is:
hpa:
cputhreshold: 60
enabled: false
maxPods: 10
minPods: 1yamlOverwrite image tag
To ensure that the desired Nextcloud version is taken into account, overwrite the image tag. Use this code to do this:
image:
repository: nextcloud
tag: 28.0.2-apache
pullPolicy: IfNotPresentyamlVersion 28.0.2 is now selected.
Select database
You have three options when selecting your database: MariaDB, PostgreSQL, or SQLite. For our example, we opt for MariaDB. Configure this database as follows and deactivate the other two systems:
internalDatabase:
enabled: false
mariadb:
architecture: standalone
auth:
database: nextcloud
forcePassword: true
password: db-password
rootPassword: root-db-password
username: nextcloud
enabled: true
primary:
persistence:
accessMode: ReadWriteOnce
enabled: true
size: 8Gi
postgresql:
enabled: falseyamlMonitor for metrics
To carry out monitoring with Prometheus or Grafana, insert the following code. This is optional.
metrics:
enabled: true
https: false
image:
pullPolicy: IfNotPresent
repository: xperimental/nextcloud-exporter
tag: v0.3.0
replicaCount: 1
service:
annotations:
prometheus.io/port: '9205'
prometheus.io/scrape: 'true'
labels: {}
type: ClusterIP
timeout: 5syamlAllow your own configuration files
By default, Nextcloud also uses a file called config.php for configuration on Kubernetes. To simplify or make this more flexible, you can insert your own configuration files using the following code:
nextcloud:
configs:
custom.config.php: |-
<?php
$CONFIG = array (
'overwriteprotocol' => 'https',
'overwrite.cli.url' => 'https://drive.example.com',
'filelocking.enabled' => 'true',
'loglevel' => '2',
'enable_previews' => true,
'trusted_domains' =>
[
'nextcloud',
'drive.example.com'
]
);yamlReplace the placeholder ‘example.com’ with your own domain.
Configure Redis
To improve caching with Redis and enhance overall performance, you can include a custom configuration file. By default, Helm Redis is installed without password protection, but it’s advisable to add an additional layer of security. Use the following code to set up Redis with password protection and integrate it with Nextcloud (add it under nextcloud: → configs:, directly after custom.config.php):
redis.config.php: |-
<?php
$CONFIG = array (
'memcache.local' => '\\OC\\Memcache\\Redis',
'memcache.distributed' => '\OC\Memcache\Redis',
'memcache.locking' => '\OC\Memcache\Redis',
'redis' => array(
'host' => getenv('REDIS_HOST'),
'port' => getenv('REDIS_HOST_PORT') ?: 6379,
'password' => getenv('REDIS_HOST_PASSWORD')
)
);yamlConfiguring the storage backend
The last configuration file is inserted for the storage backend S3. It is stored in the code as follows (add it under nextcloud: → configs:, directly after redis.config.php):
s3.config.php: |-
<?php
$CONFIG = array (
'objectstore' => array(
'class' => '\\OC\\Files\\ObjectStore\\S3',
'arguments' => array(
'bucket' => 'bucket-name',
'autocreate' => true,
'key' => 's3-access-key',
'secret' => 's3-secret-key',
'region' => 's3-region',
'hostname' => 's3-endpoint',
'use_ssl' => true,
'use_path_style' => true
)
)
);yamlSwitch off Redis configuration
Since you’ve overwritten the default configuration for Redis above, this must now be deactivated to avoid errors using the following code (add it under nextcloud:):
defaultConfigs:
.htaccess: true
apache-pretty-urls.config.php: true
apcu.config.php: true
apps.config.php: true
autoconfig.php: false
redis.config.php: false
smtp.config.php: trueyamlSet host, admin and password
Now enter the host, the administrator and the corresponding password for the use of Nextcloud on Kubernetes. Use this code for this (add it under nextcloud:):
host: drive.example.com
password: your-password
username: name-of-adminyamlReplace the placeholders with your own details.
Set up email notifications
You can optionally set up an SMTP service (Simple Mail Transfer Protocol) to receive notifications from Nextcloud (add the following code under nextcloud:):
mail:
domain: example.com
enabled: true
fromAddress: user
smtp:
authtype: LOGIN
host: example.com
name: username
password: your-password
port: 465
secure: sslyamlConfigure the persistence drive
The following persistence configuration is intended for data that Nextcloud stores on the corresponding data carrier. This doesn’t affect your user data, which is stored on S3 on a scheduled basis:
persistence:
accessMode: ReadWriteOnce
annotations: {}
enabled: true
size: 8GiyamlPassword protect Redis
It’s advisable to secure Redis with a password. This prevents errors during authentication. Use the following code to do this, replacing your password where relevant:
redis:
auth:
enabled: true
password: 'your-password-for-redis'
enabled: trueyamlLimit replications
Since you’ve already deactivated HPA, you should limit the possible number of replications to 1:
replicaCount: 1yamlInstall Nextcloud on Kubernetes
Finally, install Nexcloud on Kubernetes and also add MariaDB and Redis:
kubectl create ns nextcloud
helm upgrade --install --namespace nextcloud -f values.yaml nextcloud nextcloud/nextcloudshell