Configure Kubespray Kubernetes

Tech Stack

  • Ansible

  • Kubeadm

  • Python3

Common Problems

Clone Kubespray Repository

$ git clone https://github.com/kubernetes-sigs/kubespray.git
$ cd kubespray

Configure Pip for Python 3.10

$ curl -sS https://bootstrap.pypa.io/get-pip.py | python3.10
$ pip3.10 -V
pip 23.2.1 from /usr/local/lib/python3.10/site-packages/pip (python 3.10)

Install Requirements Dependencies

$ sudo apt install wget libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev build-essential
$ sudo pip3.10 install -r requirements.txt

Configure Hosts

$ cp -rfp inventory/sample inventory/mycluster
$ nano inventory/mycluster/inventory.ini
# ## Configure 'ip' variable to bind kubernetes services on a
# ## different ip than the default iface
# ## We should set etcd_member_name for etcd cluster. The node that is not a etcd member do not need to set the value, or can set the empty string value.
[all]
master ansible_host=10.10.10.86  ip=10.10.10.86 etcd_member_name=etcd1
worker1 ansible_host=10.10.10.47  ip=10.10.10.47 etcd_member_name=
worker2 ansible_host=10.10.10.84  ip=10.10.10.84 etcd_member_name=
# node4 ansible_host=95.54.0.15  # ip=10.3.0.4 etcd_member_name=etcd4
# node5 ansible_host=95.54.0.16  # ip=10.3.0.5 etcd_member_name=etcd5
# node6 ansible_host=95.54.0.17  # ip=10.3.0.6 etcd_member_name=etcd6

# ## configure a bastion host if your nodes are not directly reachable
# [bastion]
# bastion ansible_host=x.x.x.x ansible_user=some_user

[kube_control_plane]
master
# node2
# node3

[etcd]
master
# node2
# node3

[kube_node]
worker1
worker2
# node4
# node5
# node6

[calico_rr]

[k8s_cluster:children]
kube_control_plane
kube_node
calico_rr

Deploy Kubernetes

$ ansible-playbook -i inventory/mycluster/inventory.ini --become --user=root --become-user=root cluster.yml

Get Kube Config in Master Node

$ scp root@master:~/.kube/config ~/.kube/config
# edit the ip address 127.0.0.1 to master local ip
$ export KUBECONFIG=~/.kube/config