Files
dokku/docs/deployment/schedulers/k3s.md
T

8.8 KiB

K3s Scheduler

scheduler-k3s:initialize                           # initializes a cluster
scheduler-k3s:add-server [user:password@host:port] # adds a server node to a Dokku-managed cluster
scheduler-k3s:add-client [user:password@host:port] # adds a client node to a Dokku-managed cluster
scheduler-k3s:set [<app>|--global] <key> (<value>) # Set or clear a scheduler-k3s property for an app or the scheduler

Important

New as of 0.33.0

For multi-server support, Dokku provides the ability for users to setup a K3s cluster. As with all schedulers, it is set on a per-app basis. The scheduler can currently be overridden by running the following command:

dokku scheduler:set node-js-app selected k3s

As it is the default, unsetting the selected scheduler property is also a valid way to reset the scheduler.

dokku scheduler:set node-js-app k3s

Tutorial

Single-node cluster

Initialize the cluster in single-node mode. This will start k3s on the Dokku node itself.

# must be run as root
dokku scheduler-k3s:initialize

The above command will initialize a cluster with an automatically generated token for authentication. This token should be stored securely for later recovery, and can be displayed with via the scheduler-k3s:report command:

dokku scheduler-k3s:report --global
=====> --global scheduler-k3s information
       scheduler k3s token: topsecret:server:token

Setup registry authentication. The K3s scheduler plugin will automatically pick up any newly configured registry backends and ensure nodes in the cluster have the credentials in place for pulling images from the cluster.

# hub.docker.com
dokku registry:login hub.docker.com $USERNAME $PASSWORD

To ensure images are pushed and pulled from the correct registry, set the correct server registry property. This can be set on a per-app basis, but we will set it globally here for this tutorial.

dokku registry:set --global server hub.docker.com

If using docker hub, you'll need to use a custom repository name. As it is unique, this must be set on a per-app basis.

dokku registry:set node-js-app image-repo my-awesome-prefix/node-js-app

Additionally, apps should be configured to push images on the release phase via the push-on-release registry property.

dokku registry:set --global push-on-release true

As routing is handled by traefik managed on the k3s plugin, set the proxy plugin to k3s as well. This implements a traefik-plugin compatible layer, allowing users to otherwise interact with the traefik plugin as expected.

dokku proxy:set --global k3s

Ensure any other proxy implementations are disabled. Typically at least nginx will be running on the Dokku host and should be stopped if the host is used as load balancer.

dokku nginx:stop

Finally, set the scheduler to k3s so that app deploys will work on k3s.

dokku scheduler:set --global selected k3s

At this point, all app deploys will be performed against the k3s cluster.

Running a multi-cluster node

Important

This is future planned behavior. Commands here will not work as expected.

For high-availability, it is recommended to add both agent and server nodes to the cluster. Dokku will default to starting the cluster with an embedded Etcd database backend, and is ready to add new agent or server nodes immediately.

Multiple server nodes can be added with the scheduler-k3s:add-server command. This will ssh onto the specified server, install k3s, and join it to the current Dokku node in server mode.

Warning

Certain ports must be open for cross-server communication. Refer to the K3s networking documentation for the required open ports between servers prior to running the command.

dokku scheduler-k3s:add-server root@server-1.example.com

Server nodes are typically used to replicate the cluster state, and it is recommended to have an odd number of nodes spread across several availability zones (datacenters in close proximity within a region). This allows for higher availability in the event of a cluster failure. Server nodes do not run any app workloads, but run control-plane services such as the traefik load balancer and the etcd backing store.

Note

Only the initial Dokku server will be properly configured for deployment, and should be considered your git remote. Additional server nodes are for ensuring high-availability of the K3s etcd state. Ensure this server is properly backed up and restorable or deployments will not work.

Agent nodes are used to run. To add an agent, run the add-agent command. This will ssh onto the specified server, install k3s, and join it to the current Dokku node in agent mode. Agents are typically used to run app workloads.

dokku scheduler-k3s:add-agent root@server-1.example.com

When attaching an agent or server node, the K3s plugin will look at the IP associated with the eth0 interface and use that to connect the new node to the cluster. To change this, set the network-interface property to the appropriate value.

dokku scheduler-k3s:set --global network-interface eth1

Dokku does not manage the ssh key of the server, but the value that should be added to the remote root user's /root/.ssh/authorized_keys file can be checked with the git:public-key command:

dokku git:public-key

Joining an existing cluster

Important

This is future planned behavior. Commands here will not work as expected.

In some cases, Dokku must be setup from scratch and joined to an existing cluster. To do so, first set the k3s token value:

dokku scheduler-k3s:set --global token topsecret:server:token

Next, run the scheduler-k3s:join-cluster command. This command takes a single server node in the cluster, will SSH onto the specified server, retrieve the kubeconfig, and then configure kubectl on the Dokku node to speak with the specified k3s cluster. Dokku will also periodically retrieve all server nodes in the cluster so that server nodes can be safely replaced as needed.

dokku scheduler-k3s:join-cluster root@server-1.example.com

Using kubectl remotely

Warning

Certain ports must be open for interacting with the remote kubernets api. Refer to the K3s networking documentation for the required open ports between servers prior to running the command.

By default, Dokku assumes that all it controls all actions on the cluster, and thus does not expose the kubectl binary for administrators. To interact with kubectl, you will need to retrieve the kubeconfig for the cluster and configure your client to use that configuration.

dokku scheduler-k3s:show-kubeconfig

Scheduler Interface

The following sections describe implemented and unimplemented scheduler functionality for the k3s scheduler.

Implemented Commands and Triggers

This plugin implements various functionality through plugn triggers to integrate with Docker for running apps on a single server. The following functionality is supported by the scheduler-k3s plugin.

  • apps:destroy
  • cron
  • run - The scheduler-post-run trigger is not always triggered
  • run:detached
  • enter
  • deploy
  • logs
  • ps:stop

Unimplemented command functionality

  • apps:clone
  • apps:rename
  • run:list
  • run:logs
  • ps:inspect

The following Dokku functionality is not implemented at this time.

  • vector log integration
  • persistent storage
  • healthchecks

Logging support

App logs for the logs command are fetched by Dokku from running containers via the kubectl cli. Persisting logs via Vector is not implemented at this time. Users may choose to configure the Vector Kubernetes integration directly by following this guide.

Supported Resource Management Properties

The k3s scheduler supports a minimal list of resource limits and reservations. The following properties are supported:

Resource Limits

Note

Cron tasks retrieve resource limits based on the computed cron task ID. If unspecified, the default will be 1 CPU and 512m RAM.

  • cpu: is specified in number of CPUs a process can access.
  • memory: should be specified with a suffix of b (bytes), k (kilobytes), m (megabytes), g (gigabytes). Default unit is m (megabytes).

Resource Reservations

Note

Cron tasks retrieve resource reservations based on the computed cron task ID. If unspecified, the default will be 1 CPU and 512m RAM.

  • cpu: is specified in number of CPUs a process can access.
  • memory: should be specified with a suffix of b (bytes), k (kilobytes), m (megabytes), g (gigabytes). Default unit is m (megabytes).