Kubespray setup
Prerequisites and repository initialisation.
Preparing to deploy the Kubernetes cluster.
- ssh to the ansible server:
ssh dev@dev-ansible.reids.net.au - Cluster name will be called devcluster with dns name dev.reids.net.au
- A single ansible server can be used to deploy multiple k8s clusters by keeping each in seperate environments
- Install base packages
sudo apt update
sudo apt -y install python3-pip git yq - Install the virtual environment package
sudo apt install -y python3.12-venv - Create and activate the virtual environment
python3 -m venv venv
source venv/bin/activate - Create and change directory the kubespray directory
mkdir -p ~/kubespray-devcluster && cd ~/kubespray-devcluster - Clone kubespray
git clone https://github.com/kubernetes-sigs/kubespray.git
cd kubespray - Upgrade pip and install requirements
pip install --upgrade pip
pip install -r requirements.txt - Copy sample files to devcluster
cp -rfp inventory/sample inventory/devcluster - If error due to ModuleNotFoundError: No module named 'ruamel' then:
pip install ruamel.yamland try again - In the latest versions of kubespray there is no longer a
hosts.yaml. Insteadinventory.iniis used
Sample inventory
- Sample inventory.ini:
# This inventory describe a HA typology with stacked etcd (== same nodes as control plane)
# and 3 worker nodes
# See https://docs.ansible.com/ansible/latest/inventory_guide/intro_inventory.html
# for tips on building your # inventory
# Configure 'ip' variable to bind Kubernetes services on a different ip than the default interface
# We should set etcd_member_name for etcd cluster. The node that are not etcd members do not need to set the value,
# or can set the empty string value.
[kube_control_plane]
# node1 ansible_host=95.54.0.12 # ip=10.3.0.1 etcd_member_name=etcd1
# node2 ansible_host=95.54.0.13 # ip=10.3.0.2 etcd_member_name=etcd2
# node3 ansible_host=95.54.0.14 # ip=10.3.0.3 etcd_member_name=etcd3
[etcd:children]
kube_control_plane
[kube_node]
# node4 ansible_host=95.54.0.15 # ip=10.3.0.4
# node5 ansible_host=95.54.0.16 # ip=10.3.0.5
# node6 ansible_host=95.54.0.17 # ip=10.3.0.6
Modified inventory
- With the single master and worker nodes here is the modified inventory with the full path:
vi ~/kubespray-devcluster/kubespray/inventory/devcluster/inventory.ini[kube_control_plane]
dev-m-v1 ansible_host=192.168.30.203 etcd_member_name=etcd1
[etcd:children]
kube_control_plane
[kube_node]
dev-w-v1 ansible_host=192.168.30.206