This article proposes to automate the installation of Kubernetes 1.13 on Raspberry Pi via Ansible with a homemade role.
Prerequisites
- Have installed Raspbian on the target Raspberry Pis (at least 2), the procedure is available on a previous article Automated Initialization and Securing of Raspbian on Raspberry Pi
Installation of Docker + Kubernetes
Retrieval of the role
I developed an ansible role for this automation, here’s how to retrieve it:
## Pré-requis Docker (rôle fait maison)git clone https://gitlab.com/jls42/ansible-rpi-docker.git roles/ansible-rpi-docker## Rôle pour l'installation de Kubernetesgit clone https://gitlab.com/jls42/ansible-rpi-k8s.git roles/ansible-rpi-k8sFor more details go see the documentation on ansible-rpi-k8s
Creation of the inventory file named inventory
In this inventory example several Raspberry Pi 1, one has the ip 192.168.1.190 and the other the ip 192.168.1.191
In the child group (here rpi-k8s), the master must be declared first
[rpi1]192.168.1.190 k8s_master=true
[rpi2]192.168.1.191
[rpi-k8s:children]rpi1rpi2Preparation of the playbook k8s-rpi.yml
---- name: "Installation de Docker sur le Raspberry Pi" hosts: rpi-k8s remote_user: "pi" roles: - roles/ansible-rpi-docker vars: docker_version: 18.06.1~ce~3-0~raspbian
- name: "Installation de k8s sur le Raspberry Pi" hosts: rpi-k8s remote_user: "pi" roles: - roles/ansible-rpi-k8s vars: k8s_version: "1.13.0-00" k8s_master_token: "abcdef.0123456789abcdef" k8s_cluster_group: rpi-k8sDeployment of Docker and Kubernetes
The ansible-rpi-docker and ansible-rpi-k8s roles will be launched in sequence.
In the case where docker is already installed, it is possible to only play ansible-rpi-k8s.
export ANSIBLE_HOST_KEY_CHECKING=Falseansible-playbook -b -i inventory k8s-rpi.ymlWhich gives:
jls42@boo:~/rpi$ ansible-playbook -b -i inventory k8s-rpi.yml
PLAY [Installation de Docker sur le Raspberry Pi] ******************************************************************************************************************************************************************************************
TASK [Gathering Facts] *********************************************************************************************************************************************************************************************************************Sunday 09 December 2018 03:26:30 +0100 (0:00:00.051) 0:00:00.051 *******ok: [192.168.1.190]ok: [192.168.1.191]
TASK [roles/ansible-rpi-docker : Installe les paquets nécessaire à l'utilisation d'un dépôt HTTPS] *****************************************************************************************************************************************Sunday 09 December 2018 03:26:33 +0100 (0:00:03.476) 0:00:03.527 *******changed: [192.168.1.190] => (item=[u'apt-transport-https', u'ca-certificates', u'curl', u'gnupg2', u'software-properties-common'])changed: [192.168.1.191] => (item=[u'apt-transport-https', u'ca-certificates', u'curl', u'gnupg2', u'software-properties-common'])
TASK [roles/ansible-rpi-docker : Ajoute la clef officielle du dépôt Docker] ****************************************************************************************************************************************************************Sunday 09 December 2018 03:27:12 +0100 (0:00:39.274) 0:00:42.802 *******changed: [192.168.1.190]changed: [192.168.1.191]
TASK [roles/ansible-rpi-docker : Ajoute le dépôt Docker] ***********************************************************************************************************************************************************************************Sunday 09 December 2018 03:27:17 +0100 (0:00:04.747) 0:00:47.549 *******changed: [192.168.1.190]changed: [192.168.1.191]
TASK [roles/ansible-rpi-docker : Installe le paquet docker-ce] *****************************************************************************************************************************************************************************Sunday 09 December 2018 03:27:27 +0100 (0:00:10.238) 0:00:57.788 *******changed: [192.168.1.190]changed: [192.168.1.191]
TASK [roles/ansible-rpi-docker : Installe python-pip] **************************************************************************************************************************************************************************************Sunday 09 December 2018 03:29:04 +0100 (0:01:36.285) 0:02:34.074 *******changed: [192.168.1.191]changed: [192.168.1.190]
TASK [roles/ansible-rpi-docker : Installe docker-compose via pip] **************************************************************************************************************************************************************************Sunday 09 December 2018 03:30:06 +0100 (0:01:02.641) 0:03:36.715 *******changed: [192.168.1.191]changed: [192.168.1.190]
TASK [roles/ansible-rpi-docker : Configure Docker pour qu'il démarre au boot] **************************************************************************************************************************************************************Sunday 09 December 2018 03:31:03 +0100 (0:00:56.384) 0:04:33.099 *******ok: [192.168.1.190]ok: [192.168.1.191]
TASK [roles/ansible-rpi-docker : Ajoute l'utilisateur pi dans le groupe docker] ************************************************************************************************************************************************************Sunday 09 December 2018 03:31:04 +0100 (0:00:01.075) 0:04:34.175 *******changed: [192.168.1.191]changed: [192.168.1.190]
TASK [roles/ansible-rpi-docker : Supprime la swap] *****************************************************************************************************************************************************************************************Sunday 09 December 2018 03:31:05 +0100 (0:00:01.348) 0:04:35.523 *******changed: [192.168.1.190]changed: [192.168.1.191]PLAY [Installation de k8s sur le Raspberry Pi] *********************************************************************************************************************************************************************************************
TASK [Gathering Facts] *********************************************************************************************************************************************************************************************************************Sunday 09 December 2018 03:31:07 +0100 (0:00:02.096) 0:04:37.620 *******ok: [192.168.1.190]ok: [192.168.1.191]
TASK [roles/ansible-rpi-k8s : Installe les paquets nécessaires à l'utilisation d'un dépôt HTTPS] *******************************************************************************************************************************************Sunday 09 December 2018 03:31:09 +0100 (0:00:01.934) 0:04:39.555 *******ok: [192.168.1.190] => (item=[u'apt-transport-https', u'ca-certificates', u'curl', u'gnupg2', u'software-properties-common'])ok: [192.168.1.191] => (item=[u'apt-transport-https', u'ca-certificates', u'curl', u'gnupg2', u'software-properties-common'])
TASK [roles/ansible-rpi-k8s : Supprime la swap] ********************************************************************************************************************************************************************************************Sunday 09 December 2018 03:31:15 +0100 (0:00:05.740) 0:04:45.295 *******ok: [192.168.1.190]ok: [192.168.1.191]
TASK [roles/ansible-rpi-k8s : Active cgroup_memory] ****************************************************************************************************************************************************************************************Sunday 09 December 2018 03:31:16 +0100 (0:00:00.966) 0:04:46.262 *******changed: [192.168.1.190]changed: [192.168.1.191]
TASK [roles/ansible-rpi-k8s : Redémarre] ***************************************************************************************************************************************************************************************************Sunday 09 December 2018 03:31:17 +0100 (0:00:01.032) 0:04:47.295 *******changed: [192.168.1.191]changed: [192.168.1.190]
TASK [roles/ansible-rpi-k8s : Attente suite au redémarrage] ********************************************************************************************************************************************************************************Sunday 09 December 2018 03:31:18 +0100 (0:00:01.667) 0:04:48.962 *******ok: [192.168.1.190]ok: [192.168.1.191]
TASK [roles/ansible-rpi-k8s : Ajoute la clef officielle Kubernetes] ************************************************************************************************************************************************************************Sunday 09 December 2018 03:32:19 +0100 (0:01:00.447) 0:05:49.409 *******changed: [192.168.1.190]changed: [192.168.1.191]
TASK [roles/ansible-rpi-k8s : Ajoute le dépôt stable de Kubernetes] ************************************************************************************************************************************************************************Sunday 09 December 2018 03:32:25 +0100 (0:00:06.282) 0:05:55.692 *******changed: [192.168.1.190]changed: [192.168.1.191]
TASK [roles/ansible-rpi-k8s : Installe kubeadm, kubelet and kubectl] ***********************************************************************************************************************************************************************Sunday 09 December 2018 03:32:45 +0100 (0:00:20.277) 0:06:15.970 *******changed: [192.168.1.190] => (item=[u'kubeadm=1.13.0-00', u'kubelet=1.13.0-00', u'kubectl=1.13.0-00'])changed: [192.168.1.191] => (item=[u'kubeadm=1.13.0-00', u'kubelet=1.13.0-00', u'kubectl=1.13.0-00'])
TASK [roles/ansible-rpi-k8s : Configure kubelet pour qu'il démarre au boot] ****************************************************************************************************************************************************************Sunday 09 December 2018 03:34:25 +0100 (0:01:39.895) 0:07:55.865 *******ok: [192.168.1.191]ok: [192.168.1.190]
TASK [roles/ansible-rpi-k8s : Installe les paquets nécessaires pour l'utilisation du client CIFS] ******************************************************************************************************************************************Sunday 09 December 2018 03:34:26 +0100 (0:00:01.029) 0:07:56.894 *******changed: [192.168.1.191] => (item=[u'cifs-utils', u'util-linux', u'coreutils', u'jq'])changed: [192.168.1.190] => (item=[u'cifs-utils', u'util-linux', u'coreutils', u'jq'])
TASK [roles/ansible-rpi-k8s : Ajout le répertoire d'addons cifs] ***************************************************************************************************************************************************************************Sunday 09 December 2018 03:34:40 +0100 (0:00:13.835) 0:08:10.730 *******changed: [192.168.1.191]changed: [192.168.1.190]
TASK [roles/ansible-rpi-k8s : Télécharge le plugin CIFS] ***********************************************************************************************************************************************************************************Sunday 09 December 2018 03:34:41 +0100 (0:00:01.051) 0:08:11.782 *******changed: [192.168.1.191]changed: [192.168.1.190]TASK [roles/ansible-rpi-k8s : Installe les paquets nécessaires à l'utilisation du client GlusterFS] *********************************************************************************************************************************************************Sunday 09 December 2018 03:34:43 +0100 (0:00:01.740) 0:08:13.522 *******changed: [192.168.1.190] => (item=[u'glusterfs-client'])changed: [192.168.1.191] => (item=[u'glusterfs-client'])
TASK [roles/ansible-rpi-k8s : Définie l'ip du maître] **************************************************************************************************************************************************************************************Sunday 09 December 2018 03:35:16 +0100 (0:00:32.640) 0:08:46.162 *******ok: [192.168.1.190]ok: [192.168.1.191]
TASK [roles/ansible-rpi-k8s : Vérifie si le master a déjà été configuré] *******************************************************************************************************************************************************************Sunday 09 December 2018 03:35:16 +0100 (0:00:00.113) 0:08:46.276 *******skipping: [192.168.1.191]ok: [192.168.1.190]
TASK [roles/ansible-rpi-k8s : Définie l'initialisation du cluster à oui] *******************************************************************************************************************************************************************Sunday 09 December 2018 03:35:17 +0100 (0:00:01.074) 0:08:47.350 *******skipping: [192.168.1.191]ok: [192.168.1.190]
TASK [roles/ansible-rpi-k8s : Définie l'initialisation du cluster à non] *******************************************************************************************************************************************************************Sunday 09 December 2018 03:35:17 +0100 (0:00:00.113) 0:08:47.464 *******skipping: [192.168.1.190]skipping: [192.168.1.191]
TASK [roles/ansible-rpi-k8s : Définie l'initialisation du/des noeud(s)] ********************************************************************************************************************************************************************Sunday 09 December 2018 03:35:17 +0100 (0:00:00.097) 0:08:47.562 *******skipping: [192.168.1.190]ok: [192.168.1.191]
TASK [roles/ansible-rpi-k8s : Initialise le cluster Kubernetes sur le maître] **************************************************************************************************************************************************************Sunday 09 December 2018 03:35:17 +0100 (0:00:00.181) 0:08:47.743 *******skipping: [192.168.1.191]changed: [192.168.1.190]
TASK [roles/ansible-rpi-k8s : Attend la fin de l'initialisation] ***************************************************************************************************************************************************************************Sunday 09 December 2018 03:35:19 +0100 (0:00:01.598) 0:08:49.342 *******skipping: [192.168.1.191]FAILED - RETRYING: Attend la fin de l'initialisation (42 retries left).FAILED - RETRYING: Attend la fin de l'initialisation (41 retries left).FAILED - RETRYING: Attend la fin de l'initialisation (40 retries left).FAILED - RETRYING: Attend la fin de l'initialisation (39 retries left).FAILED - RETRYING: Attend la fin de l'initialisation (38 retries left).FAILED - RETRYING: Attend la fin de l'initialisation (37 retries left).FAILED - RETRYING: Attend la fin de l'initialisation (36 retries left).FAILED - RETRYING: Attend la fin de l'initialisation (35 retries left).FAILED - RETRYING: Attend la fin de l'initialisation (34 retries left).FAILED - RETRYING: Attend la fin de l'initialisation (33 retries left).FAILED - RETRYING: Attend la fin de l'initialisation (32 retries left).changed: [192.168.1.190]
TASK [roles/ansible-rpi-k8s : Crée le répertoire kubernetes /home/pi/.kube/] ***************************************************************************************************************************************************************Sunday 09 December 2018 03:41:02 +0100 (0:05:43.339) 0:14:32.682 *******skipping: [192.168.1.191]changed: [192.168.1.190]
TASK [roles/ansible-rpi-k8s : Copie le fichier /etc/kubernetes/admin.conf vers /home/pi/.kube/config] **************************************************************************************************************************************Sunday 09 December 2018 03:41:03 +0100 (0:00:00.948) 0:14:33.630 *******skipping: [192.168.1.191]changed: [192.168.1.190]
TASK [roles/ansible-rpi-k8s : Récupère la configuration kubernetes dans un répertoire local] ***********************************************************************************************************************************************Sunday 09 December 2018 03:41:04 +0100 (0:00:01.030) 0:14:34.661 *******skipping: [192.168.1.191]changed: [192.168.1.190]TASK [roles/ansible-rpi-k8s : Jointure de(s) noeud(s) avec le maître] **********************************************************************************************************************************************************************Sunday 09 December 2018 03:41:05 +0100 (0:00:01.016) 0:14:35.678 *******skipping: [192.168.1.190]changed: [192.168.1.191]
TASK [roles/ansible-rpi-k8s : Installation des pods réseaux avec Weave] ********************************************************************************************************************************************************************Sunday 09 December 2018 03:41:12 +0100 (0:00:06.567) 0:14:42.245 *******skipping: [192.168.1.191]changed: [192.168.1.190]
PLAY RECAP *********************************************************************************************************************************************************************************************************************************192.168.1.190 : ok=33 changed=23 unreachable=0 failed=0192.168.1.191 : ok=27 changed=18 unreachable=0 failed=0
Sunday 09 December 2018 03:41:18 +0100 (0:00:05.893) 0:14:48.139 *******===============================================================================roles/ansible-rpi-k8s ------------------------------------------------- 608.58sroles/ansible-rpi-docker ---------------------------------------------- 274.09ssetup ------------------------------------------------------------------- 5.41s~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~total ----------------------------------------------------------------- 888.09sPlaybook run took 0 days, 0 hours, 14 minutes, 48 secondsVerification
We connect to the Raspberry Pi to confirm the proper installation of Kubernetes
(the nodes will not necessarily all be in “Ready” state right away, it can take a few minutes)
jls42@boo:~/rpi$ ssh pi@192.168.1.190Linux rpi1 4.14.79-v7+ #1159 SMP Sun Nov 4 17:50:20 GMT 2018 armv7l
The programs included with the Debian GNU/Linux system are free software;the exact distribution terms for each program are described in theindividual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extentpermitted by applicable law.Last login: Sun Dec 9 02:41:12 2018 from 192.168.1.42pi@rpi1:~ $ kubectl get nodes -o wideNAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIMErpi1 Ready master 2m3s v1.13.0 192.168.1.190 <none> Raspbian GNU/Linux 9 (stretch) 4.14.79-v7+ docker://18.6.1rpi2 Ready <none> 85s v1.13.0 192.168.1.191 <none> Raspbian GNU/Linux 9 (stretch) 4.14.79-v7+ docker://18.6.1pi@rpi1:~ $And knowing that the k8s configuration has been copied locally, it is also possible to launch kubectl on the local machine (if the latter is installed).
Enjoy !
This document was translated from fr version to en language using the claude-3-opus-20240229 model. For more information on the translation process, see https://gitlab.com/jls42/ai-powered-markdown-translator