1 kubernetes
Luca Matteo Spoljarevic edited this page 2026-02-27 21:40:24 +01:00
This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

kubernetes (deployment)

Location: deployment/kubernetes/

Playbooks and inventory files for K3s: single-node install/bootstrap and multi-node cluster (master + workers).


Playbooks

k3s-deployment.yml

Single-node (or per-node) K3s install and bootstrap:

  • Installs curl, ca-certificates, iptables.
  • Downloads the official K3s install script and runs it (optional version via k3s_version, extra args via k3s_extra_args).
  • Enables and starts the k3s service.
  • Waits for /etc/rancher/k3s/k3s.yaml.
  • Fetches kubeconfig to the control machine (~/.kube/k3s-<inventory_hostname>.yaml).
  • Replaces 127.0.0.1 in the kubeconfig with the hosts inventory hostname so you can use kubectl from your laptop.
  • Optionally runs kubectl version --short to verify.

Target: hosts: k3s-host (define in inventory).

Run:

ansible-playbook -i deployment/kubernetes/inventory.ini deployment/kubernetes/k3s-deployment.yml -K

k3s-cluster.yml

Multi-node K3s cluster (one master, one or more workers):

  1. k3s-master Installs K3s server, waits for the node token, reads it and sets a fact.
  2. k3s-workers Installs K3s agent using the masters URL and token (vars reference the master host by name, e.g. w2l-srv-aap).
  3. Verify On the master, runs k3s kubectl get nodes and shows output.

Targets: Groups k3s-master and k3s-workers; use an inventory that defines these groups (e.g. inventory-cluster.yml).

Run:

ansible-playbook -i deployment/kubernetes/inventory-cluster.yml deployment/kubernetes/k3s-cluster.yml -K

Note: The playbook uses a hardcoded master hostname in vars (hostvars['w2l-srv-aap']). Change it to match your inventory or make it a variable.


Inventory files

File Purpose
inventory.ini k3s-host and kubernetes-cluster groups; for single-node or generic use.
inventory-cluster.yml INI-style groups: k3s-master, k3s-workers, k3s-all (children). For k3s-cluster.yml.
inventory-test.ini Single k3s-host (e.g. a VM) for testing.

Adjust hostnames, IPs, users, and SSH keys to match your environment.