Ansible playbooks that creates a Kubernetes 1.26 cluster of Openstack instances running Ubuntu 22.04 LTS.
- Ansible and Python3 installed on the local machine (
# yum install ansible
). - An OpenStack security group for SSH and ICMP access named
SSH and ICMP
. - Terraform and OpenStack CLI tools installed on the local machine.
$ cp keystone_rc.sh.example keystone_rc.sh
$ chmod 0600 keystone_rc.sh
The keystone_rc.sh
file will contain your API password so be careful with where you store it, and make sure it's private. Once it is, add your API password for OpenStack. You can also modify the worker count, network version, etc.
Then load the file to the shell environment on the local computer:
$ source keystone_rc.sh
SSH key pairs are tied to users, and the dashboard and API user are technically different. The SSH public key therefore has to be added to the API user explicitly:
$ openstack keypair create --public-key /path/to/keyfile.pub k8s-nodes
Change directory to tf-project
and initialize Terraform:
$ cd tf-project
$ terraform init
Then verify, plan and apply with Terraform:
$ terraform validate
$ terraform plan
$ terraform apply
Change directory back to the main directory:
$ cd ..
After creating the cluster on OpenStack, Terraform created a ansible_inventory
file in the tf-project
directory. It contains the machine names and IP addresses for the cluster.
Alternatively, a hosts
file can be created. Add the IP address to the master and workers in the hosts
file using a text editor, and make sure each machine can be reached using SSH:
$ cp hosts.example hosts
$ vim hosts
$ ansible-playbook -i tf-project/ansible_inventory playbooks/kube-dependencies.yml
$ ansible-playbook -i tf-project/ansible_inventory playbooks/master.yml
ssh
onto the master and verify that the master node get status Ready
:
$ ssh -i /path/to/ssh-key ubuntu@<master_ip>
ubuntu@k8s-master-1:~$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8s-master-1 Ready control-plane 63s v1.26.2
$ ansible-playbook -i tf-project/ansible_inventory playbooks/workers.yml
Run kubectl get nodes
once more on the master node to verify the worker nodes got added.
Edit cluster settings in the keystone_rc.sh
and source it again before re-running terraform apply
to change the cluster, before re-running the playbooks to add new workers.
Destroy the cluster when done:
$ cd tf-project
$ terraform destroy
Based on bsder's Digital Ocean tutorial «How To Create a Kubernetes 1.11 Cluster Using Kubeadm on Ubuntu 18.04».
See the LICENSE file for license rights and limitations (MIT).