This is unreleased documentation for SUSE® Virtual Clusters v1.2.0 (Dev).

Configuring an External Datastore

By default, SUSE Virtual Clusters runs each virtual cluster’s K3s server against its own embedded datastore. For high-availability or centralized-storage scenarios, you can instead point a virtual cluster at an external Kine-compatible datastore, such as PostgreSQL, MySQL, or an external etcd cluster.

External datastore support has no dedicated Cluster spec field. It is configured by mounting a K3s config drop-in file into the server pod using spec.secretMounts, the same mechanism used to inject custom K3s configuration or certificates.

Prerequisites

  • A running PostgreSQL, MySQL, or etcd instance reachable from the host cluster.

  • The connection string (DSN) for that datastore, in the same format accepted by K3s' --datastore-endpoint flag. See the K3s external datastore documentation for supported DSN formats.

Create the datastore configuration secret

Create a Secret containing a K3s config file with the datastore-endpoint set to your external datastore’s connection string. Set cluster-init: false and server: "" so the K3s server does not attempt embedded-etcd cluster bootstrap:

apiVersion: v1
kind: Secret
metadata:
  name: datastore-config
  namespace: test-k3k
type: Opaque
stringData:
  config.yaml: |
    datastore-endpoint: postgres://postgres:password@postgres.test-k3k.svc.cluster.local:5432/k3k
    cluster-init: false
    server: ""

Reference the secret from the Cluster resource

Mount the secret into both the init and server K3s config-drop-in directories using spec.secretMounts:

apiVersion: k3k.io/v1beta1
kind: Cluster
metadata:
  name: test
  namespace: test-k3k
spec:
  mode: shared
  servers: 1
  secretMounts:
    - name: externaldb-init-config
      secretName: datastore-config
      mountPath: /opt/rancher/k3s/init/config.yaml.d/
      role: server
    - name: externaldb-server-config
      secretName: datastore-config
      mountPath: /opt/rancher/k3s/server/config.yaml.d/
      role: server

This works for both shared and virtual mode, and with any number of servers.

Once the server pod is Running, the K3s server connects to the external datastore and populates the kine schema there instead of using the embedded datastore. You can confirm this by inspecting the target database directly, or by checking that the server pod does not carry the etcdpod.k3k.io/finalizer finalizer that SUSE Virtual Clusters adds for embedded-etcd clusters.