The main goal of this repo is to help with the setup and management of your Kubernetes Cluster using Ansible.
- Ansible Server to run the role(s)
- Master node and Workers nodes installed with Ubuntu 20 (focal)
- Full network connectivity between the Ansible Server, Master node and Workers nodes
- Ansible inventory file configured, example:
[k8smaster]
master-node
[k8workers]
worker-node1
worker-node2
[k8s:children]
k8smaster
k8workers
There are currently 2 roles available:
Ansible Role to bootstrap 1 Master, multiple Worker nodes Kubernetes Cluster with kubeadm to the Kubernetes version of your choice.
Based on https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/
This will setup the Kubernetes Cluster of the following design:
- 1 Master node, >= 1 Worker nodes
- Create a user to manage the Kubernetes Cluster
- Kubernetes version of your choice (eg: 1.20.5-00)
- containerd runtime
- Weave Net for Pod network
- Option of configuring required ports for Master and Worker nodes with UFW
- Option of creating an NGINX deployment after the Kubernetes Cluster is setup
- Download both kubernetes-setup.yml file and kubernetes-setup directory to your Ansible server.
- Move kubernetes-setup directory to Ansible roles folder.
- Update the variables inside /roles/kubernetes-setup/defaults/main.yml accordingly.
- Update the hosts to multi-groups specified in the Ansible inventory file inside kubernetes-setup.yml.
- Install the required Ansible collection:
ansible-galaxy install -r <path-to-dir>/roles/kubernetes-setup/requirements.yml
- Execute the role:
ansible-playbook kubernetes-setup.yml
Ansible Role to perform a rolling upgrade for multiple Master and Worker nodes Kubernetes Cluster to the Kubernetes version of your choice.
Based on https://kubernetes.io/docs/tasks/administer-cluster/kubeadm/kubeadm-upgrade/
Master node(s) are updated first, then followed by Worker node(s).
Only 1 node will be down each time for updates.
Node which is currently upgrading, will be first drained, followed by the Kubernetes components updates.
This method will ensure that your deployments will not be fully affected/down (provided there are >= 2 worker nodes).
- Download both kubernetes-cluster-rolling-updates.yml file and kubernetes-cluster-rolling-updates directory to your Ansible server.
- Move kubernetes-cluster-rolling-updates directory to Ansible roles folder.
- Update the variables inside /roles/kubernetes-cluster-rolling-updates/defaults/main.yml accordingly.
- Update the hosts to multi-groups specified in the Ansible inventory file inside kubernetes-cluster-rolling-updates.yml.
- Execute the role:
ansible-playbook kubernetes-cluster-rolling-updates.yml