Create a kubernetes cluster from scratch with multipass vms and ansible.
To create the vms run the up
script (./up
)
This script will:
- Create and start 3 vms (with names
kube-node-0
,kube-node-1
,kube-node-2
) - Add the public key
./keys/key.pub
in each vm'sauthorized_keys
- Create the ansible
inventory
file by getting each vm's ip.
Every ansible playbook must be run from ./ansible
directory (cd ansible
).
- Create and activate virtual env (optional)
python3 -m venv --clear ./venv
source ./venv/bin/activate
pip install -U pip setuptools wheel # Optionally
- Install ansible and tools
pip install -U ansible-core ansible ansible-lint ansible-navigator
./bin/install-ansible-collections-and-roles
Installs ansible collections and roles../bin/ansible-playbook 00-requirements.yml
Installs basic configuration requirements for each node../bin/ansible-playbook 01-crio.yml
Installs cri-o as container runtime./bin/ansible-playbook 02-kube-install.yml
Installs kubernetes deployment tools (kubeadm, kubelet, kubectl)../bin/ansible-playbook 03-kube-cluster.yml
Setups the kubernetes cluster into the first node kube-node-0.- (cni option 1)
./bin/ansible-playbook 04-cilium.yml
Setups cilium (cni) networking add-on. - (cni option 2)
./bin/ansible-playbook 04-calico.yml
Setups calico (cni) networking add-on. ./bin/ansible-playbook 05-kube-join-nodes.yml
Joins the rest vms to kubernetes cluster as nodes.
You can access kubernetes cluster through kube-node-0
by opening a shell to it with multipass shell kube-node-0
.
multipass shell kube-node-0
kubectl get nodes
You can access the cluster directly with kubectl
from the host machine by getting the ~/.kube/config
from kube-node-0
mkdir -p ~/.kube/
multipass transfer kube-node-0:/home/ubuntu/.kube/config - > ~/.kube/config
kubectl get nodes