Setup example for kubernetes with kubespray.
Using kubespray release v2.22.1.
Assuming you have:
VMs layout:
Clone kubespray and checkout latest tag
git clone https://github.com/kubernetes-sigs/kubespray.git
cd kubespray
git checkout v2.22.1
cp -a inventory/sample inventory/home
Example hosts inventory file:
[all]
master1.lan ansible_host=192.168.5.31 etcd_member_name=master1.lan
worker1.lan ansible_host=192.168.5.41
worker2.lan ansible_host=192.168.5.42
worker3.lan ansible_host=192.168.5.43
worker4.lan ansible_host=192.168.5.44
[kube_control_plane]
master1.lan
[etcd]
master1.lan
[kube_node]
worker1.lan
worker2.lan
worker3.lan
worker4.lan
[calico_rr]
[k8s_cluster:children]
kube_control_plane
kube_node
calico_rr
Set non-default values:
# configure arp_ignore and arp_announce to avoid answering ARP queries from kube-ipvs0 interface
# must be set to true for MetalLB to work
kube_proxy_strict_arp: true
# Custom search domains to be added in addition to the default cluster search domains
searchdomains:
- lan
# Fetch kubeconfig for cluster access
kubeconfig_localhost: true
## Automatically renew K8S control plane certificates on first Monday of each month
auto_renew_certificates: true
ansible-playbook -i inventory/home cluster.yml -b
Export KUBECONFIG for cluster access and get nodes status:
export KUBECONFIG=$(pwd)/inventory/home/artifacts/admin.conf
kubectl get nodes