Automate the provisioning of a new bare-metal multi-node Kubernetes cluster with Ansible. Uses all the industry-standard tools for an enterprise-grade cluster.
- Ansible: an open source IT automation engine.
- ContainerD: an industry-standard container runtime.
- Kubernetes: an open-source system for automating deployment, scaling, and management of containerized applications.
- Calico: an open source networking and network security solution for containers (CNI).
- MetalLB: a bare metal load-balancer for Kubernetes.
- Nginx: an Ingress controller.
- Dashboard: a web-based Kubernetes user interface.
- A Linux machine with a superuser privileges and pre-installed Ansible.
- Ubuntu machines that are intended to become part of the new Kubernetes cluster. Make sure that your SSH key is already installed on the machines by running the following command:
$ ssh-copy-id <The remote username>@<The IPv4 address of the remote machine>
- Clone this Git repository to your local working station:
$ git clone https://github.com/ArielLahiany/kubernetes.git
- Change directory to the root directory of the project:
$ cd kubernetes
- Edit the values of the default variables to your requirements:
$ vim defaults/main.yaml
- Edit the Ansible inventory file to your requirements:
$ vim inventory/hosts.ini
- Edit the Ansible Vault variables file to your requirements:
$ vim vault/main.yaml
- Use Ansible Vault command line to encrypt the Vault variables file:
$ ansible-vault encrypt vault/main.yaml
- Run the Ansible Playbook:
$ ansible-playbook -i inventory/hosts.ini -K --ask-vault-pass playbooks/cluster.yaml
- Get the IPv4 address of the deployed Nginx ingress controller:
$ kubectl get services --all-namespaces
NAMESPACE | NAME | TYPE | CLUSTER-IP | EXTERNAL-IP | PORT(S) | AGE |
---|---|---|---|---|---|---|
ingress-nginx | ingress-nginx-controller | LoadBalancer | 10.96.91.254 | IPv4 address | 80:31478/TCP,443:31633/TCP | 149m |
- Edit the hosts file on your local working station to include the path to the dashboard:
$ sudo vim /etc/hosts
<IPv4 address of the Nginx ingress controller> <dashboard.prefix>.<cluster.domain>
For example:
192.168.14.195 dashboard.cluster.local
- During the deployment process the Ansible Playbook is generating a new admin token for the dashboard. Get it by running the following command:
$ cat /home/<Your username>/.kube/dashboard
- Browse to the address you've just added to the hosts file.
- Supply the created admin token in order of login into the dashboard.