open-cluster-management-io / multicluster-controlplane

A standalone controlplane to run ocm core.
Apache License 2.0
15 stars 23 forks source link

multicluster-controlplane

The multicluster-controlplane is a lightweight Open Cluster Manager (OCM) control plane that is easy to install and has a small footprint. It is more efficient, lightweight, and cost-effective, while improving OCM scalability and support for edge scenarios.

Architecture Diagram

Some of the features are:

The benefits of these improvements are as follows:

Get started

Build

Build binary

make vendor
make build

Build image

export IMAGE_NAME=<customized image. default is quay.io/open-cluster-management/multicluster-controlplane:latest>
make image

Run controlplane as a local binary

export CONFIG_DIR=<the directory of the controlplane configuration file. default is ./_output/controlplane>
make run

You can customize the controlplane configurations by creating a config file and using the environment variable CONFIG_DIR to specify your config file directory.

NOTE: the controlplane config file name must be ocmconfig.yaml

Here is a sample file of ocmconfig.yaml:

dataDirectory: "/.ocm"
apiserver:
  externalHostname: "http://abcdefg.com"
  port: 9443
  caFile: "ca.crt"
  caKeyFile: "ca.key"
etcd:
  mode: external
  prefix: "/registry"
  servers:
  - http://etcd-1:2379
  - http://etcd-2:2379
  caFile: "etcd-trusted-ca.crt"
  certFile: "etcd-client.crt"
  keyFile: "etcd-client.key"

The yaml content shown above is a config file with all fields filled in. Following this to better understand the config file.

Field dataDirectory is a string variable indicating the directory to store generated certs ,embed etcd data and kubeconfig, etc. While this field is missed in the config file, the default value /.ocm makes sense.

Field apiserver contains config for the controlplane apiserver:

Field etcd contains config for the controlplane etcd:

NOTE: For apiserver field: If you want to use your own CA pair to sign the certificates, the caFile and caKeyFile should be set together. Which means that if one of the two fields is missed/empty, the controlplane would self-generate CA pair to sign the necessary certificates.

Use helm to deploy controlplane in a cluster

  1. Set the environment variable KUBECONFIG to your cluster kubeconfig path

    export KUBECONFIG=<the kubeconfig path of your cluster>
  2. (Optional) By default, the controlplane will have an embedded etcd, you can use the following command to deploy an external etcd

    make deploy-etcd

    This external etcd will be deployed in the namespace multicluster-controlplane-etcd, its certificates will be created at ./_output/etcd/deploy/cert-etcd and its service urls will be: http://etcd-0.etcd.multicluster-controlplane-etcd:2379, http://etcd-1.etcd.multicluster-controlplane-etcd:2379, and http://etcd-2.etcd.multicluster-controlplane-etcd:2379

  3. Run following command to deploy a controlplane

    helm repo add ocm https://open-cluster-management.io/helm-charts/
    helm repo update
    helm search repo ocm
    helm install -n multicluster-controlplane multicluster-controlplane ocm/multicluster-controlplane --create-namespace --set <values to set>
    • To provide your own ca pairs for controlplane with the following arguements:
    --set-file apiserver.ca="<path-to-ca>",apiserver.cakey="<path-to-ca-key>"
    • To use external etcd with the following arguements:

      --set-file etcd.ca="<path-to-etcd-ca>",etcd.cert="<path-to-etcd-client-cert>",etcd.certkey="<path-to-etcd-client-cert-key>"
      --set etcd.mode="external",etcd.servers={server1, server2, ...}
    • To use the OpenShift route with the following arguements:

      --set route.enabled=true
    • To use the load balance service with the following arguements:

      --set loadbalancer.enabled=true
    • To use the node port serive with the following arguements:

      --set nodeport.enabled=true
      --set nodeport.port=<your-node-port>
    • To enable the self management with the following arguements:

      --set enableSelfManagement=true
    • To delegate the authentication with kube-apiserver with the following arguements:

      --set enableDelegatingAuthentication=true

    More available config values can be found from here.

Uninstall the controlplane

helm uninstall -n multicluster-controlplane multicluster-controlplane

Access the controlplane

Join a cluster

You can use clusteradm to access and join a cluster.

  1. Get the join token from controlplane:

    clusteradm --kubeconfig=<controlplane kubeconfig file> get token --use-bootstrap-token
  2. Join a cluster using controlplane agent is now available in clusteradm(see this PR for more details, you should build the latest code). Add the --singleton flag in join command to use the controlplane agent, rather than klusterlet, to join a cluster:

clusteradm join --hub-token <controlplane token> --hub-apiserver <controlplane apiserver> --cluster-name <cluster name> --singleton
  1. Access the controlplane apiserver to accept the managed cluster:
    clusteradm --kubeconfig=<controlplane kubeconfig file> accept --clusters <cluster name>

Note: clusteradm version should be v0.4.1 or later