Skip to content

Instantly share code, notes, and snippets.

@gifflet
Last active January 31, 2024 18:31
Show Gist options
  • Save gifflet/4f6a2c92fe9ae8119725099219f528ed to your computer and use it in GitHub Desktop.
Save gifflet/4f6a2c92fe9ae8119725099219f528ed to your computer and use it in GitHub Desktop.
Adding an agent to a K3d cluster

Requirements

Docker

curl -fsSL get.docker.com | bash

K3d

curl -s https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | bash

Adding agent to cluster

Getting the token

In the server running the cluster get the environment variable K3S_TOKEN from container containing the word server-0 in the name.

docker ps

output

58096ee2bad0   rancher/k3s:v1.26.0-k3s2   "/bin/k3s server --t…"   6 months ago   Up 6 weeks   k3d-k3s-default-server-0

Now that we have the container name k3d-k3s-default-server-0 it is possible to get the token:

docker exec -it k3d-k3s-default-server-0 env | grep K3S_TOKEN

the desired output is

K3S_TOKEN=wiVEjCKZbCBxxxXXMTGf

Creating the agent and connecting to the cluster

Variables:

  • CLUSTER_IP: Host IP where the cluster is available
  • CLUSTER_PORT: Kubernetes API Port exposed by the server load balancer (available in ~/.kube/config )image
  • TOKEN: The token obtained from the server-0 container
k3d node create agent-0 --cluster https://$CLUSTER_IP:$CLUSTER_PORT --role agent --image rancher/k3s:v1.26.0-k3s2 --token $TOKEN
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment