Deploy a K3S cluster with Ansible.
Installing a single node K3S cluster is trivial (curl -sfL https://get.k3s.io | sh -
). This repository aims at providing :
- A discovery cluster for mborne/cours-devbox where vagrant and Ansible are presented before Kubernetes.
- A realistic multi-node cluster to illustrate monitoring and storage with Kubernetes (ReadWriteOnce, ReadWriteMany,...)
Copy and adapt inventory/vagrantbox
or :
- Start some VM with vagrantbox
- Ensure that SSH connexion is working :
ansible -i inventory/vagrantbox all -m ping
See roles/k3s/defaults/main.yml.
# Deploy K3S with default params :
ansible-playbook -i inventory/vagrantbox playbooks/k3s.yml
# Deploy K3S using a DockerHub mirror
ansible-playbook -i inventory/vagrantbox playbooks/k3s.yml \
-e k3s_docker_mirror=https://docker-mirror.quadtreeworld.net
# In k3s-deploy directory :
export KUBECONFIG=$PWD/output/kubeconfig.yml
# List nodes
kubectl get nodes
kubectl cluster-info
:
kubectl get nodes -o wide
:
# uninstall k3s on agent nodes
ansible -i inventory/vagrantbox k3s_agent -m shell -a "k3s-agent-uninstall.sh" --become
# uninstall k3s on master node
ansible -i inventory/vagrantbox k3s_master -m shell -a "k3s-uninstall.sh" --become
See roles/k3s/README.md :
# Deploying K3S with :
# - custom parent network for flannel (eth1 with KVM and generic/ubuntu2204)
# - custom kubernetes version
ansible-playbook -i inventory/vagrantbox playbooks/k3s.yml \
-e k3s_docker_mirror=https://docker-mirror.quadtreeworld.net \
-e k3s_flannel_iface=eth1 \
-e k3s_channel=v1.30 \
-e k3s_traefik_enabled=false
playbooks/nfs-server.yml allows the installation of an NFS server to experiment ReadWriteMany storage :
# Download https://github.com/mborne/ansible-nfs-server role :
ansible-galaxy install -r roles/requirements.yml
# Install NFS on vagrantbox-1 :
ansible-playbook -i inventory/vagrantbox playbooks/nfs-server.yml
# Check from vagrantbox-2
ssh vagrant@192.168.50.202 showmount -e vagrantbox-1
#Export list for vagrantbox-1:
#/var/nfs-data 192.168.50.0/24
See sample config inventory/vagrantbox/group_vars/k3s_master/k3s-oidc.yml.dist and docs/oidc.md - K3S - OIDC experimentation with Keycloak
Using Kubernetes in docker (Kind) also allows to create a realistic multi-node cluster (see mborne/docker-devbox - kind - quickstart.sh)