Skip to content

Highly available hosted control planes#

Note

Highly available control planes are supported for the standalone and Cluster API in-cluster use cases.

Setting up a highly available etcd cluster for Kubernetes control planes can be complicated due to their dynamic nature. In k0smotron, we solve this challenge by "externalizing" the HA setup of data storage for the control plane.

The control planes managed by k0smotron are k0s control planes. As k0s comes with support for using SQL databases as data store, which uses Kine, you can use HA databases instead of etcd. This enables you to use, for example, Postgres operator, MySQL operator, or cloud provider managed databases as the data store for the control planes.

Using Postgres operator#

This instruction demonstrates how to configure the Postgres operator to manage the data store of a control plane. Use these steps as an example for the required data store resource.

  1. Install the Postgres operator following the quickstart guide.

  2. Create the database using a custom resource:

    apiVersion: "acid.zalan.do/v1"
    kind: postgresql
    metadata:
      name: acid-minimal-cluster
    spec:
      teamId: "acid"
      volume:
        size: 10Gi
      numberOfInstances: 2
      users:
        # database owner
        k0smotron:
        - superuser
        - createdb
    
      databases:
        kine: k0smotron
      postgresql:
        version: "15"
    
  3. Once you set up the database, configure k0smotron to create a control plane:

    cat <<EOF | kubectl apply -f -
    apiVersion: k0smotron.io/v1beta1
    kind: Cluster
    metadata:
      name: k0smotron-test
    spec:
      replicas: 3
      service:
        type: LoadBalancer
      kineDataSourceURL: postgres://k0smotron:<passwd>@acid-minimal-cluster.default:5432/kine?sslmode=disable
    EOF
    

    You can also use the reference to the secret containing the database credentials:

    cat <<EOF | kubectl apply -f -
    apiVersion: v1
    kind: Secret
    metadata:
      name: database-credentials
      namespace: k0smotron-test
    type: Opaque
    data:
      K0SMOTRON_KINE_DATASOURCE_URL: <base64-encoded-datasource>
    ---
    apiVersion: k0smotron.io/v1beta1
    kind: Cluster
    metadata:
      name: k0smotron-test
    spec:
      replicas: 3
      service:
        type: LoadBalancer
      kineDataSourceSecretName: database-credentials
    EOF
    

    !!! note

    The secret must be in the same namespace as the cluster and the key
    must be `K0SMOTRON_KINE_DATASOURCE_URL`.