To set up Nextcloud on Kuber­netes, we recommend using S3 for a storage backend and MariaDB as the database. You can increase per­form­ance with a few changes to the con­fig­ur­a­tion.

Nextcloud and Kuber­netes is a rewarding com­bin­a­tion

The com­bin­a­tion of Nextcloud and Kuber­netes with S3 for storage is a promising solution in the private and business sector. The non-com­mer­cial cloud software is suitable for working with local servers as well as external hosts and boasts an excellent security ar­chi­tec­ture compared to numerous Nextcloud al­tern­at­ives. Kuber­netes is an open-source man­age­ment system for container ap­plic­a­tions and can be used for cloud computing in addition to local use. The system is con­sidered to be flexible, highly scalable and fail-safe. Read on to find out how to set up Nextcloud on Kuber­netes.

Tip

To use Nextcloud with Docker check out our com­pre­hens­ive in­struc­tions in our Digital Guide. We’ve also covered the cor­res­pond­ing steps for in­stalling Nextcloud on Ubuntu 22.04.

What con­di­tions must be met?

Before you can start setting up Nextcloud on Kuber­netes, a few con­di­tions must be met. You need suf­fi­cient storage and should have already created a Kuber­netes Cluster. You can choose to create this on your local machine or use cloud storage, depending on your available capacity. Ad­di­tion­ally, ensure the Helm package manager is set up for Kuber­netes. Once ready, you can proceed with the steps.

How to set up Nextcloud on Kuber­netes step by step

Once you have the proper found­a­tion, you can start setting up Nextcloud on Kuber­netes. The key steps are sum­mar­ised 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 des­tin­a­tion; 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

Kuber­netes is deployed using the Helm package manager, which should be installed on your client. Ad­di­tion­ally, ensure you have a con­nec­tion to your Kuber­netes cluster. If so, add the Helm re­pos­it­ory 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 spe­cific­a­tions to this file.

Set cronjobs

First define a time limit for cronjobs. On Unix-like operating systems, cronjobs are tasks that run auto­mat­ic­ally in the back­ground at scheduled intervals. For Nextcloud on Kuber­netes, these are primarily main­ten­ance tasks. In this example, we set the cronjob to run every five minutes. For larger data volumes, more frequent main­ten­ance might be advisable. Use the following code:

cronjob:
    annotations: {}
    curlInsecure: false
    enabled: true
    failedJobsHistoryLimit: 5
    image: {}
    schedule: '*/5*     *** '
    successfulJobsHistoryLimit: 2
shell

Activate HPA

Now, de­ac­tiv­ate the Ho­ri­zont­al Pod Auto­scaler (HPA), which auto­mat­ic­ally scales the number of pods. If you use Read­WriteOnce for Nextcloud and prefer to control the scaling manually, you should de­ac­tiv­ate HPA and focus on one pod. This approach is more con­veni­ent if only a few users need access. The ap­pro­pri­ate 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, Post­gr­eSQL, or SQLite. For our example, we opt for MariaDB. Configure this database as follows and de­ac­tiv­ate 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 mon­it­or­ing with Pro­meth­eus 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 Kuber­netes
Container workloads in expert hands

The ideal platform for demanding, highly scalable container ap­plic­a­tions. Managed Kuber­netes works with many cloud-native solutions and includes 24/7 expert support.

Allow your own con­fig­ur­a­tion files

By default, Nextcloud also uses a file called config.php for con­fig­ur­a­tion on Kuber­netes. To simplify or make this more flexible, you can insert your own con­fig­ur­a­tion 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 place­hold­er ‘example.com’ with your own domain.

Configure Redis

To improve caching with Redis and enhance overall per­form­ance, you can include a custom con­fig­ur­a­tion file. By default, Helm Redis is installed without password pro­tec­tion, but it’s advisable to add an ad­di­tion­al layer of security. Use the following code to set up Redis with password pro­tec­tion 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

Con­fig­ur­ing the storage backend

The last con­fig­ur­a­tion 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 con­fig­ur­a­tion

Since you’ve over­writ­ten the default con­fig­ur­a­tion for Redis above, this must now be de­ac­tiv­ated 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 ad­min­is­trat­or and the cor­res­pond­ing password for the use of Nextcloud on Kuber­netes. Use this code for this:

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

Replace the place­hold­ers with your own details.

Set up email no­ti­fic­a­tions

You can op­tion­ally set up an SMTP service (Simple Mail Transfer Protocol) to receive no­ti­fic­a­tions 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 per­sist­ence drive

The following per­sist­ence con­fig­ur­a­tion is intended for data that Nextcloud stores on the cor­res­pond­ing 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 au­then­tic­a­tion. Use the following code to do this, replacing your password where relevant:

redis:
    enabled: true
    password: 'your-password-for-redis'
    usePassword: true
shell

Limit rep­lic­a­tions

Since you’ve already de­ac­tiv­ated HPA, you should limit the possible number of rep­lic­a­tions to 1:

replicaCount: 1
shell

Install Nextcloud on Kuber­netes

Finally, install Nexcloud on Kuber­netes and also add MariaDB and Redis:

kubectl create ns nextcloud
helm upgrade --install --namespace nextcloud -f your-values.yaml nextcloud nextcloud/nextcloud
shell
IONOS Cloud Object Storage
Cloud storage at an un­beat­able price

Cost-effective, scalable storage that in­teg­rates into your ap­plic­a­tion scenarios. Protect your data with highly secure servers and in­di­vidu­al access control.

Go to Main Menu