This guide outlines the steps to deploy Kubernetes on a target machine or cluster using Ansible. The playbook automates the installation and configuration of Kubernetes components on the target system.
Before you begin, ensure the following prerequisites are met:
-
A control machine where Ansible is installed.
You can install Ansible using the following commands:- For Ubuntu/Debian:
sudo apt update sudo apt install ansible
- For Ubuntu/Debian:
-
A target machine (or multiple nodes) where:
- Python 3 is installed and accessible.
sudoprivileges are available for the user running the Ansible playbook.
Create an inventory file to define the hosts (target machine) for Kubernetes deployment. The following example shows how to configure the target machine IP:
all:
children:
kubernetes:
hosts:
localhost:
ansible_connection: local
ansible_python_interpreter: /usr/bin/python3Clone the Kubernetes deployment project from the repository (or use your own project):
git clone https://github.com/mlouguid/k8b-Ansible.git
cd k8b-Ansible
Ensure your kubernetes role has the following directory structure:
roles/
└── kubernetes/
├── tasks/
│ ├── main.yml
│ ├── install_k8s.yml
│ ├── containerd.yml
│ └── kube_prereqs.yml
├── handlers/
└── main.yml
ansible-playbook kubernetes_playbook.yml -i inventories/local/hosts --limit=kubernetes --ask-become-pass
