Skip to content

K3s Module

K3s is a highly available, certified Kubernetes distribution designed for production workloads in unattended, resource-constrained, remote locations or inside IoT appliances.

Install

npm install @testcontainers/k3s --save-dev

Examples

const container = await new K3sContainer("rancher/k3s:v1.31.2-k3s1").start();
// obtain a kubeconfig file that allows us to connect to k3s
const kubeConfig = container.getKubeConfig();

const kc = new k8s.KubeConfig();
kc.loadFromString(kubeConfig);

const client = kc.makeApiClient(k8s.CoreV1Api);

// interact with the running K3s server, e.g.:
const nodeList = await client.listNode();

Known limitations

Warning

  • K3sContainer runs as a privileged container and needs to be able to spawn its own containers. For these reasons, K3sContainer will not work in certain rootless Docker, Docker-in-Docker, or other environments where privileged containers are disallowed.