Table of Contents
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 viak3s_extra_args). - Enables and starts the
k3sservice. - Waits for
/etc/rancher/k3s/k3s.yaml. - Fetches kubeconfig to the control machine (
~/.kube/k3s-<inventory_hostname>.yaml). - Replaces
127.0.0.1in the kubeconfig with the host’s inventory hostname so you can usekubectlfrom your laptop. - Optionally runs
kubectl version --shortto 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):
- k3s-master – Installs K3s server, waits for the node token, reads it and sets a fact.
- k3s-workers – Installs K3s agent using the master’s URL and token (vars reference the master host by name, e.g.
w2l-srv-aap). - Verify – On the master, runs
k3s kubectl get nodesand 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.