Este artículo propone la automatización de la instalación de Kubernetes 1.13 en Raspberry Pi mediante Ansible con un rol hecho en casa.

Requisitos previos

Instalación de Docker + Kubernetes

Recuperación del rol
He desarrollado un rol ansible para esta automatización, aquí está cómo recuperarlo:

## 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 Kubernetes
git clone https://gitlab.com/jls42/ansible-rpi-k8s.git roles/ansible-rpi-k8s

Para más detalles, vea la documentación en ansible-rpi-k8s

Creación del archivo de inventario llamado inventory
En este ejemplo de inventario, hay varios Raspberry Pi 1, uno tiene la ip 192.168.1.190 y el otro tiene la ip 192.168.1.191
En el grupo hijo (aquí rpi-k8s), el maestro debe declararse primero.

[rpi1]
192.168.1.190 k8s_master=true

[rpi2]
192.168.1.191

[rpi-k8s:children]
rpi1
rpi2

Preparación del libro de trabajo 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-k8s

Despliegue de Docker y Kubernetes
Los roles ansible-rpi-docker y ansible-rpi-k8s se ejecutarán uno detrás del otro.
En caso de que docker ya esté instalado, solo se debe ejecutar ansible-rpi-k8s.

export ANSIBLE_HOST_KEY_CHECKING=False
ansible-playbook -b -i inventory k8s-rpi.yml

Lo que da:

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=0   
192.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.58s
roles/ansible-rpi-docker ---------------------------------------------- 274.09s
setup ------------------------------------------------------------------- 5.41s
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
total ----------------------------------------------------------------- 888.09s
Playbook run took 0 days, 0 hours, 14 minutes, 48 seconds

Verificación

Nos conectamos al Raspberry Pi para confirmar la buena instalación de Kubernetes
(los nodos no estarán necesariamente todos en estado “Listo” de inmediato, puede tardar unos minutos)

jls42@boo:~/rpi$ ssh pi@192.168.1.190
Linux 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 the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Sun Dec  9 02:41:12 2018 from 192.168.1.42
pi@rpi1:~ $ kubectl get nodes -o wide
NAME   STATUS   ROLES    AGE    VERSION   INTERNAL-IP     EXTERNAL-IP   OS-IMAGE                         KERNEL-VERSION   CONTAINER-RUNTIME
rpi1   Ready    master   2m3s   v1.13.0   192.168.1.190   <none>        Raspbian GNU/Linux 9 (stretch)   4.14.79-v7+      docker://18.6.1
rpi2   Ready    <none>   85s    v1.13.0   192.168.1.191   <none>        Raspbian GNU/Linux 9 (stretch)   4.14.79-v7+      docker://18.6.1
pi@rpi1:~ $

Y sabiendo que la configuración k8s se ha copiado localmente, también es posible ejecutar kubectl en el equipo local (si este último está instalado).

¡Disfruta!

Este documento ha sido traducido desde la versión fr por el modelo mistral-medium.