├── .gitignore ├── README.md └── install.yaml /.gitignore: -------------------------------------------------------------------------------- 1 | hosts 2 | .idea/* 3 | metallb-config.yaml 4 | .DS_Store 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # kubernetes-deploy 2 | 3 | Ansible playbooks for deploying a 3 node Kubernetes cluster with 1 master node and 2 worker nodes. The default user 4 | that will be used is `k8sadmin` so this user must exist on your servers (with sudo permissions). 5 | 6 | # Ansible setup 7 | 8 | Your local machine will need to have Ansible installed. This can be done with the following command: 9 | 10 | ``` 11 | brew install ansible 12 | ``` 13 | 14 | # Pre-requisites 15 | 16 | This project assumes that you have 3 Ubuntu servers set up and configured with access via ssh keys and configured in 17 | your `~/.ssh/config` file. 18 | 19 | Because the installation of Kubernetes requires the ability to run commands as root, you will need to be able to 20 | sudo on the servers without a password. 21 | 22 | This can be done by running the following command on each of the servers: 23 | 24 | ``` 25 | echo " ALL=(ALL) NOPASSWD:ALL" | sudo tee /etc/sudoers.d/ 26 | ``` 27 | 28 | The ansible playbooks deploy metallb as the load balancer for the cluster. This requires that you have a range of IP 29 | defined in a config map. 30 | 31 | Create a file in the repository named `metallb-config.yaml` with the following contents (replacing the IP addresses): 32 | 33 | ``` 34 | apiVersion: metallb.io/v1beta1 35 | kind: IPAddressPool 36 | metadata: 37 | name: default 38 | namespace: metallb-system 39 | spec: 40 | addresses: 41 | - 192.168.0.150-192.168.0.170 42 | --- 43 | apiVersion: metallb.io/v1beta1 44 | kind: L2Advertisement 45 | metadata: 46 | name: l2advertisement 47 | namespace: metallb-system 48 | spec: 49 | ipAddressPools: 50 | - default 51 | ``` 52 | 53 | # Host configuration 54 | 55 | ``` 56 | Host master 57 | HostName 58 | User ubuntu 59 | 60 | Host worker-1 61 | HostName 62 | User ubuntu 63 | 64 | Host worker-2 65 | HostName 66 | User ubuntu 67 | ``` 68 | 69 | You will need to create a `hosts` file in the root of the project with the following contents: 70 | 71 | ``` 72 | [master] 73 | 74 | 75 | [worker] 76 | 77 | 78 | ``` 79 | 80 | You can then test that Ansible can connect to the servers with the following command: 81 | 82 | ``` 83 | ansible -i hosts all -m ping 84 | ``` 85 | 86 | # Running the playbooks 87 | 88 | The playbooks can be run with the following command: 89 | 90 | ``` 91 | ansible-playbook -i hosts install.yaml 92 | ``` 93 | 94 | Once the playbook has completed you should have a fully functional Kubernetes cluster! -------------------------------------------------------------------------------- /install.yaml: -------------------------------------------------------------------------------- 1 | # Ansible playbook to install the required packages on the master and worker nodes 2 | - hosts: "master, worker" 3 | become: yes # Run as root 4 | 5 | tasks: 6 | - name: Configure containerd 7 | shell: | 8 | sudo tee /etc/modules-load.d/containerd.conf <