|
| 1 | +Ansible Playbook for k3s and Karmada Installation |
| 2 | +================================================= |
| 3 | + |
| 4 | +This document provides a step-by-step guide to using the provided Ansible playbook to install and configure k3s across multiple clusters. Additionally, it includes instructions for setting up Karmada, a multi-cluster management tool. |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | +## Table of Contents |
| 9 | + |
| 10 | +1. [Prerequisites](#prerequisites) |
| 11 | +2. [Installation Steps](#installation-steps) |
| 12 | + * [Setting Up Ansible](#setting-up-ansible) |
| 13 | + * [Inventory Configuration](#inventory-configuration) |
| 14 | + * [k3s Installation Playbook](#k3s-installation-playbook) |
| 15 | + * [Karmada Installation Playbook](#karmada-installation-playbook) |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | +## Prerequisites |
| 20 | +Before proceeding, ensure the following: |
| 21 | + |
| 22 | +- **Ansible Installed:** Install Ansible on the control node. |
| 23 | +- **SSH Access:** Ensure the control node has SSH access to all target nodes. |
| 24 | +- **Python 3 Installed:** Ensure Python 3 is available on all nodes. |
| 25 | +- **Supported OS:** The playbooks are tested on Ubuntu 22.04 LTS. Other Linux distributions may require adjustments. |
| 26 | +- **Multiple Machines:** At least one machine for the management cluster (Karmada) and others for k3s clusters (master and worker nodes). |
| 27 | + |
| 28 | +## Installation Steps |
| 29 | +To set up Ansible, run the follow commands: |
| 30 | + |
| 31 | +1) Update System Packages to latest version. |
| 32 | + |
| 33 | + ``` |
| 34 | + sudo apt update && sudo apt upgrade -y |
| 35 | + ``` |
| 36 | +2) Install essential packages that Ansible relies on: |
| 37 | + |
| 38 | + ``` |
| 39 | + sudo apt install -y python3 software-properties-common |
| 40 | + ``` |
| 41 | +3) Install Ansible. |
| 42 | +
|
| 43 | + ``` |
| 44 | + sudo apt install -y ansible |
| 45 | + ``` |
| 46 | +4) After installation, confirm that Ansible is installed and working correctly by checking its version: |
| 47 | + ``` |
| 48 | + ansible --version |
| 49 | + ``` |
| 50 | +Example output: |
| 51 | +
|
| 52 | +``` |
| 53 | + ansible 2.10.8 |
| 54 | + config file = None |
| 55 | + configured module search path = ['/home/pmavrikos/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] |
| 56 | + ansible python module location = /usr/lib/python3/dist-packages/ansible |
| 57 | + executable location = /usr/bin/ansible |
| 58 | + python version = 3.10.12 (main, Feb 4 2025, 14:57:36) [GCC 11.4.0] |
| 59 | +``` |
| 60 | +
|
| 61 | +### Setting Up Ansible |
| 62 | +Once Ansible is installed, you need to set up your project by cloning the repository and configuring the necessary files. |
| 63 | +
|
| 64 | +
|
| 65 | +**Clone the Repository and navigate to the project directory** |
| 66 | +
|
| 67 | +``` |
| 68 | +git clone https://github.com/nubificus/mlsysopsansible.git |
| 69 | +cd mlsysopsansible |
| 70 | +``` |
| 71 | +
|
| 72 | +### Inventory Configuration |
| 73 | +The inventory.yml file contains the list of target nodes where k3s and Karmada will be installed. Before running the playbooks, update this file with your specific setup. |
| 74 | +
|
| 75 | +
|
| 76 | +**Understand the Structure** |
| 77 | +
|
| 78 | +The file is divided into: |
| 79 | + |
| 80 | +- **management_cluster:** The machine where Karmada will be installed (usually one node). |
| 81 | +- **cluster1:** A k3s cluster with: |
| 82 | + - **master_nodes:** Control-plane nodes (you can have one or more for high availability). |
| 83 | + - **worker_nodes:** Worker nodes that run workloads. |
| 84 | + |
| 85 | +**Mandatory fields to update:** |
| 86 | +
|
| 87 | +- `ansible_host`: Replace `xxxxx` with the IP address of each target node. |
| 88 | +- `ansible_user`: Enter the SSH username for logging into the machine |
| 89 | +- `ansible_ssh_private_key_file`: Provide the full path to your SSH private key on the control machine. |
| 90 | +- `ansible_python_interpreter`: Ensure it points to a valid Python 3 interpreter path on each target node. |
| 91 | +- `k3s_cluster_name`: Specify a meaningful cluster name. |
| 92 | +- `pod_cidr` and `service_cidr`: Customize network ranges for pods and services (they must not overlap between clusters). |
| 93 | +
|
| 94 | +**Example Configuration** |
| 95 | +
|
| 96 | +``` |
| 97 | +all: |
| 98 | + children: |
| 99 | + management_cluster: # <-- In this vm will be karmada |
| 100 | + hosts: |
| 101 | + mls00: # <-- Change with your vm name |
| 102 | + ansible_host: x.x.x.x # <-- Update with the correct IP address |
| 103 | + ansible_user: mlsysops |
| 104 | + ansible_ssh_private_key_file: /home/xxxxxx/.ssh/id_rsa # <-- Update |
| 105 | + ansible_python_interpreter: /usr/bin/python3 |
| 106 | + k3s_cluster_name: management |
| 107 | + pod_cidr: "x.x.x.x/x" |
| 108 | + service_cidr: "x.x.x.x/x" |
| 109 | + |
| 110 | + cluster1: |
| 111 | + children: |
| 112 | + master_nodes: |
| 113 | + hosts: |
| 114 | + mls01: # <-- Change with your master node vm name |
| 115 | + ansible_host: x.x.x.x # <-- Update with the correct IP address |
| 116 | + ansible_user: mlsysops |
| 117 | + ansible_ssh_private_key_file: /home/xxxxxxxx/.ssh/id_rsa # <-- Update |
| 118 | + ansible_python_interpreter: /usr/bin/python3 |
| 119 | + k3s_cluster_name: cluster1 |
| 120 | + pod_cidr: "x.x.x.x/x" |
| 121 | + service_cidr: "x.x.x.x/x" |
| 122 | + worker_nodes: |
| 123 | + hosts: |
| 124 | + mls02: |
| 125 | + ansible_host: x.x.x.x # <-- Update with the correct IP address |
| 126 | + ansible_user: mlsysops |
| 127 | + ansible_ssh_private_key_file: /home/xxxxxxxxx/.ssh/id_rsa # <-- Update |
| 128 | + ansible_python_interpreter: /usr/bin/python3 |
| 129 | + k3s_cluster_name: cluster1 |
| 130 | + mls03: |
| 131 | + ansible_host: x.x.x.x # <-- Update with the correct IP address |
| 132 | + ansible_user: mlsysops |
| 133 | + ansible_ssh_private_key_file: /home/xxxxxxxxxxx/.ssh/id_rsa # <-- Update |
| 134 | + ansible_python_interpreter: /usr/bin/python3 |
| 135 | + k3s_cluster_name: cluster1 |
| 136 | +``` |
| 137 | +
|
| 138 | +**Verify** |
| 139 | +
|
| 140 | +After editing inventory.yml, save the file and check it for errors. You can test the inventory with: |
| 141 | +
|
| 142 | +``` |
| 143 | +ansible-inventory -i inventory.yml --list |
| 144 | +``` |
| 145 | +This shows all nodes Ansible will target. |
| 146 | +
|
| 147 | +### k3s Installation Playbook |
| 148 | +The k3s-install.yml playbook automates the deployment of a multi-node k3s cluster. |
| 149 | +
|
| 150 | +- Ensure the inventory file is updated before running the playbook. |
| 151 | +- Execute the playbook to install k3s across all defined nodes. |
| 152 | +- After installation, the kubeconfig file for each cluster is stored at: |
| 153 | +``` |
| 154 | +/home/<ANSIBLE_USER>/.kube/config |
| 155 | +``` |
| 156 | +on the control-plane node. |
| 157 | +
|
| 158 | +To run [k3s-install.yml](k3s-install.yml) playbook, use the following command: |
| 159 | +``` |
| 160 | +ansible-playbook -i inventory.yml k3s-install.yml |
| 161 | +``` |
| 162 | +
|
| 163 | +### Karmada Installation Playbook |
| 164 | +The karmada-install.yml playbook sets up Karmada, a multi-cluster management system. |
| 165 | +
|
| 166 | +To run [karmada-install.yml](karmada-install.yml), playbook, use the following command: |
| 167 | +``` |
| 168 | +ansible-playbook -i inventory.yml karmada-install.yml |
| 169 | +``` |
| 170 | +
|
| 171 | +
|
| 172 | +
|
0 commit comments