Skip to content

Feature: Set NC_serverid per instance #848

Open

Description

@pschichtel

Description of the change

Since NC 33 the UI recommends setting NC_serverid to a unique value per server of a nextcloud cluster. Since the ids should be stable and unique it suggests using a StatefulSet and using its ordinal as the serverid value.

Docs: https://docs.nextcloud.com/server/33/admin_manual/configuration_server/config_sample_php_parameters.html#serverid

Benefits

Not sure what the actual benefit is, but since NC suggests/recommends it, I guess the chart should comply.

Possible drawbacks

No idea if setting NC_serverid has drawbacks, but switching to a StatefulSet does make things a little more complicated.

Activity

  1. csantv commented on Apr 18, 2026

    @csantv
  2. csantv commented on Apr 19, 2026

    @csantv

    Ignore my previous comment. This should be a proper config using init containers.

    nextcloud:
      extraInitContainers:
        - name: generate-serverid-config
          image: busybox
          env:
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
          command: ["/bin/sh", "-c"]
          args:
            - |
              ID=$(echo $POD_NAME | cksum | awk '{print $1 % 1024}')
              echo "<?php \$CONFIG = array('serverid' => $ID);" > /var/local/serverid.config.php
          volumeMounts:
            - name: nextcloud-serverid-config
              mountPath: "/var/local/"
    
      extraVolumes:
      - name: nextcloud-serverid-config
        emptyDir: {}
    
      extraVolumeMounts:
      - name: nextcloud-serverid-config
        mountPath: "/var/www/html/config/serverid.config.php"
        subPath: serverid.config.php
  3. pschichtel commented on Apr 19, 2026

    @pschichtel
    Author

    I wonder if it'd a problem, that this will produce new ids on every restart

  4. csantv commented on Apr 19, 2026

    @csantv

    That makes sense I think as pods are new nextcloud servers. You could also checksum the node name instead and have more stable values.

  5. lukashartl commented on Aug 28, 2026

    @lukashartl

    I also think that it would be best to use a StatefulSet instead. The ordinal numbers used in StatefulSets are exactly what would be needed for the NC_serverid variable.

    I think there are two options here:

    1. Switch the deployment to a StatefulSet by default. I don't know if there are any downsides to this for other users.
    2. Add a variable to the values.md, called kind (or something similar) which is "Deployment" by default, or "StatefulSet". This would ensure that current setups don't break. If it is set to "StatefulSet", we could add the NC_serverid variable.
    {{- if eq (include "nextcloud.workloadKind" .) "StatefulSet" }}
    - name: NC_serverid
      valueFrom:
        fieldRef:
          fieldPath: metadata.labels['apps.kubernetes.io/pod-index']
    {{- end }}

    If we (and potentially the maintainers) can agree on an implementation, I would create the merge request and the tests for it, because I also need and want this change. 😄

  6. pschichtel commented on Aug 30, 2026

    @pschichtel
    Author

    probably saver to have it opt-in.

  7. csantv commented on Oct 23, 2026

    @csantv

    Better config without init containers

    nextcloud:
      configs:
        serverid.config.php: |
          <?php
          $CONFIG = array(
            'serverid' => abs(crc32(gethostname())) % 512,
          );

    I still think each pod is an independent php/nextcloud server so its fine to be dynamic if we treat them as cattle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions