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.

Tip

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 summarized 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 update
shell

Create values.yaml

Now create a new Helm chart with the following command:

nano values.yaml
shell

Then 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:
    annotations: {}
    curlInsecure: false
    enabled: true
    failedJobsHistoryLimit: 5
    image: {}
    schedule: '*/5*     *** '
    successfulJobsHistoryLimit: 2
shell

Activate 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: 1
shell

Overwrite image tag

To ensure that the current version of Helm is taken into account, overwrite the image tag. Use this code to do this:

image:
    repositor: nextcloud
    tag: 28.0.2-apache
    pullPolicy: IfNotPresent
shell

Version 28.0.2 or a more recent version 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:
    db:
        name: nextcloud
        password: db-password
        user: nextcloud
    enabled: true
    master:
        persistence:
            accessMode: ReadWriteOnce
            enabled: true
            size: 8Gi
    replication:
        enabled: false
    rootUser:
        password: root-db-password
        forcePassword: true
postgresql:
    enabled: false
shell

Monitor 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: 5s
shell
IONOS Cloud Managed Kubernetes
Container workloads in expert hands

The ideal platform for demanding, highly scalable container applications. Managed Kubernetes works with many cloud-native solutions and includes 24/7 expert support.

Allow 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'
                     ]
            );
shell

Replace 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:

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('your-password-for-redis')
      )
    );
shell

Configuring the storage backend

The last configuration file is inserted for the storage backend S3. It is stored in the code as follows:

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
        )
      )
    );
shell

Switch 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:

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: true
shell

Set 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:

host: drive.example.com
password: your-password
username: name-of-admin
shell

Replace 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:

mail:
    domain: example.com
    enabled: false
    fromAddress: user
    smtp:
      authtype: LOGIN
      host: example.com
      name: username
      password: your-password 
      port: 465
      secure: ssl
shell

Configure 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: 8Gi
shell

Password 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:
    enabled: true
    password: 'your-password-for-redis'
    usePassword: true
shell

Limit replications

Since you’ve already deactivated HPA, you should limit the possible number of replications to 1:

replicaCount: 1
shell

Install Nextcloud on Kubernetes

Finally, install Nexcloud on Kubernetes and also add MariaDB and Redis:

kubectl create ns nextcloud
helm upgrade --install --namespace nextcloud -f your-values.yaml nextcloud nextcloud/nextcloud
shell
IONOS Object Storage
Secure, affordable storage

Cost-effective, scalable storage that integrates into your application scenarios. Protect your data with highly secure servers and individual access control.

Was this article helpful?
We use cookies on our website to provide you with the best possible user experience. By continuing to use our website or services, you agree to their use. More Information.
Page top