Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
elearning:workbooks:kubernetes:k8s09 [2024/02/21 13:04] – admin | elearning:workbooks:kubernetes:k8s09 [2024/12/20 13:54] (Version actuelle) – admin | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
+ | ~~PDF: | ||
+ | Version - **2024.01** | ||
+ | |||
+ | Dernière mise-à-jour : ~~LASTMOD~~ | ||
+ | |||
+ | |||
+ | ======DOF310 - StatefulSets, | ||
+ | |||
+ | =====Contenu du Module===== | ||
+ | |||
+ | * **DOF310 - StatefulSets, | ||
+ | * Contenu du Module | ||
+ | * StatefulSets | ||
+ | * LAB #1 - Mise en Place d'un StatefulSet Simple | ||
+ | * 1.1 - Création du Service et du StatefulSet | ||
+ | * 1.2 - Mise en Place d'un Scale Up | ||
+ | * 1.3 - Mise en Place d'un Scale Down | ||
+ | * 1.4 - Suppression du StatefulSet | ||
+ | * StorageClass Avancé | ||
+ | * LAB #2 - Provisionnement NFS dynamique | ||
+ | * 2.1 - Configuration du Serveur NFS | ||
+ | * 2.2 - Configuration des Clients NFS | ||
+ | * 2.3 - Configuration de K8s | ||
+ | * 2.4 - Création d'un PersistentVolumeClaim | ||
+ | * 2.5 - Utilisation du PersistentVolumeClaim avec un pod | ||
+ | * 2.6 - Création d'un Deuxième PersistentVolumeClaim | ||
+ | * 2.7 - Suppression des PersistentVolumeClaims | ||
+ | * Helm Avancé | ||
+ | * LAB #3 - Création d'un Paquet Helm Simple | ||
+ | * 3.1 - Le Fichier values.yaml | ||
+ | * 3.2 - Les Templates | ||
+ | * 3.3 - Installation et Suppression | ||
+ | * Monitoring | ||
+ | * LAB #4 - Mise en Place d'une Solution Prometheus | ||
+ | * 4.1 - Déploiement du Stack avec Helm | ||
+ | * 4.2 - Consultation des Données avec Grafana | ||
+ | * 4.3 - Consultation des Alertes avec le Web UI de Prometheus | ||
+ | |||
+ | =====Ressources===== | ||
+ | |||
+ | ====Lab #1==== | ||
+ | |||
+ | * https:// | ||
+ | * https:// | ||
+ | |||
+ | ====Lab #2==== | ||
+ | |||
+ | * https:// | ||
+ | * https:// | ||
+ | * https:// | ||
+ | |||
+ | ====Lab #3==== | ||
+ | |||
+ | * https:// | ||
+ | * https:// | ||
+ | * https:// | ||
+ | * https:// | ||
+ | * https:// | ||
+ | |||
+ | =====StatefulSets===== | ||
+ | |||
+ | Un StatefulSet est un composant de Kubernetes qui est utilisé pour des applications avec état (//Stateful Applications// | ||
+ | |||
+ | Des exemples d' | ||
+ | |||
+ | * MySQL | ||
+ | * elasticsearch | ||
+ | * mongoDB | ||
+ | |||
+ | Ces applications enregistrent les données client des activités d'une session pour les utiliser lors de la session suivante. Les données enregistrées sont appelées l' | ||
+ | |||
+ | Les applications avec état sont déployées en utilisant un StatefulSet tandis que des applications **sans** état sont déployées en utilisant un **Deployment**. | ||
+ | |||
+ | Les StatefulSets et les Deployments sont similaires dans la mesure où les deux répliquent de multiples pods basés sur une spécification **identique** d'un conteneur. | ||
+ | |||
+ | La différence entre un StatefulSet et un Deployment est que dans un StatefulSet les pods ne sont **pas** identiques et possèdent ce que l'on appelle un **Pod Identity**. De ce fait les pods : | ||
+ | |||
+ | * ne peuvent pas être créés ou supprimés en même temps, | ||
+ | * ne peuvent pas être adressés d'une manière aléatoire. | ||
+ | |||
+ | Prenons le cas d'un StatfulSet contenant trois répliques d'un pod MySQL : | ||
+ | |||
+ | * mysql-0 | ||
+ | * mysql-1 | ||
+ | * mysql-2 | ||
+ | |||
+ | Notez que : | ||
+ | |||
+ | * le nom du pod prend la forme **$(Nom_du_StatefulSet)-$(ordinal)** où l' | ||
+ | * le StatefulSet ne créera pas le pod suivant tant que le pod précédent n'est pas dans un état de **Running** | ||
+ | * dans le cas de la suppression du StatefulSet ou bien dans le cas d'un **scale down**, les pods sont supprimés dans l' | ||
+ | |||
+ | Dans ce cas de notre StatefulSet, | ||
+ | |||
+ | * ne peuvent pas tous accepter des requêtes d' | ||
+ | * peuvent tous accepter des requêtes de lecture. | ||
+ | |||
+ | De ce fait, un mécanisme du StatefulSet choisit un **maître** pour accepter des requêtes d' | ||
+ | |||
+ | * mysql-0 - écriture / lecture - **Maître** | ||
+ | * mysql-1 - lecture seulement - **Esclave** | ||
+ | * mysql-2 - lecture seulement - **Esclave** | ||
+ | |||
+ | Il existe donc une différence précise entre le pod Maître et les deux pods Esclaves. | ||
+ | |||
+ | La différence entre les deux pods Esclaves s' | ||
+ | |||
+ | * mysql-0 - **/ | ||
+ | * mysql-1 - **/ | ||
+ | * mysql-2 - **/ | ||
+ | |||
+ | De façon à ce que chaque pod contient les mêmes données, un mecanisme de réplication en continu doit être mis en place entre les deux pods Esclaves et le pod Maître. | ||
+ | |||
+ | Dans le cas où un nouveau pod est ajouté au **cluster** MySQL, celui-ci doit commencer par cloner les données du dernier pod dans le cluster existant, puis il doit commencer la réplication des données avec le Maître : | ||
+ | |||
+ | * mysql-0 - données | ||
+ | * mysql-1 - données répliquées de mysql-0 | ||
+ | * mysql-2 - données répliquées de mysql-0 | ||
+ | * mysql-3 - clone des données du pod mysql-2 puis, par la suite, données répliquées de mysql-0 | ||
+ | |||
+ | L' | ||
+ | |||
+ | Par exemple, si on supprime le pod **mysql-1**, | ||
+ | |||
+ | * mysql-0 - / | ||
+ | * pod supprimé - / | ||
+ | * mysql-2 - / | ||
+ | * mysql-3 - / | ||
+ | |||
+ | En ajoutant un pod de remplaceement, | ||
+ | |||
+ | * mysql-0 | ||
+ | * mysql-1 <<<<<<<<<< | ||
+ | * mysql-2 | ||
+ | * mysql-3 | ||
+ | |||
+ | Lors de la création d'un ReplicaSet, un service d' | ||
+ | ** : | ||
+ | |||
+ | * mysql-0 - **mysql-0.mysvc.default.svc.cluster.local** | ||
+ | * mysql-1 - **mysql-1.mysvc.default.svc.cluster.local** | ||
+ | * mysql-2 - **mysql-2.mysvc.default.svc.cluster.local** | ||
+ | * mysql-3 - **mysql-3.mysvc.default.svc.cluster.local** | ||
+ | |||
+ | De cette façon, quand un pod est redémarré bien que son adresse IP changera : | ||
+ | |||
+ | * son nom ne changera **pas** | ||
+ | * son Endpoint DNS ne changera **pas** | ||
+ | |||
+ | Pour résumer : | ||
+ | |||
+ | * mysql-0 | ||
+ | * Rôle : **Maître** | ||
+ | * Données : écriture / lecture | ||
+ | * Stockage : / | ||
+ | * Endpoint DNS : mysql-0..mysvc.default.svc.cluster.local | ||
+ | * mysql-1 | ||
+ | * Rôle : **Esclave** | ||
+ | * Données : lecture seulement | ||
+ | * Stockage : / | ||
+ | * Endpoint DNS : mysql-1.mysvc.default.svc.cluster.local | ||
+ | * mysql-2 | ||
+ | * Rôle : **Esclave** | ||
+ | * Données : lecture seulement | ||
+ | * Stockage : / | ||
+ | * Endpoint DNS : mysql-2.mysvc.default.svc.cluster.local | ||
+ | * mysql-3 | ||
+ | * Rôle : **Esclave** | ||
+ | * Données : lecture seulement | ||
+ | * Stockage : / | ||
+ | * Endpoint DNS : mysql-3.mysvc.default.svc.cluster.local | ||
+ | |||
+ | Dernièrement, | ||
+ | |||
+ | * la configuration du clonage des données | ||
+ | * la configuration de la réplication des données | ||
+ | * la création et la configuration du stockage physique persistant et distant | ||
+ | * la configuration et la gestion des sauvegardes des données | ||
+ | |||
+ | ====LAB #1 - Mise en Place d'un StatefulSet Simple==== | ||
+ | |||
+ | Créez un Namespace **quarkus** puis modifiez le **context** de **kubernetes-admin@kubernetes** : | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | namespace/ | ||
+ | |||
+ | root@kubemaster: | ||
+ | Context " | ||
+ | </ | ||
+ | |||
+ | <WRAP center round important 60%> | ||
+ | **Important** : Quarkus est un framework Java natif pour Kubernetes complet, conçu pour les machines virtuelles Java (JVM) et la compilation native, qui permet d' | ||
+ | </ | ||
+ | |||
+ | Si vous souhaitez observer les résultats des commandes suivantes en temps réel, ouvrez un deuxième terminal et saisissez la commande suivante : | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | </ | ||
+ | |||
+ | ===1.1 - Création du Service et du StatefulSet=== | ||
+ | |||
+ | Créez maintenant le fichier **quarkus-service.yaml** : | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | root@kubemaster: | ||
+ | apiVersion: v1 | ||
+ | kind: Service | ||
+ | metadata: | ||
+ | name: quarkus | ||
+ | labels: | ||
+ | app: quarkus-statefulset | ||
+ | spec: | ||
+ | ports: | ||
+ | - port: 8080 | ||
+ | name: web | ||
+ | clusterIP: None | ||
+ | selector: | ||
+ | app: quarkus-statefulset | ||
+ | </ | ||
+ | |||
+ | <WRAP center round important 60%> | ||
+ | **Important** : Notez le nom du service - **quarkus**. La valeur **None** de l' | ||
+ | </ | ||
+ | |||
+ | Créez le service : | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | service/ | ||
+ | </ | ||
+ | |||
+ | Créez maintenant le fichier **statefulset.yaml** : | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | root@kubemaster: | ||
+ | apiVersion: apps/v1 | ||
+ | kind: StatefulSet | ||
+ | metadata: | ||
+ | name: quarkus-statefulset | ||
+ | labels: | ||
+ | app: quarkus-statefulset | ||
+ | spec: | ||
+ | serviceName: | ||
+ | replicas: 2 | ||
+ | template: | ||
+ | metadata: | ||
+ | labels: | ||
+ | app: quarkus-statefulset | ||
+ | spec: | ||
+ | containers: | ||
+ | - name: quarkus-statefulset | ||
+ | image: quay.io/ | ||
+ | ports: | ||
+ | - containerPort: | ||
+ | name: web | ||
+ | selector: | ||
+ | matchLabels: | ||
+ | app: quarkus-statefulset | ||
+ | </ | ||
+ | |||
+ | <WRAP center round important 60%> | ||
+ | **Important** : Notez que la valeur de **serviceName** est **quarkus**. | ||
+ | </ | ||
+ | |||
+ | Créez le StatefulSet : | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | statefulset.apps/ | ||
+ | </ | ||
+ | |||
+ | Constatez la présence des deux pods dans le Namespace : | ||
+ | |||
+ | < | ||
+ | Every 1,0s: kubectl get pods -o wide | awk ' | ||
+ | |||
+ | NAME | ||
+ | quarkus-statefulset-0 | ||
+ | quarkus-statefulset-1 | ||
+ | </ | ||
+ | |||
+ | Contrôlez l' | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | NAME READY AGE | ||
+ | quarkus-statefulset | ||
+ | </ | ||
+ | |||
+ | ainsi que la présence du service : | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | NAME TYPE CLUSTER-IP | ||
+ | quarkus | ||
+ | </ | ||
+ | |||
+ | ===1.2 - Mise en Place d'un Scale Up=== | ||
+ | |||
+ | Procédez à un scale up : | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | </ | ||
+ | |||
+ | <WRAP center round important 60%> | ||
+ | **Important** : Notez que le nom court d'un **serviceName** est **sts**. | ||
+ | </ | ||
+ | |||
+ | Constatez la présence des **trois** pods dans le Namespace : | ||
+ | |||
+ | < | ||
+ | Every 1,0s: kubectl get pods -o wide | awk ' | ||
+ | |||
+ | NAME | ||
+ | quarkus-statefulset-0 | ||
+ | quarkus-statefulset-1 | ||
+ | quarkus-statefulset-2 | ||
+ | </ | ||
+ | |||
+ | Constatez l' | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | LAST SEEN | ||
+ | 6m35s | ||
+ | 6m35s | ||
+ | 6m34s | ||
+ | 6m5s Normal | ||
+ | 6m4s Normal | ||
+ | 6m4s Normal | ||
+ | 6m3s Normal | ||
+ | 6m3s Normal | ||
+ | 5m58s | ||
+ | 5m22s | ||
+ | 5m21s | ||
+ | 5m21s | ||
+ | 99s | ||
+ | 99s | ||
+ | 98s | ||
+ | 97s | ||
+ | 97s | ||
+ | </ | ||
+ | |||
+ | Créez maintenant un pod pour interroger le DNS de K8s : | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | If you don't see a command prompt, try pressing enter. | ||
+ | / # nslookup quarkus-statefulset-0.quarkus | ||
+ | Server: | ||
+ | Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local | ||
+ | |||
+ | Name: quarkus-statefulset-0.quarkus | ||
+ | Address 1: 192.168.150.2 quarkus-statefulset-0.quarkus.quarkus.svc.cluster.local | ||
+ | / # exit | ||
+ | pod " | ||
+ | root@kubemaster: | ||
+ | </ | ||
+ | |||
+ | ===1.3 - Mise en Place d'un Scale Down=== | ||
+ | |||
+ | Procédez maintenant à un scale down : | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | statefulset.apps/ | ||
+ | </ | ||
+ | |||
+ | Constatez la présence de **deux** pods dans le Namespace : | ||
+ | |||
+ | < | ||
+ | Every 1,0s: kubectl get pods -o wide | awk ' | ||
+ | |||
+ | NAME | ||
+ | quarkus-statefulset-0 | ||
+ | quarkus-statefulset-1 | ||
+ | </ | ||
+ | |||
+ | ===1.4 - Suppression du StatefulSet=== | ||
+ | |||
+ | Pour terminer, supprimez le StatefulSet, | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | statefulset.apps " | ||
+ | |||
+ | root@kubemaster: | ||
+ | service " | ||
+ | |||
+ | root@kubemaster: | ||
+ | Context " | ||
+ | </ | ||
+ | |||
+ | =====StorageClass Avancé===== | ||
+ | |||
+ | ====LAB #2 - Provisionnement NFS dynamique==== | ||
+ | |||
+ | ===2.1 - Configuration du Serveur NFS=== | ||
+ | |||
+ | Connectez-vous à la VM CentOS8 en tant que trainee au 10.0.2.45. | ||
+ | |||
+ | Devenez root puis créez le répertoire **/ | ||
+ | |||
+ | < | ||
+ | [root@centos8 ~]# mkdir -p / | ||
+ | </ | ||
+ | |||
+ | Continuez maintenant par activer et démarrer le service **nfs-server** : | ||
+ | |||
+ | < | ||
+ | [root@centos8 ~]# systemctl status nfs-server | ||
+ | ● nfs-server.service - NFS server and services | ||
+ | | ||
+ | | ||
+ | |||
+ | [root@centos8 ~]# systemctl enable nfs-server.service | ||
+ | Created symlink / | ||
+ | |||
+ | [root@centos8 ~]# systemctl start nfs-server.service | ||
+ | |||
+ | [root@centos8 ~]# systemctl status nfs-server.service | ||
+ | ● nfs-server.service - NFS server and services | ||
+ | | ||
+ | | ||
+ | Process: 3276 ExecStart=/ | ||
+ | Process: 3263 ExecStart=/ | ||
+ | Process: 3261 ExecStartPre=/ | ||
+ | Main PID: 3276 (code=exited, | ||
+ | |||
+ | Nov 21 11:02:12 centos8.ittraining.loc systemd[1]: Starting NFS server and services... | ||
+ | Nov 21 11:02:13 centos8.ittraining.loc systemd[1]: Started NFS server and services. | ||
+ | </ | ||
+ | |||
+ | Editez le fichier **/ | ||
+ | |||
+ | < | ||
+ | [root@centos8 ~]# vi / | ||
+ | [root@centos8 ~]# cat / | ||
+ | / | ||
+ | </ | ||
+ | |||
+ | <WRAP center round important 60%> | ||
+ | **Important** : Dans ce cas, nous avons partagé le répertoire **/ | ||
+ | </ | ||
+ | |||
+ | Appliquez l' | ||
+ | |||
+ | < | ||
+ | [root@centos8 ~]# exportfs -rav | ||
+ | exporting *:/ | ||
+ | |||
+ | [root@centos8 ~]# exportfs -v | ||
+ | / | ||
+ | < | ||
+ | </ | ||
+ | |||
+ | Passez SELinux en mode permissive : | ||
+ | |||
+ | < | ||
+ | [root@centos8 ~]# getenforce | ||
+ | Enforcing | ||
+ | |||
+ | [root@centos8 ~]# setenforce permissive | ||
+ | |||
+ | </ | ||
+ | |||
+ | Configurez ensuite le pare-feu : | ||
+ | |||
+ | < | ||
+ | [root@centos8 ~]# firewall-cmd --permanent --add-service=nfs | ||
+ | success | ||
+ | [root@centos8 ~]# firewall-cmd --permanent --add-service=rpc-bind | ||
+ | success | ||
+ | [root@centos8 ~]# firewall-cmd --permanent --add-service=mountd | ||
+ | success | ||
+ | [root@centos8 ~]# firewall-cmd --reload | ||
+ | success | ||
+ | </ | ||
+ | |||
+ | ===2.2 - Configuration des Clients NFS=== | ||
+ | |||
+ | Revenez à votre gateway et connectez-vous en tant que l' | ||
+ | |||
+ | < | ||
+ | trainee@kubenode2: | ||
+ | Mot de passe : fenestros | ||
+ | root@kubenode2: | ||
+ | </ | ||
+ | |||
+ | Installez le paquet **nfs-common** : | ||
+ | |||
+ | < | ||
+ | root@kubenode2: | ||
+ | ... | ||
+ | |||
+ | root@kubenode2: | ||
+ | ... | ||
+ | </ | ||
+ | |||
+ | Vérifiez que vous pouvez voir le répertoire exporté par le 10.0.2.45 : | ||
+ | |||
+ | < | ||
+ | root@kubenode2: | ||
+ | Export list for 10.0.2.45: | ||
+ | / | ||
+ | </ | ||
+ | |||
+ | Vérifiez que vous pouvez monter le répertoire exporté par le 10.0.2.45 : | ||
+ | |||
+ | < | ||
+ | root@kubenode2: | ||
+ | root@kubenode2: | ||
+ | 10.0.2.45:/ | ||
+ | </ | ||
+ | |||
+ | Démontez ensuite **10.0.2.45:/ | ||
+ | |||
+ | < | ||
+ | root@kubenode2: | ||
+ | |||
+ | root@kubenode2: | ||
+ | </ | ||
+ | |||
+ | Connectez-vous à kubenode1 au 192.168.56.3 : | ||
+ | |||
+ | < | ||
+ | root@kubenode2: | ||
+ | The authenticity of host ' | ||
+ | ECDSA key fingerprint is SHA256: | ||
+ | Are you sure you want to continue connecting (yes/no)? yes | ||
+ | Warning: Permanently added ' | ||
+ | trainee@192.168.56.3' | ||
+ | Linux kubenode1.ittraining.loc 4.9.0-19-amd64 #1 SMP Debian 4.9.320-2 (2022-06-30) x86_64 | ||
+ | |||
+ | 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 / | ||
+ | |||
+ | Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent | ||
+ | permitted by applicable law. | ||
+ | Last login: Wed Sep 28 09:54:21 2022 from 192.168.56.2 | ||
+ | trainee@kubenode1: | ||
+ | Mot de passe : fenestros | ||
+ | root@kubenode1: | ||
+ | </ | ||
+ | |||
+ | Installez ensuite le paquet **nfs-common** : | ||
+ | |||
+ | < | ||
+ | root@kubenode1: | ||
+ | ... | ||
+ | |||
+ | root@kubenode1: | ||
+ | ... | ||
+ | </ | ||
+ | |||
+ | Revenez à votre gateway : | ||
+ | |||
+ | < | ||
+ | root@kubenode1: | ||
+ | déconnexion | ||
+ | trainee@kubenode1: | ||
+ | déconnexion | ||
+ | Connection to 192.168.56.3 closed. | ||
+ | root@kubenode2: | ||
+ | déconnexion | ||
+ | trainee@kubenode2: | ||
+ | déconnexion | ||
+ | Connection to 192.168.56.4 closed. | ||
+ | </ | ||
+ | |||
+ | ===2.3 - Configuration de K8s=== | ||
+ | |||
+ | Connectez-vous à votre **kubemaster** au 192.168.56.2. | ||
+ | |||
+ | Installez ensuite le paquet **nfs-common** : | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | ... | ||
+ | |||
+ | root@kubemaster: | ||
+ | ... | ||
+ | </ | ||
+ | |||
+ | Ajoutez le dépôt **nfs-subdir-external-provisioner** à **helm** : | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | " | ||
+ | </ | ||
+ | |||
+ | Installez le chart helm **nfs-subdir-external-provisioner** : | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | NAME: nfs-subdir-external-provisioner | ||
+ | LAST DEPLOYED: Wed Dec 7 11:12:23 2022 | ||
+ | NAMESPACE: default | ||
+ | STATUS: deployed | ||
+ | REVISION: 1 | ||
+ | TEST SUITE: None | ||
+ | </ | ||
+ | |||
+ | Contrôlez l' | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | NAME | ||
+ | netshoot | ||
+ | nfs-subdir-external-provisioner-59b4b5c476-wxkp4 | ||
+ | nginx-netshoot | ||
+ | postgresql-6f885d8957-tnlbb | ||
+ | sharedvolume | ||
+ | troubleshooting | ||
+ | volumepod | ||
+ | </ | ||
+ | |||
+ | <WRAP center round important 60%> | ||
+ | **Important** : Si le pod **nfs-subdir-external-provisioner-yyyyyyyyyy-xxxxx** reste dans un état de **ContainerCreating** pour plus de 5 minutes, supprimez les trois pods **calico-node-xxxxx** du Namespace **kube-system** et attendez qu'ils soient recréés. | ||
+ | </ | ||
+ | |||
+ | Une fois recréés, vous pouvez constater que le pod **nfs-subdir-external-provisioner-yyyyyyyyyy-xxxxx** est dans un état de Running : | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | NAMESPACE | ||
+ | default | ||
+ | default | ||
+ | default | ||
+ | default | ||
+ | default | ||
+ | default | ||
+ | default | ||
+ | </ | ||
+ | |||
+ | L' | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | I1207 10: | ||
+ | I1207 10: | ||
+ | I1207 10: | ||
+ | I1207 10: | ||
+ | I1207 10: | ||
+ | </ | ||
+ | |||
+ | Consultez maintenant la liste des StorageClasses : | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | NAME | ||
+ | localdisk | ||
+ | nfs-client | ||
+ | </ | ||
+ | |||
+ | ===2.4 - Création d'un PersistentVolumeClaim=== | ||
+ | |||
+ | Créez maintenant le fichier **pvc.yaml** : | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | root@kubemaster: | ||
+ | apiVersion: v1 | ||
+ | kind: PersistentVolumeClaim | ||
+ | metadata: | ||
+ | name: pvc1 | ||
+ | spec: | ||
+ | storageClassName: | ||
+ | accessModes: | ||
+ | - ReadWriteMany | ||
+ | resources: | ||
+ | requests: | ||
+ | storage: 500Mi | ||
+ | </ | ||
+ | |||
+ | Appliquez le fichier pvc.yaml : | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | persistentvolumeclaim/ | ||
+ | </ | ||
+ | |||
+ | Constatez maintenant la liste de PersistentVolumes et de PersistentVolumeClaims : | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | NAME CAPACITY | ||
+ | persistentvolume/ | ||
+ | persistentvolume/ | ||
+ | |||
+ | NAME | ||
+ | persistentvolumeclaim/ | ||
+ | </ | ||
+ | |||
+ | <WRAP center round important 60%> | ||
+ | **Important** : Notez que le PersistentVolume **persistentvolume/ | ||
+ | </ | ||
+ | |||
+ | Connectez-vous au serveur NFS et constatez le contenu du répertoire **/ | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | The authenticity of host ' | ||
+ | ECDSA key fingerprint is SHA256: | ||
+ | Are you sure you want to continue connecting (yes/no)? yes | ||
+ | Warning: Permanently added ' | ||
+ | trainee@10.0.2.45' | ||
+ | Activate the web console with: systemctl enable --now cockpit.socket | ||
+ | |||
+ | Last login: Wed Dec 7 10:34:25 2022 from 10.0.2.65 | ||
+ | |||
+ | [trainee@centos8 ~]$ ls -l / | ||
+ | total 0 | ||
+ | drwxrwxrwx. 2 root root 6 Dec 7 12:32 default-pvc1-pvc-721f5ed3-88b1-41bb-82c2-9eab3b4464da | ||
+ | [trainee@centos8 ~]$ exit | ||
+ | logout | ||
+ | Connection to 10.0.2.45 closed. | ||
+ | </ | ||
+ | |||
+ | ===2.5 - Utilisation du PersistentVolumeClaim avec un pod=== | ||
+ | |||
+ | Créez maintenant le fichier **nfs-busybox.yaml** : | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | root@kubemaster: | ||
+ | apiVersion: v1 | ||
+ | kind: Pod | ||
+ | metadata: | ||
+ | name: nfs-pv-pod | ||
+ | spec: | ||
+ | restartPolicy: | ||
+ | containers: | ||
+ | - name: busybox | ||
+ | image: busybox | ||
+ | command: [' | ||
+ | volumeMounts: | ||
+ | - name: pv-storage | ||
+ | mountPath: / | ||
+ | volumes: | ||
+ | - name: pv-storage | ||
+ | persistentVolumeClaim: | ||
+ | claimName: pvc1 | ||
+ | </ | ||
+ | |||
+ | Appliquez le fichier nfs-busybox.yaml : | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | pod/ | ||
+ | </ | ||
+ | |||
+ | Vérifiez que le statut du pod **nfs-pv-pod** est **Running** : | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | NAME | ||
+ | netshoot | ||
+ | nfs-pv-pod | ||
+ | nfs-subdir-external-provisioner-59b4b5c476-wxkp4 | ||
+ | nginx-netshoot | ||
+ | postgresql-6f885d8957-tnlbb | ||
+ | sharedvolume | ||
+ | troubleshooting | ||
+ | volumepod | ||
+ | </ | ||
+ | |||
+ | Connectez-vous au conteneur du pod **nfs-pv-pod** : | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | / # | ||
+ | </ | ||
+ | |||
+ | Créez le fichier **hello** dans le répertoire **pv-pod-storage** : | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | / # ls | ||
+ | bin | ||
+ | / # touch / | ||
+ | / # ls / | ||
+ | hello | ||
+ | / # exit | ||
+ | </ | ||
+ | |||
+ | Connectez-vous au serveur NFS et constatez le contenu du répertoire **/ | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | trainee@10.0.2.45' | ||
+ | Activate the web console with: systemctl enable --now cockpit.socket | ||
+ | |||
+ | Last login: Wed Dec 7 12:37:00 2022 from 10.0.2.65 | ||
+ | [trainee@centos8 ~]$ ls -lR / | ||
+ | / | ||
+ | total 0 | ||
+ | drwxrwxrwx. 2 root root 19 Dec 7 13:13 default-pvc1-pvc-721f5ed3-88b1-41bb-82c2-9eab3b4464da | ||
+ | |||
+ | / | ||
+ | total 0 | ||
+ | -rw-r--r--. 1 root root 0 Dec 7 13:13 hello | ||
+ | [trainee@centos8 ~]$ exit | ||
+ | logout | ||
+ | Connection to 10.0.2.45 closed. | ||
+ | </ | ||
+ | |||
+ | <WRAP center round important 60%> | ||
+ | **Important** : Notez la présence du fichier **hello**. | ||
+ | </ | ||
+ | |||
+ | ===2.6 - Création d'un Deuxième PersistentVolumeClaim=== | ||
+ | |||
+ | Vréez le fichier **pvc2.yaml** : | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | root@kubemaster: | ||
+ | apiVersion: v1 | ||
+ | kind: PersistentVolumeClaim | ||
+ | metadata: | ||
+ | name: pvc2 | ||
+ | spec: | ||
+ | storageClassName: | ||
+ | accessModes: | ||
+ | - ReadWriteOnce | ||
+ | resources: | ||
+ | requests: | ||
+ | storage: 100Mi | ||
+ | </ | ||
+ | |||
+ | Appliquez le fichier **pvc2.yaml** : | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | persistentvolumeclaim/ | ||
+ | </ | ||
+ | |||
+ | Constatez maintenant la liste de PersistentVolumes et de PersistentVolumeClaims : | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | NAME CAPACITY | ||
+ | persistentvolume/ | ||
+ | persistentvolume/ | ||
+ | persistentvolume/ | ||
+ | |||
+ | NAME | ||
+ | persistentvolumeclaim/ | ||
+ | persistentvolumeclaim/ | ||
+ | </ | ||
+ | |||
+ | <WRAP center round important 60%> | ||
+ | **Important** : Notez que le PersistentVolume **persistentvolume/ | ||
+ | </ | ||
+ | |||
+ | ===2.7 - Suppression des PersistentVolumeClaims=== | ||
+ | |||
+ | Commencer par supprimer le pod **nfs-pv-pod** : | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | pod " | ||
+ | </ | ||
+ | |||
+ | Constatez la suppression effective du pod : | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | NAME | ||
+ | netshoot | ||
+ | nfs-subdir-external-provisioner-59b4b5c476-wxkp4 | ||
+ | nginx-netshoot | ||
+ | postgresql-6f885d8957-tnlbb | ||
+ | sharedvolume | ||
+ | troubleshooting | ||
+ | volumepod | ||
+ | </ | ||
+ | |||
+ | Constatez maintenant la liste de PersistentVolumes et de PersistentVolumeClaims : | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | NAME CAPACITY | ||
+ | persistentvolume/ | ||
+ | persistentvolume/ | ||
+ | persistentvolume/ | ||
+ | |||
+ | NAME | ||
+ | persistentvolumeclaim/ | ||
+ | persistentvolumeclaim/ | ||
+ | </ | ||
+ | |||
+ | <WRAP center round important 60%> | ||
+ | **Important** : Notez que les PersistentVolumes et les PersistentVolumeClaims sont toujours présents. | ||
+ | </ | ||
+ | |||
+ | Supprimes les deux PersistentVolumeClaims : | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | persistentvolumeclaim " | ||
+ | persistentvolumeclaim " | ||
+ | </ | ||
+ | |||
+ | Constatez ensuite que les deux PersistentVolumes ont été supprimés automatiquement : | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | NAME CAPACITY | ||
+ | persistentvolume/ | ||
+ | </ | ||
+ | |||
+ | Connectez-vous au serveur NFS et constatez le contenu du répertoire **/ | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | trainee@10.0.2.45' | ||
+ | Activate the web console with: systemctl enable --now cockpit.socket | ||
+ | |||
+ | Last login: Wed Dec 7 13:15:49 2022 from 10.0.2.65 | ||
+ | [trainee@centos8 ~]$ ls -lR / | ||
+ | / | ||
+ | total 0 | ||
+ | drwxrwxrwx. 2 root root 19 Dec 7 13:13 archived-default-pvc1-pvc-721f5ed3-88b1-41bb-82c2-9eab3b4464da | ||
+ | drwxrwxrwx. 2 root root 6 Dec 7 13:24 archived-default-pvc2-pvc-6dbce6de-e473-4e4c-99be-0fbea26576de | ||
+ | |||
+ | / | ||
+ | total 0 | ||
+ | -rw-r--r--. 1 root root 0 Dec 7 13:13 hello | ||
+ | |||
+ | / | ||
+ | total 0 | ||
+ | [trainee@centos8 ~]$ exit | ||
+ | logout | ||
+ | Connection to 10.0.2.45 closed. | ||
+ | </ | ||
+ | |||
+ | <WRAP center round important 60%> | ||
+ | **Important** : Notez que les répertoires ont un préfixe **archived-** | ||
+ | </ | ||
+ | |||
+ | =====Helm Avancé===== | ||
+ | |||
+ | Un chart est une collection de fichiers et de répertoires qui prennent la forme suivante : | ||
+ | |||
+ | < | ||
+ | MyChart/ | ||
+ | Chart.yaml | ||
+ | LICENSE | ||
+ | README.md | ||
+ | values.yaml | ||
+ | values.schema.json | ||
+ | charts/ | ||
+ | crds/ | ||
+ | templates/ | ||
+ | templates/ | ||
+ | </ | ||
+ | |||
+ | Le langage des templates de helm est basé sur le langage GO. | ||
+ | |||
+ | Dans le LAB suivant, vous allez prendre les deux manifests suivants, **ghost.yaml** et **ghost-service.yaml** et créer un chart helm pour installer | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | root@kubemaster: | ||
+ | apiVersion: apps/v1 | ||
+ | kind: Deployment | ||
+ | metadata: | ||
+ | name: blog | ||
+ | labels: | ||
+ | app: blog | ||
+ | spec: | ||
+ | replicas: 1 | ||
+ | selector: | ||
+ | matchLabels: | ||
+ | app: blog | ||
+ | template: | ||
+ | metadata: | ||
+ | labels: | ||
+ | app: blog | ||
+ | spec: | ||
+ | containers: | ||
+ | - name: blog | ||
+ | image: ghost: | ||
+ | imagePullPolicy: | ||
+ | ports: | ||
+ | - containerPort: | ||
+ | env: | ||
+ | - name: url | ||
+ | value: http:// | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | root@kubemaster: | ||
+ | apiVersion: v1 | ||
+ | kind: Service | ||
+ | metadata: | ||
+ | name: blog | ||
+ | spec: | ||
+ | type: NodePort | ||
+ | selector: | ||
+ | app: blog | ||
+ | ports: | ||
+ | - protocol: TCP | ||
+ | port: 80 | ||
+ | targetPort: 2368 | ||
+ | </ | ||
+ | |||
+ | ====LAB #3 - Création d'un Paquet Helm Simple==== | ||
+ | |||
+ | Commencez par créer le répertoire **~/ghost** et placez-vous dedans : | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | root@kubemaster: | ||
+ | </ | ||
+ | |||
+ | Un chart necéssite la présence d'un fichier nommé **Chart.yaml** qui doit décrire le chart en question. Créez donc ce fichier : | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | </ | ||
+ | |||
+ | ===3.1 - Le Fichier values.yaml=== | ||
+ | |||
+ | Un chart a aussi besoin d'un fichier dénommé **values.yaml** qui contient des valeurs de configuration du chart en question. Créez donc le fichier values.yaml avec le contenu suivant : | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | root@kubemaster: | ||
+ | service: | ||
+ | name: blog | ||
+ | type: NodePort | ||
+ | app: blog | ||
+ | protocol: TCP | ||
+ | port: 80 | ||
+ | targetPort: 2368 | ||
+ | </ | ||
+ | |||
+ | ===3.2 - Les Templates=== | ||
+ | |||
+ | Créez le sous-répertoire **templates** dans **ghost** : | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | </ | ||
+ | |||
+ | Copiez le contenu du fichier **~/ | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | root@kubemaster: | ||
+ | apiVersion: v1 | ||
+ | kind: Service | ||
+ | metadata: | ||
+ | name: blog | ||
+ | spec: | ||
+ | type: NodePort | ||
+ | selector: | ||
+ | app: blog | ||
+ | ports: | ||
+ | - protocol: TCP | ||
+ | port: 80 | ||
+ | targetPort: 2368 | ||
+ | </ | ||
+ | |||
+ | Modifiez ensuite ce fichier pour lire les valeurs du fichier **values.yaml** : | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | root@kubemaster: | ||
+ | apiVersion: v1 | ||
+ | kind: Service | ||
+ | metadata: | ||
+ | name: {{ .Values.service.name }} | ||
+ | spec: | ||
+ | type: {{ .Values.service.type }} | ||
+ | selector: | ||
+ | app: {{ .Values.service.app }} | ||
+ | ports: | ||
+ | - protocol: {{ .Values.service.protocol }} | ||
+ | port: {{ .Values.service.port }} | ||
+ | targetPort: {{ .Values.service.targetPort }} | ||
+ | </ | ||
+ | |||
+ | Naviguez vers le répertoire parent du répertoire **ghost** : | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | </ | ||
+ | |||
+ | Vérifiez que helm peut lire la liste des valeurs du fichier values.yaml : | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | Error: validation: chart.metadata.name is required | ||
+ | </ | ||
+ | |||
+ | L' | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | root@kubemaster: | ||
+ | name: ghost | ||
+ | version: 1 | ||
+ | </ | ||
+ | |||
+ | Vérifiez maintenant que helm peut lire la liste des valeurs du fichier values.yaml : | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | service: | ||
+ | name: blog | ||
+ | type: NodePort | ||
+ | app: blog | ||
+ | protocol: TCP | ||
+ | port: 80 | ||
+ | targetPort: 2368 | ||
+ | </ | ||
+ | |||
+ | Vérifiez maintenant que le manifest **service.yaml** qui sera créé par Helm est correct : | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | NAME: check | ||
+ | LAST DEPLOYED: Thu Dec 8 15:54:13 2022 | ||
+ | NAMESPACE: default | ||
+ | STATUS: pending-install | ||
+ | REVISION: 1 | ||
+ | TEST SUITE: None | ||
+ | HOOKS: | ||
+ | MANIFEST: | ||
+ | --- | ||
+ | # Source: ghost/ | ||
+ | apiVersion: v1 | ||
+ | kind: Service | ||
+ | metadata: | ||
+ | name: blog | ||
+ | spec: | ||
+ | type: NodePort | ||
+ | selector: | ||
+ | app: blog | ||
+ | ports: | ||
+ | - protocol: TCP | ||
+ | port: 80 | ||
+ | targetPort: 2368 | ||
+ | </ | ||
+ | |||
+ | Copiez maintenant le contenu du fichier **~/ | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | root@kubemaster: | ||
+ | apiVersion: apps/v1 | ||
+ | kind: Deployment | ||
+ | metadata: | ||
+ | name: blog | ||
+ | labels: | ||
+ | app: blog | ||
+ | spec: | ||
+ | replicas: 1 | ||
+ | selector: | ||
+ | matchLabels: | ||
+ | app: blog | ||
+ | template: | ||
+ | metadata: | ||
+ | labels: | ||
+ | app: blog | ||
+ | spec: | ||
+ | containers: | ||
+ | - name: blog | ||
+ | image: ghost: | ||
+ | imagePullPolicy: | ||
+ | ports: | ||
+ | - containerPort: | ||
+ | env: | ||
+ | - name: url | ||
+ | value: http:// | ||
+ | </ | ||
+ | |||
+ | Modifiez ensuite ce fichier pour lire les valeurs du fichier **values.yaml** : | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | root@kubemaster: | ||
+ | apiVersion: apps/v1 | ||
+ | kind: Deployment | ||
+ | metadata: | ||
+ | name: {{ .Values.blog.name }} | ||
+ | labels: | ||
+ | app: {{ .Values.blog.label }} | ||
+ | spec: | ||
+ | replicas: {{ .Values.blog.replicas }} | ||
+ | selector: | ||
+ | matchLabels: | ||
+ | app: {{ .Values.blog.name }} | ||
+ | template: | ||
+ | metadata: | ||
+ | labels: | ||
+ | app: {{ .Values.blog.name }} | ||
+ | spec: | ||
+ | containers: | ||
+ | - name: {{ .Values.blog.name }} | ||
+ | image: {{ .Values.blog.image }} | ||
+ | imagePullPolicy: | ||
+ | ports: | ||
+ | - containerPort: | ||
+ | env: | ||
+ | - name: {{ .Values.blog.url }} | ||
+ | value: {{ .Values.blog.urlValue }} | ||
+ | </ | ||
+ | |||
+ | Completez maintenant le contenu du fichier values.yaml : | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | root@kubemaster: | ||
+ | service: | ||
+ | name: blog | ||
+ | type: NodePort | ||
+ | app: blog | ||
+ | protocol: TCP | ||
+ | port: 80 | ||
+ | targetPort: 2368 | ||
+ | blog: | ||
+ | name: blog | ||
+ | label: blog | ||
+ | replicas: 1 | ||
+ | image: ghost: | ||
+ | imagePullPolicy: | ||
+ | containerPort: | ||
+ | url: url | ||
+ | urlValue: http:// | ||
+ | </ | ||
+ | |||
+ | Vérifiez maintenant que le manifest **ghost.yaml** qui sera créé par Helm est correct : | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | NAME: check | ||
+ | LAST DEPLOYED: Thu Dec 8 16:12:29 2022 | ||
+ | NAMESPACE: default | ||
+ | STATUS: pending-install | ||
+ | REVISION: 1 | ||
+ | TEST SUITE: None | ||
+ | HOOKS: | ||
+ | MANIFEST: | ||
+ | --- | ||
+ | # Source: ghost/ | ||
+ | apiVersion: v1 | ||
+ | kind: Service | ||
+ | metadata: | ||
+ | name: blog | ||
+ | spec: | ||
+ | type: NodePort | ||
+ | selector: | ||
+ | app: blog | ||
+ | ports: | ||
+ | - protocol: TCP | ||
+ | port: 80 | ||
+ | targetPort: 2368 | ||
+ | --- | ||
+ | # Source: ghost/ | ||
+ | apiVersion: apps/v1 | ||
+ | kind: Deployment | ||
+ | metadata: | ||
+ | name: blog | ||
+ | labels: | ||
+ | app: blog | ||
+ | spec: | ||
+ | replicas: 1 | ||
+ | selector: | ||
+ | matchLabels: | ||
+ | app: blog | ||
+ | template: | ||
+ | metadata: | ||
+ | labels: | ||
+ | app: blog | ||
+ | spec: | ||
+ | containers: | ||
+ | - name: blog | ||
+ | image: ghost: | ||
+ | imagePullPolicy: | ||
+ | ports: | ||
+ | - containerPort: | ||
+ | env: | ||
+ | - name: url | ||
+ | value: http:// | ||
+ | </ | ||
+ | |||
+ | Consultez maintenant l' | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | ghost | ||
+ | ├── Chart.yaml | ||
+ | ├── templates | ||
+ | │ | ||
+ | │ | ||
+ | └── values.yaml | ||
+ | |||
+ | 1 directory, 4 files | ||
+ | </ | ||
+ | |||
+ | ===3.3 - Installation et Suppression=== | ||
+ | |||
+ | Installez le chart **ghost** : | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | NAME: live | ||
+ | LAST DEPLOYED: Thu Dec 8 16:14:13 2022 | ||
+ | NAMESPACE: default | ||
+ | STATUS: deployed | ||
+ | REVISION: 1 | ||
+ | TEST SUITE: None | ||
+ | </ | ||
+ | |||
+ | Vérifiez l' | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | NAME | ||
+ | blog | ||
+ | kubernetes | ||
+ | service-netshoot | ||
+ | </ | ||
+ | |||
+ | Vérifiez la présence du pod dans le cluster : | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | NAME | ||
+ | blog-8545df8764-hk8rc | ||
+ | netshoot | ||
+ | nfs-subdir-external-provisioner-59b4b5c476-wxkp4 | ||
+ | nginx-netshoot | ||
+ | postgresql-6f885d8957-tnlbb | ||
+ | sharedvolume | ||
+ | troubleshooting | ||
+ | volumepod | ||
+ | </ | ||
+ | |||
+ | Vérifiez le statut du chart : | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | NAME: live | ||
+ | LAST DEPLOYED: Thu Dec 8 16:14:13 2022 | ||
+ | NAMESPACE: default | ||
+ | STATUS: deployed | ||
+ | REVISION: 1 | ||
+ | TEST SUITE: None | ||
+ | </ | ||
+ | |||
+ | Dernièrement, | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | release " | ||
+ | </ | ||
+ | |||
+ | =====Monitoring===== | ||
+ | |||
+ | Le serveur Prometheus est composé de trois modules : | ||
+ | |||
+ | * **Data Retrieval Worker** qui récupére les métriques | ||
+ | * **Time Series Database** qui stocke les métriques | ||
+ | * **HTTP Server** qui accepte des requêtes PromQL et qui fournit un Web UI pour la consultation des données | ||
+ | |||
+ | <WRAP center round important 60%> | ||
+ | **Important** : **[[https:// | ||
+ | </ | ||
+ | |||
+ | Des alertes sont ensuite passées à l' | ||
+ | |||
+ | ====LAB #4 - Mise en Place d'une Solution Prometheus==== | ||
+ | |||
+ | Connectez-vous à la VM **Gateway_10.0.2.40_VNC**. | ||
+ | |||
+ | ===4.1 - Déploiement du Stack avec Helm=== | ||
+ | |||
+ | Ajoutez le dépôt **prometheus-community** : | ||
+ | |||
+ | < | ||
+ | trainee@gateway: | ||
+ | " | ||
+ | |||
+ | trainee@gateway: | ||
+ | </ | ||
+ | |||
+ | Installez ensuite le chart **kube-prometheus-stack** : | ||
+ | |||
+ | < | ||
+ | trainee@gateway: | ||
+ | NAME: prometheus | ||
+ | LAST DEPLOYED: Thu Dec 8 17:04:17 2022 | ||
+ | NAMESPACE: default | ||
+ | STATUS: deployed | ||
+ | REVISION: 1 | ||
+ | NOTES: | ||
+ | kube-prometheus-stack has been installed. Check its status by running: | ||
+ | kubectl --namespace default get pods -l " | ||
+ | |||
+ | Visit https:// | ||
+ | </ | ||
+ | |||
+ | Patientez jusqu' | ||
+ | |||
+ | < | ||
+ | trainee@gateway: | ||
+ | NAME | ||
+ | prometheus-kube-prometheus-operator-689dd6679c-2th6f | ||
+ | prometheus-kube-state-metrics-6cfd96f4c8-wrw2n | ||
+ | prometheus-prometheus-node-exporter-8cb4s | ||
+ | prometheus-prometheus-node-exporter-ll4qp | ||
+ | prometheus-prometheus-node-exporter-x87f7 | ||
+ | </ | ||
+ | |||
+ | Consultez maintenant l' | ||
+ | |||
+ | < | ||
+ | trainee@gateway: | ||
+ | NAME | ||
+ | pod/ | ||
+ | pod/ | ||
+ | pod/ | ||
+ | pod/ | ||
+ | pod/ | ||
+ | |||
+ | NAME TYPE CLUSTER-IP | ||
+ | service/ | ||
+ | service/ | ||
+ | service/ | ||
+ | service/ | ||
+ | service/ | ||
+ | |||
+ | NAME | ||
+ | daemonset.apps/ | ||
+ | |||
+ | NAME READY | ||
+ | deployment.apps/ | ||
+ | deployment.apps/ | ||
+ | |||
+ | NAME | ||
+ | replicaset.apps/ | ||
+ | replicaset.apps/ | ||
+ | |||
+ | NAME READY AGE | ||
+ | statefulset.apps/ | ||
+ | statefulset.apps/ | ||
+ | </ | ||
+ | |||
+ | Dans cette sortie on constate : | ||
+ | |||
+ | * 2 StatefulSets dont : | ||
+ | * le serveur Prometheus **statefulset.apps/ | ||
+ | * l' | ||
+ | * 2 Deployments dont : | ||
+ | * l' | ||
+ | * le kube-state-metrics **deployment.apps/ | ||
+ | * 2 ReplicaSets créés par les Deployments : | ||
+ | * **replicaset.apps/ | ||
+ | * **replicaset.apps/ | ||
+ | * 1 DaemonSet **daemonset.apps/ | ||
+ | * les pods de ce DaemonSet sont responsables pour la transformation des métriques des noeuds en métriques Prometheus | ||
+ | |||
+ | L' | ||
+ | |||
+ | < | ||
+ | trainee@gateway: | ||
+ | NAME | ||
+ | prometheus-kube-prometheus-alertmanager-overview | ||
+ | prometheus-kube-prometheus-apiserver | ||
+ | prometheus-kube-prometheus-cluster-total | ||
+ | prometheus-kube-prometheus-controller-manager | ||
+ | prometheus-kube-prometheus-etcd | ||
+ | prometheus-kube-prometheus-grafana-datasource | ||
+ | prometheus-kube-prometheus-grafana-overview | ||
+ | prometheus-kube-prometheus-k8s-coredns | ||
+ | prometheus-kube-prometheus-k8s-resources-cluster | ||
+ | prometheus-kube-prometheus-k8s-resources-namespace | ||
+ | prometheus-kube-prometheus-k8s-resources-node | ||
+ | prometheus-kube-prometheus-k8s-resources-pod | ||
+ | prometheus-kube-prometheus-k8s-resources-workload | ||
+ | prometheus-kube-prometheus-k8s-resources-workloads-namespace | ||
+ | prometheus-kube-prometheus-kubelet | ||
+ | prometheus-kube-prometheus-namespace-by-pod | ||
+ | prometheus-kube-prometheus-namespace-by-workload | ||
+ | prometheus-kube-prometheus-node-cluster-rsrc-use | ||
+ | prometheus-kube-prometheus-node-rsrc-use | ||
+ | prometheus-kube-prometheus-nodes | ||
+ | prometheus-kube-prometheus-nodes-darwin | ||
+ | prometheus-kube-prometheus-persistentvolumesusage | ||
+ | prometheus-kube-prometheus-pod-total | ||
+ | prometheus-kube-prometheus-prometheus | ||
+ | prometheus-kube-prometheus-proxy | ||
+ | prometheus-kube-prometheus-scheduler | ||
+ | prometheus-kube-prometheus-workload-total | ||
+ | </ | ||
+ | |||
+ | ainsi que des Secrets : | ||
+ | |||
+ | < | ||
+ | trainee@gateway: | ||
+ | NAME TYPE | ||
+ | alertmanager-prometheus-kube-prometheus-alertmanager | ||
+ | alertmanager-prometheus-kube-prometheus-alertmanager-generated | ||
+ | alertmanager-prometheus-kube-prometheus-alertmanager-tls-assets-0 | ||
+ | alertmanager-prometheus-kube-prometheus-alertmanager-web-config | ||
+ | my-secret | ||
+ | prometheus-grafana | ||
+ | prometheus-kube-prometheus-admission | ||
+ | prometheus-prometheus-kube-prometheus-prometheus | ||
+ | prometheus-prometheus-kube-prometheus-prometheus-tls-assets-0 | ||
+ | prometheus-prometheus-kube-prometheus-prometheus-web-config | ||
+ | sh.helm.release.v1.nfs-subdir-external-provisioner.v1 | ||
+ | sh.helm.release.v1.prometheus.v1 | ||
+ | </ | ||
+ | |||
+ | des **Custom Resource Definitions** ou crd : | ||
+ | |||
+ | < | ||
+ | trainee@gateway: | ||
+ | NAME CREATED AT | ||
+ | alertmanagerconfigs.monitoring.coreos.com | ||
+ | alertmanagers.monitoring.coreos.com | ||
+ | bgpconfigurations.crd.projectcalico.org | ||
+ | bgppeers.crd.projectcalico.org | ||
+ | blockaffinities.crd.projectcalico.org | ||
+ | caliconodestatuses.crd.projectcalico.org | ||
+ | clusterinformations.crd.projectcalico.org | ||
+ | felixconfigurations.crd.projectcalico.org | ||
+ | globalnetworkpolicies.crd.projectcalico.org | ||
+ | globalnetworksets.crd.projectcalico.org | ||
+ | hostendpoints.crd.projectcalico.org | ||
+ | ipamblocks.crd.projectcalico.org | ||
+ | ipamconfigs.crd.projectcalico.org | ||
+ | ipamhandles.crd.projectcalico.org | ||
+ | ippools.crd.projectcalico.org | ||
+ | ipreservations.crd.projectcalico.org | ||
+ | kubecontrollersconfigurations.crd.projectcalico.org | ||
+ | networkpolicies.crd.projectcalico.org | ||
+ | networksets.crd.projectcalico.org | ||
+ | podmonitors.monitoring.coreos.com | ||
+ | probes.monitoring.coreos.com | ||
+ | prometheuses.monitoring.coreos.com | ||
+ | prometheusrules.monitoring.coreos.com | ||
+ | servicemonitors.monitoring.coreos.com | ||
+ | thanosrulers.monitoring.coreos.com | ||
+ | </ | ||
+ | |||
+ | ===4.2 - Consultation des Données avec Grafana=== | ||
+ | |||
+ | L' | ||
+ | |||
+ | Grafana est une plate-forme de visualisation de données interactive open source, développée par Grafana Labs, qui permet aux utilisateurs de voir leurs données via des tableaux et des graphiques qui sont unifiés dans un tableau de bord (ou plusieurs tableaux de bord ) pour une interprétation et une compréhension plus faciles. | ||
+ | |||
+ | Consultez les objets Grafana : | ||
+ | |||
+ | < | ||
+ | trainee@gateway: | ||
+ | pod/ | ||
+ | service/ | ||
+ | deployment.apps/ | ||
+ | replicaset.apps/ | ||
+ | </ | ||
+ | |||
+ | Vérifiez le port utilisé par Grafana : | ||
+ | |||
+ | < | ||
+ | trainee@gateway: | ||
+ | logger=http.server t=2022-12-08T16: | ||
+ | </ | ||
+ | |||
+ | ainsi que le nom de l' | ||
+ | |||
+ | < | ||
+ | trainee@gateway: | ||
+ | logger=sqlstore t=2022-12-08T16: | ||
+ | </ | ||
+ | |||
+ | Le mot de passe par défaut de l' | ||
+ | |||
+ | <WRAP center round important 60%> | ||
+ | **Important** : Notez que le mot de passe est **prom-operator**. | ||
+ | </ | ||
+ | |||
+ | Mettez en place une redirection de port : | ||
+ | |||
+ | < | ||
+ | trainee@gateway: | ||
+ | Forwarding from 127.0.0.1: | ||
+ | Forwarding from [::1]:3000 -> 3000 | ||
+ | |||
+ | </ | ||
+ | |||
+ | Consultez maintenant la VM **Gateway_10.0.2.40_VNC** et lancez le navigateur web. Saisissez l'URL **http:// | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | Cliquez ensuite sur **Dashboards > Browse > Kubernetes / Compute Resources / Node (Pods)** : | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | Dernièrement, | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | ===4.3 - Consultation des Alertes avec le Web UI de Prometheus=== | ||
+ | |||
+ | Pour consultez le Web UI de Prometheus, mettez en place une redirection de port : | ||
+ | |||
+ | < | ||
+ | trainee@gateway: | ||
+ | Forwarding from 127.0.0.1: | ||
+ | Forwarding from [::1]:9090 -> 9090 | ||
+ | </ | ||
+ | |||
+ | Retournez dans l' | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | Pour consultez la liste des alertes, cliquez sur le lien Alerts dans le menu en haut de la page : | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | ----- | ||
+ | Copyright © 2024 Hugh Norris |