Ansible playbook for spinning up a Kubernetes cluster (HA or non-HA) on multipass ubuntu VMs
- Use ansible to create a number of multipass VMs
- Check out multipass refence documentation for more details on commands used
- Use kubeadm to orchestrate a kubernetes cluster on the VMs as control and worker nodes
- Use kubectl to interact with the cluster
-
What's in the /create directory?
- contains configurations to create all the nodes needed for a kubernetes cluster, including control, worker, and load balancer (if cluster is HA) nodes
- cloud-init-template.j2: multipass supports cloud-init, this template is used to create the worker VMs cloud-init config file
- create-vm-tasks.yaml: tasks to create the nodes according to config file and creates an inventory file to be consumed in a different ansible play
- install-packages-tasks.yaml: tasks to install & configure apt packages needed for the node
- join-cluster-tasks.yaml: tasks to configure & join nodes to the cluster
- playbook.yaml: the main ansible playbook - parses the config file, executes tasks in
create-vm-tasks.yaml
and run plays from other playbooks to configure an HA k8s cluster - vars.yaml: contains all the variables
- /control - contains configurations to initialize and configure control plane nodes
- /loadbalancer - contains configurations to configure load balancer node
-
What's in the /control directory?
- init-first-ctrl-node-tasks.yaml: tasks to initialize the cluster, configure the control nodes
- kubeadm-config-template.j2: template for kubeadm config file
-
What's in the /loadbalancer directory?
- cloud-init-template.j2: multipass supports cloud-init, this template is used to create the cloud-init config file
- haproxy-cfg-template.j2: template for haproxy config file
- configure-lb-tasks.yaml: tasks to configure the haproxy load balancer config
-
What's in the /inventories directory?
- control.yaml: inventory file for control nodes
- loadbalancer.yaml: inventory file for load balancer nodes
- worker.yaml: inventory file for worker nodes
-
What's in the /upgrade directory?
- upgrade-node-tasks.yaml: tasks to upgrade the control nodes
- playbook.yaml: playbook that calls playbooks from
/control
andworker
-
How to create a kubernetes cluster
- run
ansible-playbook create/playbook.yaml
- run
-
How to upgrade a kubernetes cluster
- run
ansible-playbook upgrade/playbook.yaml
- run
-
How to delete the cluster
- run
multipass stop --all
to stop all the multipass VMs - run
multipass delete -all
to delete all the multipass VMs. ❗ FYI: will DELETE all multipass VMs ❗ - run
multipass purge
to purge the VMs
- run