k3d is a lightweight wrapper to run k3s (Rancher Lab’s minimal Kubernetes distribution) in docker.
This repo contains a set of recipes to configure and use k3d in different use cases.
K3d requires to have installed the following components
To install, executes the following command:
curl -s https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | bash
Create config file containing configuration of the cluster
k3d-cluster.yml
apiVersion: k3d.io/v1alpha3
kind: Simple
name: mycluster-simple
servers: 1
agents: 2
This is a basic configuration creating a cluster with 1 k3s server and 2 k3s agents
And execute
k3d cluster create -c k3d-cluster.yml
HTTP_PROXY and HTTPS_PROXY environment variables need to be passed to k3d containers
As stated in K3d FAQ, it also requires to validate corporate certificate within the containers. For doing that path to corparte CA certificate must be mounted in k3d containers.
apiVersion: k3d.io/v1alpha3
kind: Simple
name: mycluster-behind-corporate-proxy
servers: 1
agents: 2
volumes:
- volume: /etc/ssl/certs/corporate-ca.pem:/etc/ssl/certs/corporate-ca.crt
env:
- envVar: HTTP_PROXY=http://<corporate_proxy>:<port>
nodeFilters:
- all
- envVar: HTTPS_PROXY=http://<corporate_proxy>:<port>
nodeFilters:
- all
k3s arguments need to be passed to enabling remote monitoring to k3s metrics endpoints.
Within configuratoin file set the parameters under options.k3s.extraArgs
apiVersion: k3d.io/v1alpha3
kind: Simple
name: mycluster-with-metrics-exposed
servers: 1
agents: 2
options:
k3s:
extraArgs:
- arg: --kube-proxy-arg=metrics-bind-address=0.0.0.0
nodeFilters:
- server:*
- agent:*
- arg: --kube-controller-manager-arg=bind-address=0.0.0.0
nodeFilters:
- server:*
- arg: --kube-scheduler-arg=bind-address=0.0.0.0
nodeFilters:
- server:*
For making accesible in localhost at 0.0.0.0:8080 the k3s loadbalancer where traefik is listening create the following k3d config file
apiVersion: k3d.io/v1alpha3
kind: Simple
name: mycluster-with-traefik-ingress-accesible
servers: 1
agents: 2
ports:
- port: 8080:80 # same as `--port '8080:80@loadbalancer'`
nodeFilters:
- loadbalancer