Documentation ¶
Overview ¶
Package k3s provides a Gnomock Preset for lightweight kubernetes (k3s). This preset by no means should be used in any kind of deployment, and no other presets are supposed to be deployed in it. The goal of this preset is to allow easier testing of Kubernetes automation tools.
This preset does not use a well-known docker image like most other presets do. Instead, it uses a custom built and adapted image that runs lightweight Kubernetes (k3s) in a docker container: https://github.com/orlangure/k3s-dind.
Please make sure to pick a version here: https://hub.docker.com/repository/docker/orlangure/k3s.
The following versions include important fixes that prevent this preset from working on recent Linux Kernel versions, please make sure to avoid using older versions for each API level:
- v1.18.19
- v1.19.11
- v1.20.7
- v1.21.1
Keep in mind that k3s runs in a single docker container, meaning it might be limited in memory, CPU and storage. Also remember that this cluster always runs on a single node.
To connect to this cluster, use `Config` function that can be used together with Kubernetes client for Go, or `ConfigBytes` that can be saved as `kubeconfig` file and used by `kubectl`.
This preset currently doesn't work on arm64 architecture, or on Ubuntu 22.04 (latest supported Ubuntu version is 20.04) due to internal cgroup changes.
Index ¶
Constants ¶
const (
KubeconfigPort = "kubeconfig"
)
KubeconfigPort is a port that exposes a single `/kubeconfig` endpoint. It can be used to retrieve a configured kubeconfig file to use to connect to this container using kubectl.
Variables ¶
This section is empty.
Functions ¶
func Config ¶
Config returns `*rest.Config` instance of Kubernetes client-go package. This config can be used to create a new client that will work against k3s cluster running in the provided container.
func ConfigBytes ¶
ConfigBytes returns file contents of kubeconfig file that should be used to connect to the cluster running in the provided container.
Types ¶
type Option ¶
type Option func(*P)
Option is an optional configuration of this Gnomock preset. Use available Options to configure the container.
func WithPort ¶
WithPort allows to use a custom port for k3s API access instead of the default one. If no custom port is provided, port 48443 is used instead.
Please make sure that whichever port you choose to use (including the default) is available on the host system. Otherwise this container won't start.
type P ¶
P is a Gnomock Preset implementation of lightweight kubernetes (k3s).
func (*P) Ports ¶
func (p *P) Ports() gnomock.NamedPorts
Ports returns ports that should be used to access this container.