!!! note This module is INCUBATING. While it is ready for use and operational in the current version of Testcontainers, it is possible that it may receive breaking changes in the future. See our contributing guidelines for more information on our incubating modules policy.
Testcontainers module for Rancher's K3s lightweight Kubernetes. This module is intended to be used for testing components that interact with Kubernetes APIs - for example, operators.
Start a K3s server as follows:
Starting a K3S server inside_block:starting_k3s
K3sContainer
exposes a working Kubernetes client configuration, as a YAML String, via the getKubeConfigYaml()
method.
This may be used with Kubernetes clients - e.g. for the official Java client and the Fabric8 Kubernetes client:
Official Java client inside_block:connecting_with_k8sio Fabric8 Kubernetes client inside_block:connecting_with_fabric8
!!! 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.
* k3s containers may be unable to run on host machines where `/var/lib/docker` is on a BTRFS filesystem. See [k3s-io/k3s#4863](https://github.com/k3s-io/k3s/issues/4863) for an example.
Add the following dependency to your pom.xml
/build.gradle
file:
testImplementation "org.testcontainers:k3s:{{latest_version}}"
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>k3s</artifactId>
<version>{{latest_version}}</version>
<scope>test</scope>
</dependency>