Skip to content

[DEV] Deploy a K3S multi-node cluster with ansible

License

Notifications You must be signed in to change notification settings

mborne/k3s-deploy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

k3s-deploy

Deploy a K3S multi-node cluster with Ansible.

Motivation

Installing a single node K3S cluster is trivial (curl -sfL https://get.k3s.io | sh -). This repository aims at providing :

  • A realistic multi-node cluster to illustrate monitoring and storage with Kubernetes (ReadWriteOnce, ReadWriteMany,...)
  • A discovery cluster for mborne/cours-devbox where vagrant and Ansible are presented before Kubernetes.

Requirements

Copy and adapt inventory/vagrantbox or :

  • Start some VM with vagrantbox
  • Ensure that SSH connexion is working : ansible -i inventory/vagrantbox all -m ping

Parameters

See roles/k3s/defaults/main.yml.

Usage

Download external roles

ansible-galaxy install -r roles/requirements.yml

Deploy K3S

# Deploy K3S with default params :
ansible-playbook -i inventory/vagrantbox playbooks/k3s.yml
# Deploy K3S with a docker mirror :
# ansible-playbook -i inventory/vagrantbox playbooks/k3s.yml -e k3s_docker_mirror=https://docker-mirror.quadtreeworld.net

Configure kubectl

# In k3s-deploy directory :
export KUBECONFIG=$PWD/output/kubeconfig.yml
# List nodes
kubectl get nodes

See roles/k3s/tasks/fetch-config.yml

Check kubectl config

  • kubectl cluster-info :

cluster-info

  • kubectl get nodes -o wide :

get nodes

Have fun with kubernetes!

Uninstall K3S

# 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

Advanced usage

Installing NFS server on master node

# Install NFS on vagrantbox-1
ansible-playbook -i inventory/vagrantbox playbooks/nfs-server.yml
# Check from vagrantbox-2
ssh vagrant@vagrantbox-2 showmount -e vagrantbox-1

Enabling OIDC on K3S

See docs/oidc.md - K3S - OIDC experimentation with Keycloak

Alternatives

Using Kubernetes in docker (Kind) also allows to create a realistic multi-node cluster (see mborne/docker-devbox - kind - quickstart.sh)

License

MIT

Notes

About

[DEV] Deploy a K3S multi-node cluster with ansible

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Languages