Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente | ||
|
information:kebernetes:install [2023/12/04 12:04] benoit [Installation et configuration du plugin réseau] |
— (Version actuelle) | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| - | ====== Installation de Kubernetes ====== | ||
| - | |||
| - | Nous allons installer Kubernetes sur 2 serveurs : | ||
| - | * Un pour le rôle de master (IP: 10.0.6.8) | ||
| - | * Un pour le rôle de node (IP: 10.0.4.248) | ||
| - | |||
| - | |||
| - | ===== Prérequis ===== | ||
| - | |||
| - | ==== Matériel requis ==== | ||
| - | |||
| - | La machine doit disposer minimum des ressources suivantes : | ||
| - | * 2 Go de mémoire RAM | ||
| - | * 2 CPU | ||
| - | |||
| - | |||
| - | |||
| - | ==== Désactiver la Swap sur les machines ==== | ||
| - | |||
| - | Il est nécessaire de désactiver la swap pour faire fonctionner Kubernetes. | ||
| - | |||
| - | Désactiver la swap sur les 2 serveurs : | ||
| - | swapoff -a | ||
| - | |||
| - | Pour désactiver de manière persistante, mettre ne commentaire le point de montage ''swap'' dans le fichier ''/etc/fstab''. | ||
| - | |||
| - | ==== Configurations noyau Linux requis ==== | ||
| - | |||
| - | Editer le fichier : | ||
| - | vim /etc/modules-load.d/k8s.conf | ||
| - | |||
| - | Ajouter les lignes : | ||
| - | overlay | ||
| - | br_netfilter | ||
| - | |||
| - | Activer les modules : | ||
| - | modprobe overlay | ||
| - | modprobe br_netfilter | ||
| - | |||
| - | Vérifier que les modules sont chargés : | ||
| - | lsmod | grep br_netfilter | ||
| - | lsmod | grep overlay | ||
| - | |||
| - | Résultat attandu : | ||
| - | br_netfilter 32768 0 | ||
| - | bridge 294912 1 br_netfilter | ||
| - | overlay 163840 0 | ||
| - | |||
| - | Editer le fichier : | ||
| - | vim /etc/sysctl.d/kubernetes.conf | ||
| - | |||
| - | Insérer les lignes suivantes (Autorisation du Bridge et de l'IP Forwarding) : | ||
| - | net.bridge.bridge-nf-call-ip6tables = 1 | ||
| - | net.bridge.bridge-nf-call-iptables = 1 | ||
| - | net.ipv4.ip_forward = 1 | ||
| - | |||
| - | Activation des options réseau du noyau : | ||
| - | sysctl --system | ||
| - | |||
| - | ==== Installer et configurer Docker ==== | ||
| - | |||
| - | [[informatique:docker:installation|Installation de Docker]] | ||
| - | |||
| - | Créer le répertoire : | ||
| - | mkdir -p /etc/systemd/system/docker.service.d | ||
| - | |||
| - | Editer le fichier : | ||
| - | vim /etc/docker/daemon.json | ||
| - | |||
| - | Insérer le contenu suivant : | ||
| - | { | ||
| - | "exec-opts": ["native.cgroupdriver=systemd"], | ||
| - | "log-driver": "json-file", | ||
| - | "log-opts": { | ||
| - | "max-size": "100m" | ||
| - | }, | ||
| - | "storage-driver": "overlay2" | ||
| - | } | ||
| - | |||
| - | Relancer le service Docker : | ||
| - | systemctl daemon-reload | ||
| - | systemctl restart docker | ||
| - | |||
| - | |||
| - | ==== Installer Cri-Dockerd (Editeur Mirantis) ==== | ||
| - | |||
| - | Il est nécessaire d'installer un interface CRI (Container Runtime Interface). L'interface recommandée par Kubernetes pour Docker est **cri-dockerd**. | ||
| - | |||
| - | |||
| - | Vérifier que Docker est bien lancé : | ||
| - | systemctl status docker | ||
| - | |||
| - | Installer les paquetages pré-requis : | ||
| - | apt install git wget curl | ||
| - | |||
| - | Identification de la dernière version de Cri-Dockerd : | ||
| - | VER=$(curl -s https://api.github.com/repos/Mirantis/cri-dockerd/releases/latest|grep tag_name | cut -d '"' -f 4|sed 's/v//g') | ||
| - | echo $VER | ||
| - | |||
| - | Téléchargement et décompression de l'archive | ||
| - | wget https://github.com/Mirantis/cri-dockerd/releases/download/v${VER}/cri-dockerd-${VER}.amd64.tgz | ||
| - | wget https://raw.githubusercontent.com/Mirantis/cri-dockerd/master/packaging/systemd/cri-docker.service | ||
| - | wget https://raw.githubusercontent.com/Mirantis/cri-dockerd/master/packaging/systemd/cri-docker.socket | ||
| - | tar xvf cri-dockerd-${VER}.amd64.tgz | ||
| - | |||
| - | Copie des fichiers dans le système : | ||
| - | mv cri-dockerd/cri-dockerd /usr/local/bin/ | ||
| - | mv cri-docker.socket cri-docker.service /etc/systemd/system/ | ||
| - | sed -i -e 's,/usr/bin/cri-dockerd,/usr/local/bin/cri-dockerd,' /etc/systemd/system/cri-docker.service | ||
| - | |||
| - | Tester le binaire : | ||
| - | cri-dockerd --version | ||
| - | |||
| - | Résultat attendu : | ||
| - | cri-dockerd 0.3.7 (170103f2) | ||
| - | |||
| - | Activer et lancer Cri-Dockerd : | ||
| - | systemctl daemon-reload | ||
| - | systemctl enable cri-docker.service | ||
| - | systemctl enable --now cri-docker.socket | ||
| - | |||
| - | Vérifier que le service fonctionne : | ||
| - | systemctl status cri-docker.socket | ||
| - | |||
| - | Résultat attendu : | ||
| - | ● cri-docker.socket - CRI Docker Socket for the API | ||
| - | Loaded: loaded (/etc/systemd/system/cri-docker.socket; enabled; preset: enabled) | ||
| - | Active: active (listening) since Mon 2023-12-04 05:45:27 UTC; 10s ago | ||
| - | ... | ||
| - | |||
| - | ===== Installation ===== | ||
| - | |||
| - | **A faire sur le master et les nodes** | ||
| - | |||
| - | Ajouter le dépôt à APT : | ||
| - | |||
| - | apt install apt-transport-https curl | ||
| - | curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | gpg --dearmor -o /etc/apt/trusted.gpg.d/google.gpg | ||
| - | add-apt-repository "deb http://apt.kubernetes.io/ kubernetes-xenial main" | ||
| - | |||
| - | Installation : | ||
| - | apt update | ||
| - | apt install kubelet kubeadm kubectl kubernetes-cni | ||
| - | |||
| - | Vérifier le fonctionnement : | ||
| - | kubectl version --client && kubeadm version | ||
| - | |||
| - | Résultat attendu : | ||
| - | Client Version: v1.28.2 | ||
| - | Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3 | ||
| - | kubeadm version: &version.Info{Major:"1", Minor:"28", GitVersion:"v1.28.2", GitCommit:"89a4ea3e1e4ddd7f7572286090359983e0387b2f", GitTreeState:"clean", BuildDate:"2023-09-13T09:34:32Z", GoVersion:"go1.20.8", Compiler:"gc", Platform:"linux/amd64"} | ||
| - | |||
| - | Activer le service kubelet de Kubernetes : | ||
| - | systemctl enable kubelet | ||
| - | ===== Initialisation du Master et ajout des Nodes ===== | ||
| - | |||
| - | |||
| - | ==== Initialisation du Master ==== | ||
| - | |||
| - | Il s'agit d'installer les images et lancer les conteneurs nécessaires au fonctionnement du Master. | ||
| - | |||
| - | Ajouter l'enregistrement de l'hôte dans le fichier hosts : | ||
| - | echo "10.0.6.8 k8s-master" >> /etc/hosts | ||
| - | |||
| - | Paramétrer la méthode de récupération d'image. | ||
| - | kubeadm config images pull --cri-socket /run/cri-dockerd.sock | ||
| - | |||
| - | Initialisation du Cluster : | ||
| - | kubeadm init --pod-network-cidr=192.168.89.0/16 --cri-socket /run/cri-dockerd.sock | ||
| - | |||
| - | * pod-network-cidr : C'est pour définir le réseau dédié au fonctionnement des POD Kubernetes. Il faut que les IP des nodes soient dans ce réseau. | ||
| - | |||
| - | Résultat attendu : | ||
| - | Your Kubernetes control-plane has initialized successfully! | ||
| - | | ||
| - | To start using your cluster, you need to run the following as a regular user: | ||
| - | | ||
| - | mkdir -p $HOME/.kube | ||
| - | sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config | ||
| - | sudo chown $(id -u):$(id -g) $HOME/.kube/config | ||
| - | | ||
| - | Alternatively, if you are the root user, you can run: | ||
| - | | ||
| - | export KUBECONFIG=/etc/kubernetes/admin.conf | ||
| - | | ||
| - | You should now deploy a pod network to the cluster. | ||
| - | Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at: | ||
| - | https://kubernetes.io/docs/concepts/cluster-administration/addons/ | ||
| - | | ||
| - | Then you can join any number of worker nodes by running the following on each as root: | ||
| - | | ||
| - | kubeadm join 10.0.6.8:6443 --token 0f1p8l.i5789sopbs4yod8r \ | ||
| - | --discovery-token-ca-cert-hash sha256:99642bae81510327a55119dbc73bb3291eda748924cd889090239292dd91fea8 | ||
| - | |||
| - | |||
| - | Nous allons suivre les instructions indiqué lors de l'initialisation du Cluster : | ||
| - | mkdir -p $HOME/.kube | ||
| - | sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config | ||
| - | sudo chown $(id -u):$(id -g) $HOME/.kube/config | ||
| - | |||
| - | Vérifier les informations du cluster : | ||
| - | kubectl cluster-info | ||
| - | |||
| - | Résultat attendu : | ||
| - | Kubernetes control plane is running at https://10.0.6.8:6443 | ||
| - | CoreDNS is running at https://10.0.6.8:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy | ||
| - | | ||
| - | To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'. | ||
| - | |||
| - | ==== Ajout des Nodes ==== | ||
| - | |||
| - | **A faire sur chaque node.** | ||
| - | |||
| - | Pour enregistrer le node au master : | ||
| - | kubeadm join 10.0.6.8:6443 --token 0f1p8l.i5789sopbs4yod8r --discovery-token-ca-cert-hash \ | ||
| - | sha256:99642bae81510327a55119dbc73bb3291eda748924cd889090239292dd91fea8 --cri-socket /run/cri-dockerd.sock | ||
| - | |||
| - | ==== Vérification des nodes sur le Master ==== | ||
| - | |||
| - | Vérifier la liste des nodes : | ||
| - | kubectl get nodes | ||
| - | |||
| - | Résultat attendu : | ||
| - | NAME STATUS ROLES AGE VERSION | ||
| - | k8s-master NotReady control-plane 18m v1.28.2 | ||
| - | k8s-node NotReady <none> 8m37s v1.28.2 | ||
| - | |||
| - | ===== Installation et configuration du plugin réseau ===== | ||
| - | |||
| - | Nous utiliserons le plugin **Flannel**. | ||
| - | |||
| - | Il est validé par l'éditeur [[https://kubernetes.io/docs/concepts/cluster-administration/addons/|Kubernetes]]. | ||
| - | |||