Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
Prochaine révision
Révision précédente
elearning:workbooks:kubernetes:k8s06 [2022/09/04 11:44] – created adminelearning:workbooks:kubernetes:k8s06 [2025/01/17 15:25] (Version actuelle) admin
Ligne 1: Ligne 1:
 ~~PDF:LANDSCAPE~~ ~~PDF:LANDSCAPE~~
  
-Version - **2022.02**+Version - **2024.01**
  
 Dernière mise-à-jour : ~~LASTMOD~~ Dernière mise-à-jour : ~~LASTMOD~~
  
-======DOF304 Gestion du Réseau, des Services et d'une Architecture de Microservices======+ 
 +======DOF307 Troubleshooting K8s======
  
 =====Contenu du Module===== =====Contenu du Module=====
  
-  * **DOF304 Gestion du Réseau, des Services et d'une Architecture de Microservices**+  * **DOF307 Troubleshooting K8s**
     * Contenu du Module     * Contenu du Module
-    * LAB #1 - Gestion du Réseau et des Services +    * LAB #1 - Le Serveur API 
-      * 1.1 - Présentation +      * 1.1 - Connexion Refusée 
-      * 1.2 - Le Service NodePort +      * 1.2 - Journaux des Pods Système 
-      * 1.- Le Service ClusterIP +    * LAB #2 - Les Noeuds 
-    * LAB #Gestion de l'Architecture des Microservices +      * 2.- Le Statut NotReady 
-      * 2.1 - Présentation +    * LAB #Les Pods 
-      * 2.2 - Création des Deployments +      * 3.1 - L'Erreur ImagePullBackOff 
-      * 2.Création des Services +      * 3.2 - L'Erreur CrashLoopBackOff 
-      * 2.Déployer l'Application +    * LAB #4 - Les Conteneurs 
-      * 2.5 - Scaling Up+      * 4.La Commande exec 
 +    * LAB #5 - Le Réseau 
 +      * 5.kube-proxy et le DNS 
 +      * 5.2 Le Conteneur netshoot
  
-=====LAB #1 - Gestion du Réseau et des Services=====+=====LAB #1 - Le Serveur API=====
  
-====1.1 - Présentation====+====1.1 - Connexion Refusée====
  
-Kubernetes impose des conditions pour l’implémentation d'un réseau :+Quand il n'est pas possible de se connecter au serveur API de K8s, on obtient une erreur telle que :
  
-  * Les PODs sur un nœud peuvent communiquer avec tous les PODs sur tous le nœuds sans utiliser NAT, +<code> 
-  * Les agents sur un nœud (par exemple kubelet) peuvent communiquer avec tous les PODs sur le nœud.+trainee@kubemaster:~$ kubectl get pods 
 +The connection to the server localhost:8080 was refused - did you specify the right host or port? 
 +</code>
  
-<WRAP center round important> +En règle générale, cette erreur est due à une des trois situations suivantes :
-**Important** : La description technique et détaillée de l'approche réseau de Kubernetes peut être consultée à l'adresse : **[[https://kubernetes.io/docs/concepts/cluster-administration/networking/]]**. +
-</WRAP>+
  
-Dans le cluster de ce cours, le réseau mis en place pour Kubernetes est le 192.168.56.0/24+===Le Service kubelet===
  
-Actuellement il y a 3 PODs dans le cluster :+Vérifiez que le service kubelet est activé et en cours d'exécution sur le contrôleur :
  
 <code> <code>
-root@kubemaster:~# kubectl get pods +trainee@kubemaster:~$ su 
-NAME                                READY   STATUS    RESTARTS   AGE +Mot de passe : fenestros
-myapp-deployment-57c6cb89d9-dh4cb   1/    Running            7h36m +
-myapp-deployment-57c6cb89d9-f69nk   1/    Running            7h36m +
-myapp-deployment-57c6cb89d9-q7d4p   1/    Running            7h36m +
-</code>+
  
-Sous Kubernetes, les adresses IP sont attachées aux PODs :+root@kubemaster:~# systemctl status kubelet 
 +● kubelet.service - kubelet: The Kubernetes Node Agent 
 +   Loaded: loaded (/lib/systemd/system/kubelet.service; enabled; vendor preset: enable 
 +  Drop-In: /etc/systemd/system/kubelet.service.d 
 +           └─10-kubeadm.conf 
 +   Active: active (running) since Fri 2022-09-16 09:29:34 CEST; 1 weeks 4 days ago 
 +     Docs: https://kubernetes.io/docs/home/ 
 + Main PID: 550 (kubelet) 
 +    Tasks: 17 (limit: 4915) 
 +   Memory: 129.6M 
 +      CPU: 4h 16min 54.676s 
 +   CGroup/system.slice/kubelet.service 
 +           └─550 /usr/bin/kubelet --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kub
  
-<code> +WarningJournal has been rotated since unit was started. Log output is incomplete or  
-root@kubemaster:~# kubectl get pods -o wide +lines 1-14/14 (END) 
-NAME                                READY   STATUS    RESTARTS   AGE     IP               NODE                       NOMINATED NODE   READINESS GATES +[q]
-myapp-deployment-57c6cb89d9-dh4cb   1/1     Running            7h37m   192.168.150.12   kubenode2.ittraining.loc   <none>           <none> +
-myapp-deployment-57c6cb89d9-f69nk   1/1     Running            7h37m   192.168.239.19   kubenode1.ittraining.loc   <none>           <none> +
-myapp-deployment-57c6cb89d9-q7d4p   1/    Running            7h37m   192.168.239.20   kubenode1.ittraining.loc   <none>           <none>+
 </code> </code>
  
-<WRAP center round important> +===La Variable KUBECONFIG===
-**Important** : Notez que les adresses **192.168.239.x** sont associées aux PODs sur kubenode1 tandis que les adresses **192.168.150.x** sont associées aux PODs sur kubenode2. Ces adresses sont issues du réseau **192.168.0.0/16** stipulé par l'option **--pod-network-cidr** lors de l'initialisation du maître du cluster. +
-</WRAP>+
  
-En sachant que dans chaque POD existe un conteneur Nginx, testez si vous pouvez afficher la page d'accueil de Nginx en vous connectant à kubenode1 et kubenode2 à partir de votre Gateway :+Si vous utilisez le compte root pour interagir avec K8s, vérifiez que la variable **KUBECONFIG** est renseignée correctement :
  
 <code> <code>
-trainee@kubemaster:~$ exit +root@kubemaster:~# echo $KUBECONFIG 
-déconnexion +/etc/kubernetes/admin.conf
-Connection to 10.0.2.65 closed. +
-trainee@gateway:~$ curl 192.168.56.3 +
-curl: (7) Failed to connect to 192.168.56.3 port 80: Connection refused +
-trainee@gateway:~$ curl 192.168.56.4 +
-curl: (7) Failed to connect to 192.168.56.4 port 80: Connection refused+
 </code> </code>
  
-<WRAP center round important> +===Le Fichier $HOME/.kube/config===
-**Important** : Notez l'échec de la connexion. +
-</WRAP>+
  
-Testez maintenant si vous pouvez afficher la page d'accueil de Nginx en vous connectant à un des PODs **à partir de votre Gateway** :+Si vous utilisez un compte d'un utilisateur normal pour interagir avec K8s, vérifiez que le fichier **$HOME/.kube/config** est renseigné correctement et qu'il possède les bonnes permissions :
  
 <code> <code>
-trainee@gateway:~$ curl 192.168.239.19 +root@kubemaster:~# exit 
-^C+déconnexion 
 +trainee@kubemaster:~$ 
 + 
 +trainee@kubemaster:~$ cat $HOME/.kube/config 
 +apiVersion: v1 
 +clusters: 
 +- cluster: 
 +    certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUMvakNDQWVhZ0F3SUJBZ0lCQURBTkJna3Foa2lHOXcwQkFRc0ZBREFWTVJNd0VRWURWUVFERXdwcmRXSmwKY201bGRHVnpNQjRYRFRJeU1Ea3dOREEzTXpVek5sb1hEVE15TURrd01UQTNNelV6Tmxvd0ZURVRNQkVHQTFVRQpBeE1LYTNWaVpYSnVaWFJsY3pDQ0FTSXdEUVlKS29aSWh2Y05BUUVCQlFBRGdnRVBBRENDQVFvQ2dnRUJBS2RICm9PbXpsd2xEdXdDSWhPdEk5aEVVYXpMWjNhNExDVVRyZDlIdlBSWDBYZGZGS2w3S29OS3RXYVhjK1pBbFNBazAKaXVZYzE1NXlIQ3ViYUEyU1FmYzZFMElIZ25ISlFqSy9WSTI1Szc1Zjg5NHk5dGlvczVoc1dDemdodUhUTkEwTgpyZmhzb0lPMHBHU0dEdStrR1lpN25lQVZwZUwyL2JjYy8xdzVyaEh4bGFackNsaFNsaVJQcWFqclFyVWNSWm5lCk9XS09TWjNObi9neTRGUktlRXpzOTllNU14OXp2Y0JxWC9zSTRqYjJoRWQ0NnBuTG1OMlM4NEFjQzR6R01iRHEKSHY0aDMra1lkbmE5YUJwN3hSWGNHNWRlZVl1Yzhramt1dEhGUlNMYUlLSzBYa2lCbEtBOHR0YU1tSkYrczRMdgplblhDTEpYd1RCWWtGd3RMemc4Q0F3RUFBYU5aTUZjd0RnWURWUjBQQVFIL0JBUURBZ0trTUE4R0ExVWRFd0VCCi93UUZNQU1CQWY4d0hRWURWUjBPQkJZRUZOdCtnOEJtVWNoekY4My9ZSEcveWIxaVdmc0lNQlVHQTFVZEVRUU8KTUF5Q0NtdDFZbVZ5Ym1WMFpYTXdEUVlKS29aSWh2Y05BUUVMQlFBRGdnRUJBRWZOMHoyVnl6dUxiek5YOC9pcAp0VFFGV2Q4TDJvMUV6L0FKZzR2akpMTG9VcmVKTHhtckpMcW1Yc3JUU2hCYXYzODJxcHRjeDhqNktRRjMwZzIyCnJxSUxuNzN5NFdBYVJKNFgwM2dtUGlheWlmZzdYOHFNaEpjbmtqRlN3Vy92VUt1YWkvcDdpWkFQMUVCL1FtUFgKNXphUEZIT1d3QWIvQzU2ZmxrMmpJcVE3bmRvL2VpOFRsdTI5MG1JYUdGSFRPU0hCYk1ReEE3RjVUV3ZXQ0l5aQpPdTA5REFZdnU3dGFSZlA1SkhVdFlQL0Vady9KMUxlaWxrL3ZMbStTSXV0L0puR2hvTDJUdWVQUnd3TCtXRWswClNrS3RKQkVFQ2hVYkdzZVN2RndEdS96NlgvQXFtSXRyQXJnVy9mTlV1TW9GRHo0MXFLYll4ekZuZ2hkSTN5WGsKQ25NPQotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0tCg== 
 +    server: https://192.168.56.2:6443 
 +  name: kubernetes 
 +contexts: 
 +- context: 
 +    cluster: kubernetes 
 +    user: kubernetes-admin 
 +  name: kubernetes-admin@kubernetes 
 +current-context: kubernetes-admin@kubernetes 
 +kind: Config 
 +preferences: {} 
 +users: 
 +- name: kubernetes-admin 
 +  user: 
 +    client-certificate-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURJVENDQWdtZ0F3SUJBZ0lJZDVaTG10Yng1ODh3RFFZSktvWklodmNOQVFFTEJRQXdGVEVUTUJFR0ExVUUKQXhNS2EzVmlaWEp1WlhSbGN6QWVGdzB5TWpBNU1EUXdOek0xTXpaYUZ3MHlNekE1TURReE1ESTRNakJhTURReApGekFWQmdOVkJBb1REbk41YzNSbGJUcHRZWE4wWlhKek1Sa3dGd1lEVlFRREV4QnJkV0psY201bGRHVnpMV0ZrCmJXbHVNSUlCSWpBTkJna3Foa2lHOXcwQkFRRUZBQU9DQVE4QU1JSUJDZ0tDQVFFQTZLLy8zREhnczZ1c2VBaDIKWitVdFZxekRSRERIMUt5RjB2VlhtUml6alcyVHR3dEhjS3NKV3dUcVprS3BMb2hMSndNVUEyeVlrS04xWXpLRwpjVWc4N2VvcGJBcWRTS3dFclBOdHZ5WlBPK2VrQ3AxQVo1dXA5T3cxM1FVQkZHZVpkR2haVkZHV1paaWNsMkQzCnRjY3dqcmhDS3pUcmVhMTFOWkZIWGZqTmxnaXNlYk4rbGZEcDM4K3l3cVBDQXNrWkdlYUFZcFlvSXlqRlQwSS8KNDA2dXlpeUI1OHdxaE1zQjU3S1NWWko3K01ncGR0SjVCcmZOeE5lNng3cmQ3TXNwb0VWeXlBUlBMdk50WTdWago0VGVMSm9aNDYwci81cG5EWjlXbFgrMnN2VXRFRjVJcmdoMnZhU3pLNHBWaEJRS2M3S2dSdXVtZjBFYnphWXhWCmQ5eUVDUUlEQVFBQm8xWXdWREFPQmdOVkhROEJBZjhFQkFNQ0JhQXdFd1lEVlIwbEJBd3dDZ1lJS3dZQkJRVUgKQXdJd0RBWURWUjBUQVFIL0JBSXdBREFmQmdOVkhTTUVHREFXZ0JUYmZvUEFabEhJY3hmTi8yQnh2OG05WWxuNwpDREFOQmdrcWhraUc5dzBCQVFzRkFBT0NBUUVBaFNNTGkrQStsQmkyQUI1K1IxTTRLNmRYRjc0RjNvUlNKT3pWCjlkQmppejV2czdtSkFNeURrLzBYQzlaVmhER2N1QnZiQ1RzWVBuOHhlZXV6Uml6OGI2Ny8zNW4rVUp0SlZoRFgKdmdaejJkQmFSQ3ZtVStoV1RueW5CUU9lRDlEQ2RuQXA2ZlJCNE9oN1pEOXNXZGxoOEMrbTBMaXE1UzV5Uy92SQpVeWVQZ096aWlZMlF5ajdwTjhqczd5OG9Ia2lGOTM2Nlh3V0VoK1lWeGgxcG9iMGhIa1ZBUEZVS25Ed0xKS2N1CmY4MlBSU0dSWVZoaVlWZFM2ZTg1TFhxRkkwMVdqd2txVVo4NHhPVVYyekVCSGlIZ0lKN09VbjArbEYrQW8wVkoKZ1l2L2kzYW9IcUsxc21kejVjWWNxQTlPaW1xalZ5RWV6czhjS0xYbFRnZ2VQM2krOVE9PQotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0tCg== 
 +    client-key-data: LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0tLQpNSUlFb3dJQkFBS0NBUUVBNksvLzNESGdzNnVzZUFoMlorVXRWcXpEUkRESDFLeUYwdlZYbVJpempXMlR0d3RICmNLc0pXd1RxWmtLcExvaExKd01VQTJ5WWtLTjFZektHY1VnODdlb3BiQXFkU0t3RXJQTnR2eVpQTytla0NwMUEKWjV1cDlPdzEzUVVCRkdlWmRHaFpWRkdXWlppY2wyRDN0Y2N3anJoQ0t6VHJlYTExTlpGSFhmak5sZ2lzZWJOKwpsZkRwMzgreXdxUENBc2taR2VhQVlwWW9JeWpGVDBJLzQwNnV5aXlCNTh3cWhNc0I1N0tTVlpKNytNZ3BkdEo1CkJyZk54TmU2eDdyZDdNc3BvRVZ5eUFSUEx2TnRZN1ZqNFRlTEpvWjQ2MHIvNXBuRFo5V2xYKzJzdlV0RUY1SXIKZ2gydmFTeks0cFZoQlFLYzdLZ1J1dW1mMEViemFZeFZkOXlFQ1FJREFRQUJBb0lCQUNHTVpwNXZ6bzc1SEllOQo2Sng0TFg1R3NHeWZmK0JJODQ2RDh4cE90bXlZdE9oNlJ0V1d3MldOSXVLVmorRDJvNmMvU1Y1cEJPSXR2eG9MClNka0JhazkvS0hPOFlBci9TamxKYTdSWXFLbmhid1Jjd2RGdVh5WEIvTTRlRDViS2pSUjhpd3llS3NvQkkrcXIKZjJ1RkNabzZOTWdYL0M5eDgrbENSZ0RsZzNhekNRQm1wVW9CM2ZmbjdpaDRIc3MzMkR6K29FcEx2TnkyS2o0RgpUTFVGQ0pTcTFKTXVQN2tVaXI1WUpzUTFySFcrUlNiNEZVNlJpTzkzSjJNdStWVmcxR0dxMEI4c3o5eStOSDNXClhJY3B1MGNtOXN2MzBUZG1OcGRWRnZqOXR6ZzJlbW1wZTNFcmdQak1LQjFUWDdtT3BrVXVsZjNKQ1VRYk1JS1UKVDdaajg3VUNnWUVBNlg3Vnp5ZmprU3hFVU0xbEFQbG1DNjJkUFJPajQxQjA5M2dYaHUyQ3hIQlRKUzdrYVhsSgpTOHFFcjlrV1FvRFVoM1N5RldhSkhNZy9lOWJRdHhBRWl5alFvbE4vSEZ2aEdrWGNNVm1pMXE3ZFdUVjM3aEVCCmExekNPcFVtZWR4OWszanpKUkx3b1VaNUtySTR0WkJyOXNwQXltTEZPb09oMm16NEtYSXo4ZWNDZ1lFQS94MDYKclJ2NzJGNXI3UmlLSG45cHUyUHJEYkdlSFVGZ01tZHI0MW9NQnlHem5ZY3E2M2FmM3RacWFEVGs1SnBDTFlDeQpvUEk1UlYvQWdvQmNmeDhLVzRpdW0rVTZhOTN2R1FCWkxJY2o3c1k1SnBFSysvYnZTUGNDTzJlU214c3JhZ01PCm5odjV0ZUxYSlpTelZwcERzZ2hmQXJ3NDUxQmZFclVWOEVwZi9JOENnWUJQbnh5eHcxeHFpTG5UQS9kSldjSmUKZ1JsNVZsVXdrcU1RTURkMW4xQlVSQ2xXS0tOakJDVG1YMnpYdWlOSkVqMW00M2hHcSt4ZGtEdDFzMDhBM2NsdQoyc0FxV21haCtRTE52cnpUWjBtTUE1MGZhb2cyK2oyTnF0Zmd1ak9nb250LzZtS2ZaZElBYk5Pc3A1R0crSFNZCmQyZVluQTI5WWwyeTZpM0ZsRmY2U1FLQmdRRFdFdDd6K0hHREJPaW4wbG5FY2NKMW5zalZldUJsU0VEQ3l3bzcKZzRwb1NaMkJhTFZaVlBlZWRHcGgrMUMvaTdwUW1KaE1lallZd3RxMko2UjJmOE9mUDdqVjFLc0xiUGFBRWt6QwpFcnpTVnNBS1h0Zkt5MUhMOW9xRzhzaVJJMkZ3MmhQZ0ZUV2JyVGhBcnVFMm9NaUJrb2kzc041SExLZzYrSDNxClgxN2dmUUtCZ0ZYUUw5TzBqOWNYM3FzVU00K0pyL3JwUXJ1L2t4b1YydFpQZzljVEplN3p2dVYrazE2ZFhaTisKS202L0tQNWN5UnIzYnFrUXZBYjZHK2xlcUh0QTVvTk9SalI5bDI0SjNnNnl5YlBrakR2eU8rRVgrUlNDV203QwpiZ2NxeE16Q1BJYmtWSEpsYXdqczJKaWp5YTh0OUV6N09YcWFXYU8yakptK2pVVzdsaStmCi0tLS0tRU5EIFJTQSBQUklWQVRFIEtFWS0tLS0tCg==
 </code> </code>
- 
-Connectez-vous à **kubemaster** : 
  
 <code> <code>
-trainee@gateway:~$ ssh -l trainee 192.168.56.2 +trainee@kubemaster:~$ ls -l $HOME/.kube/config 
-trainee@192.168.56.2's password: trainee +-rw------- 1 trainee sudo 5636 sept28 12:56 /home/trainee/.kube/config
-Linux kubemaster.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 /usr/share/doc/*/copyright. 
- 
-Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent 
-permitted by applicable law. 
-Last login: Wed Jul 13 15:45:46 2022 from 10.0.2.40 
 trainee@kubemaster:~$ su - trainee@kubemaster:~$ su -
-Mot de passe : fenestros +Mot de passe :  
-root@kubemaster:~#+root@kubemaster:~# 
 </code> </code>
  
-Bien évidementil est possible d'afficher la page en vous connectant à un des PODs de **l'intérieur** du cluster :+====1.2 - Journaux des Pods Système==== 
 + 
 +Sià ce stade, vous n'avez pas trouvé d'erreurs apparentes, il convient de regarder le journal du pod **kube-system_kube-apiserver-xxxxxxxxxxxxx** :
  
 <code> <code>
-root@kubemaster:~# curl 192.168.239.19 +root@kubemaster:~# ls -l /var/log/pods 
-<!DOCTYPE html> +total 28 
-<html> +drwxr-xr-x 6 root root 4096 sept.  4 09:44 kube-system_calico-node-dc7hd_3fe340ed-6df4-4252-9e4e-8c244453176a 
-<head> +drwxr-xr-x 3 root root 4096 sept.  4 13:00 kube-system_coredns-565d847f94-tqd8z_d96f42ed-ebd4-4eb9-8c89-2d80b81ef9cf 
-<title>Welcome to nginx!</title> +drwxr-xr-x 3 root root 4096 sept.  4 12:36 kube-system_etcd-kubemaster.ittraining.loc_ddbb10499877103d862e5ce637b18ab1 
-<style> +drwxr-xr-x 3 root root 4096 sept.  4 12:36 kube-system_kube-apiserver-kubemaster.ittraining.loc_ec70600cac9ca8c8ea9545f1a42f82e5 
-    body { +drwxr-xr-x 3 root root 4096 sept.  4 12:36 kube-system_kube-controller-manager-kubemaster.ittraining.loc_0e3dcf54223b4398765d21e9e6aaebc6 
-        width35em; +drwxr-xr-x 3 root root 4096 sept.  4 12:31 kube-system_kube-proxy-x7fpc_80673937-ff21-4dba-a821-fb3b0b1541a4 
-        margin0 auto; +drwxr-xr-x 3 root root 4096 sept 4 12:36 kube-system_kube-scheduler-kubemaster.ittraining.loc_c3485d2a42b90757729a745cd8ee5f7d
-        font-familyTahoma, Verdana, Arial, sans-serif; +
-    } +
-</style> +
-</head> +
-<body> +
-<h1>Welcome to nginx!</h1> +
-<p>If you see this page, the nginx web server is successfully installed and +
-workingFurther configuration is required.</p>+
  
-<p>For online documentation and support please refer to +root@kubemaster:~# ls -l /var/log/pods/kube-system_kube-apiserver-kubemaster.ittraining.loc_ec70600cac9ca8c8ea9545f1a42f82e5 
-<a href="http://nginx.org/">nginx.org</a>.<br/> +total 4 
-Commercial support is available at +drwxr-xr-x 2 root root 4096 sept. 16 09:31 kube-apiserver
-<a href="http://nginx.com/">nginx.com</a>.</p>+
  
-<p><em>Thank you for using nginx.</em></p> +root@kubemaster:~# ls -l /var/log/pods/kube-system_kube-apiserver-kubemaster.ittraining.loc_ec70600cac9ca8c8ea9545f1a42f82e5/kube-apiserver 
-</body> +total 2420 
-</html>+-rw-r----- 1 root root 1009731 sept. 16 08:19 0.log 
 +-rw-r----- 1 root root 1460156 sept. 28 12:22 1.log 
 + 
 +root@kubemaster:~# tail /var/log/pods/kube-system_kube-apiserver-kubemaster.ittraining.loc_ec70600cac9ca8c8ea9545f1a42f82e5/kube-apiserver/1.log 
 +2022-09-28T11:22:18.406048353+02:00 stderr F Trace[1595276047]: [564.497826ms] [564.497826ms] END 
 +2022-09-28T11:22:18.406064364+02:00 stderr F I0928 09:22:18.405784       1 trace.go:205] Trace[1267846829]: "Get" url:/apis/coordination.k8s.io/v1/namespaces/kube-system/leases/kube-scheduler,user-agent:kube-scheduler/v1.25.0 (linux/amd64) kubernetes/a866cbe/leader-election,audit-id:1b71bbbb-49ad-4f40-b859-f40b06416452,client:192.168.56.2,accept:application/vnd.kubernetes.protobuf, */*,protocol:HTTP/2.0 (28-Sep-2022 09:22:17.899) (total time: 505ms): 
 +2022-09-28T11:22:18.406072365+02:00 stderr F Trace[1267846829]: ---"About to write a response" 505ms (09:22:18.405) 
 +2022-09-28T11:22:18.406079291+02:00 stderr F Trace[1267846829]: [505.988424ms] [505.988424ms] END 
 +2022-09-28T12:17:17.854768983+02:00 stderr F I0928 10:17:17.854660       1 alloc.go:327] "allocated clusterIPs" service="default/service-netshoot" clusterIPs=map[IPv4:10.107.115.28] 
 +2022-09-28T12:22:18.832566527+02:00 stderr F I0928 10:22:18.831876       1 trace.go:205] Trace[338168453]: "List(recursive=true) etcd3" audit-id:8acb508c-5121-4d18-8f8a-ed87d01f33b8,key:/pods/default,resourceVersion:,resourceVersionMatch:,limit:500,continue: (28-Sep-2022 10:22:18.063) (total time: 768ms): 
 +2022-09-28T12:22:18.83263296+02:00 stderr F Trace[338168453]: [768.168206ms] [768.168206ms] END 
 +2022-09-28T12:22:18.832893075+02:00 stderr F I0928 10:22:18.832842       1 trace.go:205] Trace[238339745]: "List" url:/api/v1/namespaces/default/pods,user-agent:kubectl/v1.25.0 (linux/amd64) kubernetes/a866cbe,audit-id:8acb508c-5121-4d18-8f8a-ed87d01f33b8,client:192.168.56.2,accept:application/json;as=Table;v=v1;g=meta.k8s.io,application/json;as=Table;v=v1beta1;g=meta.k8s.io,application/json,protocol:HTTP/2.0 (28-Sep-2022 10:22:18.063) (total time: 769ms): 
 +2022-09-28T12:22:18.832902737+02:00 stderr F Trace[238339745]: ---"Listing from storage done" 768ms (10:22:18.831) 
 +2022-09-28T12:22:18.832908995+02:00 stderr F Trace[238339745]: [769.149103ms] [769.149103ms] END
 </code> </code>
  
-<WRAP center round important> +A noter que quand le serveur API redevient fonctionnel, il est possible de consulter le journal en utilisant la commande **kubectl logs** :
-**Important** : Retenez donc qu'à ce stade il n'est pas possible d'afficher la page d'accueil de Nginx en vous connectant de l'extérieur du cluster. +
-</WRAP> +
- +
-Lors de l'installation du cluster nous avons spécifié l'utilisation d'une extension réseau appelée **Calico**, issue de la liste suivante : +
- +
-  * **[[https://www.projectcalico.org/|Calico]]**, +
-  * **[[https://cilium.io/|Cilium]]**, +
-  * **[[https://coreos.com/flannel/docs/latest/|Flannel]]**, +
-  * **[[https://www.kube-router.io/|Kube-router]]**, +
-  * **[[https://romana.io/|Romana]]**, +
-  * **[[https://www.weave.works/oss/net/|WeaveNet]]**, +
-  * **[[https://antrea.io/docs/master/getting-started/|Antrea]]**, +
-  * **[[https://github.com/alauda/kube-ovn|kube-ovn]]**, +
-  * Canal (utilise Flannel pour le réseau et Calico pour le pare-feu). +
- +
-<WRAP center round important> +
-**Important** : Une étude comparative des extensions réseau pour Kubernetes peut être trouvée à la page : **[[https://itnext.io/benchmark-results-of-kubernetes-network-plugins-cni-over-10gbit-s-network-updated-august-2020-6e1b757b9e49]]**. +
-</WRAP> +
- +
-Ces extensions permettent la mise en place de Services : +
- +
-  * NodePort, +
-    * Ce Service rend un POD accessible sur un port du nœud le contenant, +
-  * ClusterIP +
-    * Ce Service crée une adresse IP virtuelle afin de permettre la communication entre de services différents dans le cluster, par exemple des serveurs front-end avec des serveurs back-end, +
-  * LoadBalancer +
-    * Ce service provisionne un équilibrage de charge pour une application dans certains fournisseurs de Cloud publique tels **A**mazon **W**eb **S**ervices et **G**oogle **C**loud **P**latform. +
- +
-====1.2 - Le Service NodePort==== +
- +
-Le Service NodePort définit trois ports : +
- +
-  * **TargetPort** : le port sur le POD, +
-  * **Port** : le port sur le Service lié à un IP du Cluster, +
-  * **NodePort** : le port sur le Nœud issu de la plage 30000-32767. +
- +
-{{ :elearning:workbooks:debian:6:avance:kubernetes12.png?direct&800 |}} +
- +
-Si dans le même nœud, plusieurs PODs ont les étiquettes qui correspondent au **selector** du Service, le Service identifie les PODs et s'étend automatiquement pour englober tous les PODs. Les PODs sont appelés des **End-Points** : +
- +
-{{ :elearning:workbooks:debian:6:avance:kubernetes13.png?direct&600 |}} +
- +
-<WRAP center round important> +
-**Important** : Notez que dans ce cas l'équilibrage de charge est automatique est utilise l’algorithme **Random** avec une affinité de session.. +
-</WRAP> +
- +
-De même, quand les PODs sont distribués sur plusieurs nœuds, le Service s'étend pour tout englober : +
- +
-{{ :elearning:workbooks:debian:6:avance:kubernetes14.png?direct&800 |}} +
- +
-Créez donc le fichier YAML **service-definition.yaml** :+
  
 <code> <code>
-root@kubemaster:~# vi service-definition.yaml +root@kubemaster:~# kubectl get pods -n kube-system 
-root@kubemaster:~# cat service-definition.yaml +NAME                                                READY   STATUS    RESTARTS        AGE 
-apiVersion: v1 +calico-kube-controllers-6799f5f4b4-2tgpq            1/1     Running                 42m 
-kind: Service +calico-node-5htrc                                   1/    Running   1 (12d ago)     24d 
-metadata: +calico-node-dc7hd                                   1/    Running   1 (12d ago)     24d 
-  name: myapp-service +calico-node-qk5kt                                   1/    Running   1 (12d ago)     24d 
- +coredns-565d847f94-kkpbp                            1/1     Running                 42m 
-spec: +coredns-565d847f94-tqd8z                            1/1     Running   1 (12d ago)     23d 
-  type: NodePort +etcd-kubemaster.ittraining.loc                      1/1     Running   1 (12d ago)     23d 
-  ports: +kube-apiserver-kubemaster.ittraining.loc            1/1     Running   1 (12d ago)     23d 
-    targetPort: 80 +kube-controller-manager-kubemaster.ittraining.loc   1/    Running   12 (5d3h ago)   23d 
-      port: 80 +kube-proxy-ggmt6                                    1/1     Running   1 (12d ago)     23d 
-      nodePort: 30008 +kube-proxy-x5j2r                                    1/1     Running   1 (12d ago)     23d 
-  selector: +kube-proxy-x7fpc                                    1/1     Running   1 (12d ago)     23d 
-    app: myapp +kube-scheduler-kubemaster.ittraining.loc            1/1     Running   14 (29h ago)    23d 
-    type: front-end+metrics-server-5dbb5ff5bd-vh5fz                     1/    Running   1 (12d ago)     23d
 </code> </code>
- 
-<WRAP center round important> 
-**Important** : Notez que si le champ **type:** est manquant, sa valeur par défaut est **ClusterIP**. Notez aussi que dans **ports**, seul le champ **port** est obligatoire. Si le champ **targetPort** est manquant, sa valeur par défaut est celle du champ **port**. Si le champ **nodePort** est manquant, sa valeur par défaut est le premier port disponible dans la plage entre **30 000** et **32 767**. Dernièrement, il est possible de spécifier de multiples définitions de ports dans le service. 
-</WRAP> 
- 
-Le champs **selector** contient les étiquettes des PODs concernés par la mise en place du Service : 
  
 <code> <code>
-root@kubemaster:~# cat pod-definition.yaml +root@kubemaster:~# kubectl logs kube-apiserver-kubemaster.ittraining.loc -n kube-system | tail 
-apiVersionv1 +Trace[1595276047][564.497826ms] [564.497826ms] END 
-kindPod +I0928 09:22:18.405784       1 trace.go:205] Trace[1267846829]: "Get" url:/apis/coordination.k8s.io/v1/namespaces/kube-system/leases/kube-scheduler,user-agent:kube-scheduler/v1.25.0 (linux/amd64) kubernetes/a866cbe/leader-election,audit-id:1b71bbbb-49ad-4f40-b859-f40b06416452,client:192.168.56.2,accept:application/vnd.kubernetes.protobuf, */*,protocol:HTTP/2.0 (28-Sep-2022 09:22:17.899) (total time: 505ms): 
-metadata: +Trace[1267846829]---"About to write a response" 505ms (09:22:18.405) 
-  namemyapp-pod +Trace[1267846829][505.988424ms] [505.988424ms] END 
-  labels+I0928 10:17:17.854660       1 alloc.go:327] "allocated clusterIPs" service="default/service-netshoot" clusterIPs=map[IPv4:10.107.115.28] 
-    appmyapp +I0928 10:22:18.831876       1 trace.go:205] Trace[338168453]: "List(recursive=true) etcd3" audit-id:8acb508c-5121-4d18-8f8a-ed87d01f33b8,key:/pods/default,resourceVersion:,resourceVersionMatch:,limit:500,continue: (28-Sep-2022 10:22:18.063) (total time: 768ms)
-    typefront-end +Trace[338168453][768.168206ms] [768.168206ms] END 
-spec+I0928 10:22:18.832842       1 trace.go:205] Trace[238339745]: "List" url:/api/v1/namespaces/default/pods,user-agent:kubectl/v1.25.0 (linux/amd64) kubernetes/a866cbe,audit-id:8acb508c-5121-4d18-8f8a-ed87d01f33b8,client:192.168.56.2,accept:application/json;as=Table;v=v1;g=meta.k8s.io,application/json;as=Table;v=v1beta1;g=meta.k8s.io,application/json,protocol:HTTP/2.0 (28-Sep-2022 10:22:18.063) (total time: 769ms): 
-  containers+Trace[238339745]---"Listing from storage done" 768ms (10:22:18.831) 
-    namenginx-container +Trace[238339745]: [769.149103ms] [769.149103ms] END
-      imagenginx+
 </code> </code>
  
-Créez le Service en utilisant le fichier **service-definition.yaml** :+=====LAB #2 Les Nœuds=====
  
-<code> +====2.Le Statut NotReady====
-root@kubemaster:~# kubectl create -f service-definition.yaml +
-service/myapp-service created +
-</code>+
  
-Constatez la création du Service :+Quand un nœud du cluster démontre un problème, il convient de regarder la section **Conditions** dans la sortie de la commande **kubectl describe node** du nœud concerné :
  
 <code> <code>
-root@kubemaster:~# kubectl get services +root@kubemaster:~# kubectl describe node kubenode1.ittraining.loc 
-NAME            TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE +... 
-kubernetes      ClusterIP   10.96.0.1      <none>        443/TCP        26h +Conditions: 
-myapp-service   NodePort    10.97.228.14   <none>        80:30008/TCP   13s+  Type                 Status  LastHeartbeatTime                 LastTransitionTime                Reason                       Message 
 +  ----                 ------  -----------------                 ------------------                ------                       ------- 
 +  NetworkUnavailable   False   Fri, 16 Sep 2022 09:35:05 +0200   Fri, 16 Sep 2022 09:35:05 +0200   CalicoIsUp                   Calico is running on this node 
 +  MemoryPressure       False   Wed, 28 Sep 2022 09:17:21 +0200   Sun, 04 Sep 2022 13:13:02 +0200   KubeletHasSufficientMemory   kubelet has sufficient memory available 
 +  DiskPressure         False   Wed, 28 Sep 2022 09:17:21 +0200   Sun, 04 Sep 2022 13:13:02 +0200   KubeletHasNoDiskPressure     kubelet has no disk pressure 
 +  PIDPressure          False   Wed, 28 Sep 2022 09:17:21 +0200   Sun, 04 Sep 2022 13:13:02 +0200   KubeletHasSufficientPID      kubelet has sufficient PID available 
 +  Ready                True    Wed, 28 Sep 2022 09:17:21 +0200   Thu, 15 Sep 2022 17:57:04 +0200   KubeletReady                 kubelet is posting ready status 
 +...
 </code> </code>
  
-<WRAP center round important> +En règle générale, le statut de NotReady est créé par la panne du service **kubelet** sur le nœud, comme démontre l'exemple suivant :
-**Important** : Notez que le Service a une adresse IP du cluster et qu'il a exposé le port **30 008**+
-</WRAP> +
- +
-Testez maintenant si vous pouvez afficher la page d'accueil de Nginx en vous connectant à un des PODs à partir de votre Gateway en utilisant le port exposé :+
  
 <code> <code>
-root@kubemaster:~# exit +root@kubemaster:~# ssh -l trainee 192.168.56.3 
-déconnexion+trainee@192.168.56.3's password: trainee 
 +Linux kubenode1.ittraining.loc 4.9.0-19-amd64 #1 SMP Debian 4.9.320-2 (2022-06-30) x86_64
  
-trainee@kubemaster:~$ exit +The programs included with the Debian GNU/Linux system are free software; 
-déconnexion +the exact distribution terms for each program are described in the 
-Connection to 192.168.56.2 closed.+individual files in /usr/share/doc/*/copyright.
  
-trainee@gateway:~$ curl 192.168.56.3:30008 +Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent 
-<!DOCTYPE html> +permitted by applicable law. 
-<html> +Last login: Fri Sep 16 18:07:39 2022 from 192.168.56.2 
-<head> +trainee@kubenode1:~$ su - 
-<title>Welcome to nginx!</title> +Mot de passe fenestros
-<style> +
-    body { +
-        width35em; +
-        margin0 auto; +
-        font-family: Tahoma, Verdana, Arial, sans-serif; +
-    } +
-</style> +
-</head> +
-<body> +
-<h1>Welcome to nginx!</h1> +
-<p>If you see this page, the nginx web server is successfully installed and +
-working. Further configuration is required.</p>+
  
-<p>For online documentation and support please refer to +root@kubenode1:~# systemctl stop kubelet
-<a href="http://nginx.org/">nginx.org</a>.<br/> +
-Commercial support is available at +
-<a href="http://nginx.com/">nginx.com</a>.</p>+
  
-<p><em>Thank you for using nginx.</em></p> +root@kubenode1:~# systemctl disable kubelet 
-</body> +Removed /etc/systemd/system/multi-user.target.wants/kubelet.service.
-</html>+
  
-trainee@gateway:~$ curl 192.168.56.4:30008 +root@kubenode1:~# exit 
-<!DOCTYPE html> +déconnexion 
-<html> +trainee@kubenode1:~$ exit 
-<head> +déconnexion 
-<title>Welcome to nginx!</title> +Connection to 192.168.56.3 closed.
-<style> +
-    body { +
-        width: 35em; +
-        margin: 0 auto; +
-        font-family: Tahoma, Verdana, Arial, sans-serif; +
-    } +
-</style> +
-</head> +
-<body> +
-<h1>Welcome to nginx!</h1> +
-<p>If you see this page, the nginx web server is successfully installed and +
-working. Further configuration is required.</p>+
  
-<p>For online documentation and support please refer to +root@kubemaster:~# kubectl get nodes 
-<a href="http://nginx.org/">nginx.org</a>.<br/> +NAME                        STATUS     ROLES           AGE   VERSION 
-Commercial support is available at +kubemaster.ittraining.loc   Ready      control-plane   24d   v1.25.0 
-<a href="http://nginx.com/">nginx.com</a>.</p> +kubenode1.ittraining.loc    NotReady   <none         24d   v1.25.0 
- +kubenode2.ittraining.loc    Ready      <none         24d   v1.25.0
-<p><em>Thank you for using nginx.</em></p> +
-</body> +
-</html>+
 </code> </code>
  
-====1.3 - Le Service ClusterIP==== +En activant et en démarrant le service, le nœud retrouve son statut de **Ready** :
- +
-Le Service **ClusterIP** permet de regrouper les PODs offrant le même service afin de faciliter la communicationpar exemple : +
- +
-  * 3 PODs front-end = une adresse ClusterIP, +
-  * 3 PODs back-end = une autre adresse ClusterIP. +
- +
-Pour créer un Service ClusterIP, créez le fichier **clusterip-definition.yaml** :+
  
 <code> <code>
-trainee@gateway:~ssh -l trainee 192.168.56.2 +root@kubemaster:~ssh -l trainee 192.168.56.3 
-trainee@192.168.56.2's password: trainee +trainee@192.168.56.3's password: trainee 
-Linux kubemaster.ittraining.loc 4.9.0-19-amd64 #1 SMP Debian 4.9.320-2 (2022-06-30) x86_64+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 programs included with the Debian GNU/Linux system are free software;
Ligne 332: Ligne 255:
 Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
 permitted by applicable law. permitted by applicable law.
-Last login: Wed Jul 13 15:53:15 2022 from 10.0.2.40 +Last login: Wed Sep 28 09:20:14 2022 from 192.168.56.2 
-trainee@kubemaster:~$ su -+trainee@kubenode1:~$ su -
 Mot de passe : fenestros Mot de passe : fenestros
-root@kubemaster:~# vi clusterip-definition.yaml 
-root@kubemaster:~# cat clusterip-definition.yaml 
---- 
-apiVersion: v1 
-kind: Service 
-metadata: 
-  name: back-end 
  
-spec+root@kubenode1:~# systemctl enable kubelet 
-  type: ClusterIP +Created symlink /etc/systemd/system/multi-user.target.wants/kubelet.service → /lib/systemd/system/kubelet.service.
-  ports: +
-    targetPort: 80 +
-      port: 80 +
-  selector: +
-    app: myapp +
-    type: front-end +
-</code>+
  
-Créez le Service en utilisant le fichier **clusterip-definition.yaml** :+root@kubenode1:~# systemctl start kubelet
  
-<code> +root@kubenode1:~# systemctl status kubelet 
-root@kubemaster:~# kubectl create -f clusterip-definition.yaml +● kubelet.service kubelet: The Kubernetes Node Agent 
-service/back-end created +   Loaded: loaded (/lib/systemd/system/kubelet.service; enabled; vendor preset: enable 
-</code>+  Drop-In: /etc/systemd/system/kubelet.service.d 
 +           └─10-kubeadm.conf 
 +   Active: active (running) since Wed 2022-09-28 09:54:49 CEST; 7s ago 
 +     Docs: https://kubernetes.io/docs/home/ 
 + Main PID: 5996 (kubelet) 
 +    Tasks: 18 (limit: 4915) 
 +   Memory: 32.1M 
 +      CPU: 555ms 
 +   CGroup: /system.slice/kubelet.service 
 +           └─5996 /usr/bin/kubelet --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-ku
  
-Vérifiez maintenant la présence du Service :+sept. 28 09:54:51 kubenode1.ittraining.loc kubelet[5996]: I0928 09:54:51.572692    599 
 +sept. 28 09:54:52 kubenode1.ittraining.loc kubelet[5996]: I0928 09:54:52.181515    599 
 +sept. 28 09:54:52 kubenode1.ittraining.loc kubelet[5996]: I0928 09:54:52.239266    599 
 +sept. 28 09:54:52 kubenode1.ittraining.loc kubelet[5996]: I0928 09:54:52.289189    599 
 +sept. 28 09:54:52 kubenode1.ittraining.loc kubelet[5996]: E0928 09:54:52.289617    599 
 +sept. 28 09:54:52 kubenode1.ittraining.loc kubelet[5996]: I0928 09:54:52.289652    599 
 +sept. 28 09:54:54 kubenode1.ittraining.loc kubelet[5996]: I0928 09:54:54.139010    599 
 +sept. 28 09:54:56 kubenode1.ittraining.loc kubelet[5996]: I0928 09:54:56.138812    599 
 +sept. 28 09:54:56 kubenode1.ittraining.loc kubelet[5996]: I0928 09:54:56.241520    599 
 +sept. 28 09:54:57 kubenode1.ittraining.loc kubelet[5996]: I0928 09:54:57.243967    599 
 +root@kubenode1:~#
  
-<code> +root@kubenode1:~# exit 
-root@kubemaster:~# kubectl get services +déconnexion 
-NAME            TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE +trainee@kubenode1:~$ exit 
-back-end        ClusterIP   10.111.91.134   <none>        80/TCP         3m35s +déconnexion 
-kubernetes      ClusterIP   10.96.0.1       <none>        443/TCP        28h +Connection to 192.168.56.3 closed. 
-myapp-service   NodePort    10.97.228.14    <none>        80:30008/TCP   98m+ 
 +root@kubemaster:~# kubectl get nodes 
 +NAME                        STATUS   ROLES           AGE   VERSION 
 +kubemaster.ittraining.loc   Ready    control-plane   24d   v1.25.0 
 +kubenode1.ittraining.loc    Ready    <none>          24d   v1.25.
 +kubenode2.ittraining.loc    Ready    <none>          24d   v1.25.0
 </code> </code>
  
-Supprimez maintenant les Services créés :+=====LAB #3 - Les Pods=====
  
-<code> +Quand un pod du cluster démontre un problème, il convient de regarder la section **Events** dans la sortie de la commande **kubectl describe pod** du pod concerné.
-root@kubemaster:~# kubectl delete service myapp-service +
-service "myapp-service" deleted+
  
-root@kubemaster:~# kubectl delete service back-end +====3.1 L'Erreur ImagePullBackOff====
-service "back-end" deleted +
-</code>+
  
-Dernièrement supprimez le Deployment **myapp-deployment** :+Commencez par créer le fichier **deployment-postgresql.yaml** :
  
 <code> <code>
-root@kubemaster:~# kubectl delete deployment myapp-deployment +root@kubemaster:~# vi deployment-postgresql.yaml 
-deployment.extensions "myapp-deployment" deleted+root@kubemaster:~# cat deployment-postgresql.yaml 
 +apiVersion: apps/v1 
 +kind: Deployment 
 +metadata: 
 +  name: postgresql 
 +  labels: 
 +    app: postgresql 
 +spec: 
 +  replicas: 1 
 +  selector: 
 +    matchLabels: 
 +      app: postgresql 
 +  template: 
 +    metadata: 
 +      labels: 
 +        app: postgresql 
 +    spec: 
 +      containers: 
 +      image: bitnami/postgresql:10.12.10 
 +        imagePullPolicy: IfNotPresent 
 +        name: postgresql
 </code> </code>
  
-Vérifiez qu'il ne reste que le service par défaut **kubernetes** :+Déployez ensuite l'application :
  
 <code> <code>
-root@kubemaster:~# kubectl get all +root@kubemaster:~# kubectl apply -f deployment-postgresql.yaml 
-NAME                 TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE +deployment.apps/postgresql created
-service/kubernetes   ClusterIP   10.96.0.1    <none>        443/TCP   28h+
 </code> </code>
  
-=====LAB #2 - Gestion d'une Architecture de Microservices===== +En consultant le pod créévous verrez qu'il y a une erreur de type **ImagePullBackOff** :
- +
-====2.1 - Présentation==== +
- +
-Vous allez mettre en place une application simple, appelé **demo-voting-app** et développé par Docker, sous forme de microservices : +
- +
-{{ :elearning:workbooks:debian:6:avance:app.png?direct&400 |}} +
- +
-Dans cette application le conteneur **voting-app** permet de voter pour des **chats** ou des **chiens**. Cette application tourne sous Python et fournit une interace HTML : +
- +
-{{ :elearning:workbooks:debian:6:avance:kubernetes15.png?direct&800 |}} +
- +
-Lors de la votele résultat de celle-ci est stocké dans **Redis** dans une base de données en mémoire. Le résultat est ensuite passé au conteneur **Worker** qui tourne sous .NET et qui met à jour la base de données persistante dans le conteneur **db** qui tourne sous PostgreSQL. +
- +
-L'application **result-app** qui tourne sous NodeJS lit ensuite la table dans la base de données PostgreSQL et affiche le résultat sous forme HTML : +
- +
-{{ :elearning:workbooks:debian:6:avance:kubernetes16.png?direct&800 |}} +
- +
-Cette application peut être mise en place sous docker avec les commandes suivantes :+
  
 <code> <code>
-docker run -d --name=redis redis +root@kubemaster:~# kubectl get pods 
-docker run -d --name=db -e POSTGRES_PASSWORD=postgres -e POSTGRES_USER=postgres postgres:9.4  +NAME                          READY   STATUS             RESTARTS   AGE 
-docker run ---name=vote -p 5000:80 --link redis:redis dockersamples/examplevotingapp_vote +postgresql-6778f6569c-x84xd   0/1     ImagePullBackOff            25s 
-docker run -d --name=result -p 5001:80 --link db:db dockersamples/examplevotingapp_result +sharedvolume                  2/2     Running            0          8d 
-docker run -d --name=worker --link db:db --link redis:redis dockersamples/examplevotingapp_worker+volumepod                     0/1     Completed          0          8d
 </code> </code>
  
-Par contre, Docker annonce le retrait éventuel de l'option **--lien** et indique qu'il vaudrait mieux utiliser des réseaux pour assurer la communication entre les conteneurs : +Consultez la section **Events** de la sortie de la commande **describe** pour voir ce que se passe :
- +
-"Warning: The --link flag is a legacy feature of Docker. It may eventually be removed. Unless you absolutely need to continue using it, we recommend that you use user-defined networks to facilitate communication between two containers instead of using --link. One feature that user-defined networks do not support that you can do with --link is sharing environment variables between containers. However, you can use other mechanisms such as volumes to share environment variables between containers in a more controlled way." +
- +
-Cette application peut être mise en place sous docker swarm avec les commandes suivantes :+
  
 <code> <code>
-docker@manager1:~$ docker node ls +root@kubemaster:~# kubectl describe pod postgresql-6778f6569c-x84xd | tail 
-ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS      ENGINE VERSION +                             node.kubernetes.io/unreachable:NoExecute op=Exists for 300s 
-vwshwppuaoze785gy12k0gh62 *   manager1            Ready               Active              Leader              18.09.3 +Events: 
-t0rjtq76j35mbn44olp0t3yeq     worker1             Ready               Active                                  18.09.3 +  Type     Reason     Age                From               Message 
-udv7w988tepuba7pf6rb5k1o3     worker2             Ready               Active                                  18.09.3 +  ----     ------     ----               ----               ------- 
-uz2m26qe0hdf7lplb9a5m0ysv     worker3             Ready               Active                                  18.09.3 +  Normal   Scheduled  74s                default-scheduler  Successfully assigned default/postgresql-6778f6569c-x84xd to kubenode1.ittraining.loc 
-sfig9atrbgzt41sjxhj95wfgu     worker4             Ready               Active                                  18.09.3 +  Normal   Pulling    28s (x3 over 74s)  kubelet            Pulling image "bitnami/postgresql:10.12.10" 
-56az1cupssf9uqx9h0yvbmydw     worker5             Ready               Active                                  18.09.3+  Warning  Failed     27s (x3 over 72s)  kubelet            Failed to pull image "bitnami/postgresql:10.12.10": rpc error: code = NotFound desc = failed to pull and unpack image "docker.io/bitnami/postgresql:10.12.10": failed to resolve reference "docker.io/bitnami/postgresql:10.12.10": docker.io/bitnami/postgresql:10.12.10: not found 
 +  Warning  Failed     27s (x3 over 72s)  kubelet            Error: ErrImagePull 
 +  Normal   BackOff    12s (x3 over 72s)  kubelet            Back-off pulling image "bitnami/postgresql:10.12.10" 
 +  Warning  Failed     12s (x3 over 72s)  kubelet            Error: ImagePullBackOff
 </code> </code>
  
-<code> +Comme vous pouvez constater, il existe trois avertissements
-docker@manager1:~$ vi docker-stack.yml +
-docker@manager1:~$ cat docker-stack.yml +
-version: "3" +
-services:+
  
-  redis: +<file> 
-    image: redis:alpine +  Warning  Failed     27s (x3 over 72s)  kubelet            Failed to pull image "bitnami/postgresql:10.12.10": rpc errorcode = NotFound desc = failed to pull and unpack image "docker.io/bitnami/postgresql:10.12.10"failed to resolve reference "docker.io/bitnami/postgresql:10.12.10"docker.io/bitnami/postgresql:10.12.10not found
-    ports: +
-      - "6379" +
-    networks: +
-      - frontend +
-    deploy: +
-      replicas: 1 +
-      update_config: +
-        parallelism:+
-        delay: 10s +
-      restart_policy: +
-        condition: on-failure +
-  db: +
-    image: postgres:9.+
-    volumes: +
-      - db-data:/var/lib/postgresql/data +
-    networks: +
-      - backend +
-    deploy: +
-      placement: +
-        constraints: [node.role == manager] +
-  vote: +
-    image: dockersamples/examplevotingapp_vote:before +
-    ports: +
-      - 5000:80 +
-    networks: +
-      - frontend +
-    depends_on: +
-      - redis +
-    deploy: +
-      replicas: 2 +
-      update_config: +
-        parallelism:+
-      restart_policy: +
-        condition: on-failure +
-  result: +
-    image: dockersamples/examplevotingapp_result:before +
-    ports: +
-      - 5001:80 +
-    networks: +
-      - backend +
-    depends_on: +
-      - db +
-    deploy: +
-      replicas: 1 +
-      update_config: +
-        parallelism:+
-        delay: 10s +
-      restart_policy: +
-        conditionon-failure+
  
-  worker: +  Warning  Failed     27s (x3 over 72s)  kubelet            ErrorErrImagePull
-    image: dockersamples/examplevotingapp_worker +
-    networks: +
-      - frontend +
-      - backend +
-    deploy: +
-      mode: replicated +
-      replicas: 1 +
-      labels: [APP=VOTING] +
-      restart_policy: +
-        condition: on-failure +
-        delay: 10s +
-        max_attempts:+
-        window: 120s +
-      placement: +
-        constraints: [node.role == manager]+
  
-  visualizer+  Warning  Failed     12s (x3 over 72s)  kubelet            ErrorImagePullBackOff 
-    image: dockersamples/visualizer:stable +</file>
-    ports: +
-      - "8080:8080" +
-    stop_grace_period: 1m30s +
-    volumes: +
-      - "/var/run/docker.sock:/var/run/docker.sock" +
-    deploy: +
-      placement: +
-        constraints: [node.role == manager]+
  
-networks: +Le premier des trois avertissements nous dit clairement qu'il y a un problème au niveau du tag de l'image spécifié dans le fichier **deployment-postgresql.yaml** **docker.io/bitnami/postgresql:10.12.10not found**.
-  frontend: +
-  backend:+
  
-volumes: +Modifiez donc le tag dans ce fichier à ** 10.13.0** :
-  db-data: +
-</code>+
  
 <code> <code>
-docker@manager1:~$ docker stack deploy -c docker-stack.yml app +root@kubemaster:~# vi deployment-postgresql.yaml 
-Creating network app_backend +root@kubemaster:~# cat deployment-postgresql.yaml
-Creating network app_frontend +
-Creating network app_default +
-Creating service app_worker +
-Creating service app_visualizer +
-Creating service app_redis +
-Creating service app_db +
-Creating service app_vote +
-Creating service app_result +
-</code> +
- +
-====2.2 - Création des Deployments==== +
- +
-Créez le répertoire **myapp**. Placez-vous dans ce répertoire et créez le fichier **voting-app-deployment.yaml** : +
- +
-<code> +
-root@kubemaster:~# mkdir myapp +
-root@kubemaster:~# cd myapp +
-root@kubemaster:~/app# vi voting-app-deployment.yaml +
-root@kubemaster:~/app# cat voting-app-deployment.yaml +
----+
 apiVersion: apps/v1 apiVersion: apps/v1
 kind: Deployment kind: Deployment
 metadata: metadata:
-  name: voting-app-deployment+  name: postgresql
   labels:   labels:
-    app: demo-voting-app+    app: postgresql
 spec: spec:
   replicas: 1   replicas: 1
   selector:   selector:
     matchLabels:     matchLabels:
-      name: voting-app-pod +      app: postgresql
-      app: demo-voting-app+
   template:   template:
     metadata:     metadata:
-      name: voting-app-pod 
       labels:       labels:
-        name: voting-app-pod +        app: postgresql
-        app: demo-voting-app +
     spec:     spec:
       containers:       containers:
-      - name: voting-app +      - image: bitnami/postgresql:10.13.0 
-        image: dockersamples/examplevotingapp_vote +        imagePullPolicyIfNotPresent 
-        ports+        namepostgresql
-        - containerPort80+
 </code> </code>
  
-<WRAP center round important> +Appliquez maintenant le fichier :
-**Important** : Ce fichier décrit un Deployment. Notez que le Deployment crée **un** replica du POD spécifié par **template** contenant un conteneur dénommé **voting-app** qui utilise le port 80 et qui est créé à partir de l'image **dockersamples/examplevotingapp_vote**. +
-</WRAP> +
- +
-Créez maintenant le fichier **redis-deployment.yaml** :+
  
 <code> <code>
-root@kubemaster:~/appvi redis-deployment.yaml +root@kubemaster:~# kubectl apply -deployment-postgresql.yaml 
-root@kubemaster:~/app# cat redis-deployment.yaml +deployment.apps/postgresql configured
---- +
-apiVersion: apps/v1 +
-kind: Deployment +
-metadata: +
-  name: redis-deployment +
-  labels: +
-    app: demo-voting-app +
-spec: +
-  replicas: 1 +
-  selector: +
-    matchLabels: +
-      name: redis-pod +
-      app: demo-voting-app +
-  template: +
-    metadata: +
-      name: redis pod +
-      labels: +
-        name: redis-pod +
-        app: demo-voting-app +
- +
-    spec: +
-      containers: +
-      - name: redis +
-        image: redis +
-        ports: +
-        - containerPort: 6379+
 </code> </code>
  
-<WRAP center round important> +====3.2 - L'Erreur CrashLoopBackOff====
-**Important** : Ce fichier décrit un DeploymentNotez que le Deployment crée **un** replica du POD spécifié par **template** contenant un conteneur dénommé **redis** qui utilise le port 6379 et qui est créé à partir de l'image **redis**. +
-</WRAP>+
  
-Créez le fichier **worker-deployment.yaml** :+En consultant le deuxième Pod créé, vous verrez qu'il y a une erreur de type **CrashLoopBackOff** :
  
 <code> <code>
-root@kubemaster:~/appvi worker-deployment.yaml +root@kubemaster:~# kubectl get pods 
-root@kubemaster:~/app# cat worker-deployment.yaml +NAME                          READY   STATUS             RESTARTS     AGE 
---+postgresql-6668d5d6b5-swr9g   0/1     CrashLoopBackOff   1 (3s ago)   46s 
-apiVersion: apps/v1 +postgresql-6778f6569c-x84xd   0/    ImagePullBackOff              5m55s 
-kind: Deployment +sharedvolume                  2/2     Running            0            8d 
-metadata: +volumepod                     0/    Completed          0            8d 
-  name: worker-app-deployment +</code>
-  labels: +
-    app: demo-voting-app +
-spec: +
-  replicas: +
-  selector: +
-    matchLabels: +
-      name: worker-app-pod +
-      app: demo-voting-app +
-  template: +
-    metadata: +
-      name: worker-app-pod +
-      labels: +
-        name: worker-app-pod +
-        app: demo-voting-app+
  
-    spec+Consultez la section **Events** de la sortie de la commande **describe** pour voir ce que se passe avec le deuxième pod 
-      containers: + 
-      nameworker-app +<code> 
-        image: dockersamples/examplevotingapp_worker+root@kubemaster:~# kubectl describe pod postgresql-6668d5d6b5-swr9g | tail 
 +Events: 
 +  Type     Reason     Age                  From               Message 
 +  ----     ------     ----                 ----               ------
 +  Normal   Scheduled  4m3s                 default-scheduler  Successfully assigned default/postgresql-6668d5d6b5-swr9g to kubenode1.ittraining.loc 
 +  Normal   Pulling    4m2s                 kubelet            Pulling image "bitnami/postgresql:10.13.0" 
 +  Normal   Pulled     3m22s                kubelet            Successfully pulled image "bitnami/postgresql:10.13.0" in 40.581665048s 
 +  Normal   Created    90s (x5 over 3m21s)  kubelet            Created container postgresql 
 +  Normal   Started    90s (x5 over 3m21s)  kubelet            Started container postgresql 
 +  Normal   Pulled     90s (x4 over 3m20s)  kubelet            Container image "bitnami/postgresql:10.13.0" already present on machine 
 +  Warning  BackOff    68s (x9 over 3m19s)  kubelet            Back-off restarting failed container
 </code> </code>
  
-<WRAP center round important> +Cette fois-ci, la section **Events** nous donne aucune indication concernant le problème !
-**Important** : Ce fichier décrit un Deployment. Notez que le Deployment crée **un** replica du POD spécifié par **template** contenant un conteneur dénommé **worker-app** qui est créé à partir de l'image **dockersamples/examplevotingapp_worker**. +
-</WRAP>+
  
-Créez ensuite le fichier **postgres-deployment.yaml** :+Pour obtenir plus d'information concernant le problème, on peut utiliser la commande **logs** :
  
 <code> <code>
-root@kubemaster:~/appvi postgres-deployment.yaml +root@kubemaster:~# kubectl logs postgresql-6668d5d6b5-swr9g | tail 
-root@kubemaster:~/app# cat postgres-deployment.yaml +postgresql 08:43:48.60  
---- +postgresql 08:43:48.60 Welcome to the Bitnami postgresql container 
-apiVersionapps/v1 +postgresql 08:43:48.60 Subscribe to project updates by watching https://github.com/bitnami/bitnami-docker-postgresql 
-kindDeployment +postgresql 08:43:48.60 Submit issues and feature requests at https://github.com/bitnami/bitnami-docker-postgresql/issues 
-metadata: +postgresql 08:43:48.60  
-  namepostgres-deployment +postgresql 08:43:48.62 INFO  ==> ** Starting PostgreSQL setup ** 
-  labels: +postgresql 08:43:48.63 INFO  ==> Validating settings in POSTGRESQL_* env vars.. 
-    app: demo-voting-app +postgresql 08:43:48.63 ERROR ==> The POSTGRESQL_PASSWORD environment variable is empty or not set. Set the environment variable ALLOW_EMPTY_PASSWORD=yes to allow the container to be started with blank passwords. This is recommended only for development. 
-spec: +postgresql 08:43:48.63 ERROR ==> The POSTGRESQL_PASSWORD environment variable is empty or not set. Set the environment variable ALLOW_EMPTY_PASSWORD=yes to allow the container to be started with blank passwords. This is recommended only for development.
-  replicas+
-  selector: +
-    matchLabels: +
-      name: postgres-pod +
-      app: demo-voting-app +
-  template: +
-    metadata+
-      namepostgres pod +
-      labels+
-        namepostgres-pod +
-        appdemo-voting-app +
- +
-    spec: +
-      containers: +
-      - name: postgres +
-        image: postgres:9.+
-        env: +
-        - namePOSTGRES_USER +
-          valuepostgres +
-        - namePOSTGRES_PASSWORD +
-          valuepostgres +
-        ports: +
-        - containerPort: 5432+
 </code> </code>
  
-<WRAP center round important> +La sortie de la commande **logs** nous indique clairement que le problème est lié au contenu de la variable **POSTGRESQL_PASSWORD** qui est vide. Elle nous indique aussi que nous pourrions fixer la valeur de la variable **ALLOW_EMPTY_PASSWORD** à **yes** pour contourner ce problème : 
-**Important** : Ce fichier décrit un Deployment. Notez que le Deployment crée **un** replica du POD spécifié par **template** contenant un conteneur dénommé **postgres** qui utilise le port 5432 et qui est créé à partir de l'image **postgres:9.4**+ 
-</WRAP>+<file> 
 +... 
 +postgresql 08:43:48.63 ERROR ==> The POSTGRESQL_PASSWORD environment variable is empty or not set. Set the environment variable ALLOW_EMPTY_PASSWORD=yes to allow the container to be started with blank passwords. This is recommended only for development
 +</file>
  
-Dernièrement, créez le fichier **result-app-deployment.yaml** :+Mettez à jour donc le fichier **deployment-postgresql.yaml** :
  
 <code> <code>
-root@kubemaster:~/app# vi result-app-deployment.yaml +root@kubemaster:~# vi deployment-postgresql.yaml 
-root@kubemaster:~/app# cat result-app-deployment.yaml +root@kubemaster:~# cat deployment-postgresql.yaml
----+
 apiVersion: apps/v1 apiVersion: apps/v1
 kind: Deployment kind: Deployment
 metadata: metadata:
-  name: result-app-deployment+  name: postgresql
   labels:   labels:
-    app: demo-voting-app+    app: postgresql
 spec: spec:
   replicas: 1   replicas: 1
   selector:   selector:
     matchLabels:     matchLabels:
-      name: result-app-pod +      app: postgresql
-      app: demo-voting-app+
   template:   template:
     metadata:     metadata:
-      name: result-app-pod 
       labels:       labels:
-        name: result-app-pod +        app: postgresql
-        app: demo-voting-app +
     spec:     spec:
       containers:       containers:
-      - nameresult-app +      - imagebitnami/postgresql:10.13.0 
-        imagedockersamples/examplevotingapp_result +        imagePullPolicyIfNotPresent 
-        ports+        name: postgresql 
-        - containerPort80+        env
 +        - namePOSTGRESQL_PASSWORD 
 +          value: "VerySecurePassword:-)"
 </code> </code>
  
-<WRAP center round important> +Appliquez la configuration :
-**Important** Ce fichier décrit un Deployment. Notez que le Deployment crée **un** replica du POD spécifié par **template** contenant un conteneur dénommé **result-app** qui utilise le port 80 et qui est créé à partir de l'image **dockersamples/examplevotingapp_result**. +
-</WRAP>+
  
-====2.3 Création des Services====+<code> 
 +root@kubemaster:~# kubectl apply -f deployment-postgresql.yaml 
 +deployment.apps/postgresql configured 
 +</code>
  
-Créez maintenant le fichier **redis-service.yaml** :+Constatez l'état du Pod ainsi que le deployment :
  
 <code> <code>
-root@kubemaster:~/appvi redis-service.yaml +root@kubemaster:~# kubectl get pods 
-root@kubemaster:~/app# cat redis-service.yaml +NAME                          READY   STATUS      RESTARTS   AGE 
---- +postgresql-6f885d8957-tnlbb   1/    Running              29s 
-apiVersion: v1 +sharedvolume                  2/2     Running              8d 
-kind: Service +volumepod                     0/    Completed            8d
-metadata: +
-  name: redis +
-  labels: +
-    name: redis-service +
-    app: demo-voting-app+
  
-spec+root@kubemaster:~# kubectl get deployments 
-  ports: +NAME         READY   UP-TO-DATE   AVAILABLE   AGE 
-  port: 6379 +postgresql   1/               1           14m
-    targetPort: 6379 +
-  selector: +
-    name: redis-pod +
-    app: demo-voting-app+
 </code> </code>
  
-<WRAP center round important> +Utilisez maintenant l'option **-f** de la commande logs pour voir les traces en continu :
-**Important** : Ce fichier décrit un Service **ClusterIP**. Notez que le Service expose le port **6379** sur tout POD ayant le nom **redis-pod**. +
-</WRAP> +
- +
-Créez ensuite le fichier **postgres-service.yaml** :+
  
 <code> <code>
-root@kubemaster:~/appvi postgres-service.yaml +root@kubemaster:~# kubectl logs postgresql-6f885d8957-tnlbb -f 
-root@kubemaster:~/app# cat postgres-service.yaml +postgresql 08:48:35.14  
---- +postgresql 08:48:35.14 Welcome to the Bitnami postgresql container 
-apiVersionv1 +postgresql 08:48:35.14 Subscribe to project updates by watching https://github.com/bitnami/bitnami-docker-postgresql 
-kindService +postgresql 08:48:35.14 Submit issues and feature requests at https://github.com/bitnami/bitnami-docker-postgresql/issues 
-metadata+postgresql 08:48:35.15  
-  namedb +postgresql 08:48:35.16 INFO  ==> ** Starting PostgreSQL setup ** 
-  labels+postgresql 08:48:35.17 INFO  ==> Validating settings in POSTGRESQL_* env vars.. 
-    namedb-service +postgresql 08:48:35.18 INFO  ==> Loading custom pre-init scripts... 
-    appdemo-voting-app+postgresql 08:48:35.18 INFO  ==> Initializing PostgreSQL database... 
 +postgresql 08:48:35.20 INFO  ==> pg_hba.conf file not detected. Generating it... 
 +postgresql 08:48:35.20 INFO  ==> Generating local authentication configuration 
 +postgresql 08:48:47.94 INFO  ==> Starting PostgreSQL in background... 
 +postgresql 08:48:48.36 INFO  ==> Changing password of postgres 
 +postgresql 08:48:48.39 INFO  ==> Configuring replication parameters 
 +postgresql 08:48:48.46 INFO  ==> Configuring fsync 
 +postgresql 08:48:48.47 INFO  ==> Loading custom scripts... 
 +postgresql 08:48:48.47 INFO  ==> Enabling remote connections 
 +postgresql 08:48:48.48 INFO  ==> Stopping PostgreSQL... 
 +postgresql 08:48:49.49 INFO  ==> ** PostgreSQL setup finished! **
  
-spec: +postgresql 08:48:49.50 INFO  ==> ** Starting PostgreSQL ** 
-  ports: +2022-09-28 08:48:49.633 GMT [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432 
-  port: 5432 +2022-09-28 08:48:49.633 GMT [1] LOG:  listening on IPv6 address "::", port 5432 
-    targetPort: 5432 +2022-09-28 08:48:49.699 GMT [1] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432" 
-  selector+2022-09-28 08:48:49.817 GMT [106] LOG:  database system was shut down at 2022-09-28 08:48:48 GMT 
-    namepostgres-pod +2022-09-28 08:48:49.852 GMT [1] LOG:  database system is ready to accept connections 
-    appdemo-voting-app+^C
 </code> </code>
  
-<WRAP center round important> +<WRAP center round important 60%
-**Important** : Ce fichier décrit un Service **ClusterIP**. Notez que le Service expose le port **5432** sur tout POD ayant le nom **postgres-pod**.+**Important** : Notez l'utilisation de **^C** pour arrêter la commande **kubectl logs postgresql-6f885d8957-tnlbb -f**. 
 </WRAP> </WRAP>
  
-Créez le fichier **voting-app-service.yaml** :+=====LAB #4 - Les Conteneurs===== 
 + 
 +====4.1 - La Commande exec==== 
 + 
 +La commande **exec** peut être utilisée pour exécuter une commande à l'intérieur d'un conteneur dans un pod. Imaginons que vous souhaitez vérifier le contenu du fichier de configuration de PostgreSQL, **postgresql.conf** :
  
 <code> <code>
-root@kubemaster:~/appvi voting-app-service.yaml +root@kubemaster:~# kubectl exec postgresql-6f885d8957-tnlbb -- cat /opt/bitnami/postgresql/conf/postgresql.conf | more 
-root@kubemaster:~/appcat voting-app-service.yaml +# ----------------------------- 
---- +# PostgreSQL configuration file 
-apiVersion: v1 +# ----------------------------- 
-kindService +# 
-metadata: +# This file consists of lines of the form
-  name: voting-service +# 
-  labels: +#   name = value 
-    name: voting-service +
-    app: demo-voting-app+# (The "=" is optional.)  Whitespace may be used.  Comments are introduced with 
 +# "#" anywhere on a line.  The complete list of parameter names and allowed 
 +# values can be found in the PostgreSQL documentation. 
 +
 +# The commented-out settings shown in this file represent the default values. 
 +# Re-commenting a setting is NOT sufficient to revert it to the default value; 
 +# you need to reload the server. 
 +
 +# This file is read on server startup and when the server receives a SIGHUP 
 +# signal.  If you edit the file on a running system, you have to SIGHUP the 
 +# server for the changes to take effect, run "pg_ctl reload", or execute 
 +# "SELECT pg_reload_conf()" Some parameters, which are marked below, 
 +# require a server shutdown and restart to take effect. 
 +
 +# Any parameter can also be given as a command-line option to the server, e.g., 
 +# "postgres -c log_connections=on" Some parameters can be changed at run time 
 +# with the "SET" SQL command. 
 +
 +# Memory units:  kB = kilobytes        Time units:  ms  = milliseconds 
 +#                MB = megabytes                       = seconds 
 +#                GB = gigabytes                     min = minutes 
 +#                TB = terabytes                       = hours 
 +#                                                     = days
  
-spec: 
-  type: NodePort 
-  ports: 
-  - port: 80 
-    targetPort: 80 
-  selector: 
-    name: voting-app-pod 
-    app: demo-voting-app 
-</code> 
  
-<WRAP center round important> +#------------------------------------------------------------------------------ 
-**Important** : Ce fichier décrit un Service **NodePort**. Notez que le Service expose le port **80** sur tout POD ayant le nom **voting-app-pod**. +# FILE LOCATIONS 
-</WRAP>+#------------------------------------------------------------------------------
  
-Dernièrement, créez le fichier **result-app-service.yaml** :+# The default values of these variables are driven from the -D command-line 
 +# option or PGDATA environment variable, represented here as ConfigDir.
  
-<code> +#data_directory = 'ConfigDir'           # use data in another directory 
-root@kubemaster:~/appvi result-app-service.yaml +                                        (change requires restart) 
-root@kubemaster:~/appcat result-app-service.yaml +#hba_file = 'ConfigDir/pg_hba.conf'     host-based authentication file 
---- +                                        # (change requires restart) 
-apiVersion: v1 +#ident_file = 'ConfigDir/pg_ident.conf' # ident configuration file 
-kind: Service +                                        # (change requires restart)
-metadata: +
-  name: result-service +
-  labels: +
-    name: result-service +
-    app: demo-voting-app+
  
-spec: +# If external_pid_file is not explicitly set, no extra PID file is written. 
-  type: NodePort +#external_pid_file = ''                 # write an extra PID file 
-  ports: +                                        # (change requires restart)
-  - port: 80 +
-    targetPort: 80 +
-  selector: +
-    name: result-app-pod +
-    app: demo-voting-app +
-</code>+
  
-<WRAP center round important> 
-**Important** : Ce fichier décrit un Service **NodePort**. Notez que le Service expose le port **80** sur tout POD ayant le nom **result-app-pod**. 
-</WRAP> 
  
-====2.4 Déployer l'Application====+#------------------------------------------------------------------------------ 
 +# CONNECTIONS AND AUTHENTICATION 
 +#------------------------------------------------------------------------------
  
-Vérifiez que vous avez créé tous les fichiers YAML necéssaires : +--More--
- +
-<code> +
-root@kubemaster:~/myapp# ls +
-postgres-deployment.yaml  redis-deployment.yaml  result-app-deployment.yaml  voting-app-deployment.yaml  worker-deployment.yaml +
-postgres-service.yaml     redis-service.yaml     result-app-service.yaml     voting-app-service.yaml+
 </code> </code>
  
-Utilisez ensuite la commande **kubectl create** :+Dernièrement, Il est évidement possible de rentrer dans le conteneur lui-même afin de procéder à des recherches de problèmes éventuels :
  
 <code> <code>
-root@kubemaster:~/myapp# kubectl create -f . +root@kubemaster:~# kubectl exec postgresql-6f885d8957-tnlbb --stdin --tty -- /bin/bash 
-deployment.apps/postgres-deployment created +I have no name!@postgresql-6f885d8957-tnlbb:/$ exit 
-service/db created +exit 
-deployment.apps/redis-deployment created +root@kubemaster:~# 
-service/redis created +
-deployment.apps/result-app-deployment created +
-service/result-service created +
-deployment.apps/voting-app-deployment created +
-service/voting-service created +
-deployment.apps/worker-app-deployment created+
 </code> </code>
  
-<WRAP center round important> +=====LAB #5 - Le Réseau======
-**Important** : Notez l'utilisation du caractère **.** qui indique tout fichier dans le répertoire courant. +
-</WRAP>+
  
-Attendez que tous les Deployments soient **READY** (7 à 10 minutes) :+====5.1 - kube-proxy et le DNS==== 
 + 
 +Utilisez la commande **kubectl get pods** pour obtenir les noms des pods **kube-proxy** et **coredns** :
  
 <code> <code>
-root@kubemaster:~/myapp# kubectl get deployments +root@kubemaster:~# kubectl get pods -n kube-system 
-NAME                    READY   UP-TO-DATE   AVAILABLE   AGE +NAME                                                READY   STATUS    RESTARTS        AGE 
-postgres-deployment     1/1                          51m +calico-kube-controllers-6799f5f4b4-2tgpq            1/1     Running   0               160m 
-redis-deployment        1/1                          51m +calico-node-5htrc                                   1/1     Running   (12d ago)     24d 
-result-app-deployment   1/1                1           51m +calico-node-dc7hd                                   1/1     Running   1 (12d ago)     24d 
-voting-app-deployment   1/1                          51m +calico-node-qk5kt                                   1/1     Running   (12d ago)     24d 
-worker-app-deployment   1/1                1           51m+coredns-565d847f94-kkpbp                            1/1     Running                 160m 
 +coredns-565d847f94-tqd8z                            1/1     Running   1 (12d ago)     23d 
 +etcd-kubemaster.ittraining.loc                      1/1     Running   (12d ago)     23d 
 +kube-apiserver-kubemaster.ittraining.loc            1/1     Running   1 (12d ago)     23d 
 +kube-controller-manager-kubemaster.ittraining.loc   1/1     Running   12 (5d4h ago)   23d 
 +kube-proxy-ggmt6                                    1/    Running   1 (12d ago)     23d 
 +kube-proxy-x5j2r                                    1/1     Running   1 (12d ago)     23d 
 +kube-proxy-x7fpc                                    1/1     Running   (12d ago)     23d 
 +kube-scheduler-kubemaster.ittraining.loc            1/1     Running   14 (31h ago)    23d 
 +metrics-server-5dbb5ff5bd-vh5fz                     1/    Running   1 (12d ago)     23d
 </code> </code>
  
-Contrôlez ensuite l'état des PODs :+Recherchez des erreurs éventuelles dans les journaux de chaque pod :
  
 <code> <code>
-root@kubemaster:~/myapp# kubectl get pods +root@kubemaster:~# kubectl logs -n kube-system kube-proxy-ggmt6 | tail 
-NAME                                     READY   STATUS    RESTARTS   AGE +I0916 07:32:34.968850       shared_informer.go:255] Waiting for caches to sync for service config 
-postgres-deployment-5b8bd66778-j99zz     1/    Running            51m +I0916 07:32:34.968975       config.go:226] "Starting endpoint slice config controller" 
-redis-deployment-67d4c466c4-9wzfn        1/    Running            51m +I0916 07:32:34.968988       shared_informer.go:255] Waiting for caches to sync for endpoint slice config 
-result-app-deployment-b8f9dc967-nzbgd    1/    Running            51m +I0916 07:32:34.968995       config.go:444] "Starting node config controller" 
-voting-app-deployment-669dccccfb-jpn6h   1/    Running            51m +I0916 07:32:34.969002       shared_informer.go:255] Waiting for caches to sync for node config 
-worker-app-deployment-559f7749b6-jh86r   1/    Running            51m+I0916 07:32:35.069078       shared_informer.go:262] Caches are synced for service config 
 +I0916 07:32:35.069147       shared_informer.go:262] Caches are synced for node config 
 +I0916 07:32:35.069169       shared_informer.go:262] Caches are synced for endpoint slice config 
 +I0916 07:33:06.103911       1 trace.go:205] Trace[210170851]: "iptables restore" (16-Sep-2022 07:33:03.886) (total time: 2216ms): 
 +Trace[210170851]: [2.216953699s] [2.216953699s] END
 </code> </code>
- 
-ainsi que la liste des Services : 
  
 <code> <code>
-root@kubemaster:~/myapp# kubectl get services +root@kubemaster:~# kubectl logs -n kube-system coredns-565d847f94-kkpbp | tail 
-NAME             TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE +[INFO] plugin/kubernetes: waiting for Kubernetes API before starting server 
-db               ClusterIP   10.107.90.45     <none>        5432/TCP       24h +[INFO] plugin/kubernetes: waiting for Kubernetes API before starting server 
-kubernetes       ClusterIP   10.96.0.1        <none>        443/TCP        4d9h +.:53 
-redis            ClusterIP   10.102.154.105   <none>        6379/TCP       24h +[INFO] plugin/reload: Running configuration SHA512 = 591cf328cccc12bc490481273e738df59329c62c0b729d94e8b61db9961c2fa5f046dd37f1cf888b953814040d180f52594972691cd6ff41be96639138a43908 
-result-service   NodePort    10.103.192.107   <none>        80:31526/TCP   24h +CoreDNS-1.9.
-voting-service   NodePort    10.96.42.244     <none>        80:32413/TCP   24h+linux/amd64, go1.18.2, 45b0a11
 </code> </code>
  
-Dans le cas donc de l'exemple dans ce cours, l'application ressemble maintenant au diagramme suivant :+====5.2 - Le Conteneur netshoot====
  
-{{ :elearning:workbooks:debian:6:avance:app1.png?direct&400 |}}+Si, à ce stade, vous n'avez pas trouvé d'erreurs apparentes, il convient de créer un pod qui contiendra un conteneur généré de l'image **nicolaka/netshoot**. Cette image contient un grand nombre d'outils de dépannage pré-installés :
  
-====2.5 - Scaling Up=====+{{ :elearning:workbooks:kubernetes:netshoot.png?nolink&600 |}}
  
-Éditez le fichier **voting-app-deployment.yaml** et modifiez la valeur du champ **replicas** de 1 à 3 :+Créez le fichier **nginx-netshoot.yaml** :
  
 <code> <code>
-root@kubemaster:~/app# vi voting-app-deployment.yaml +root@kubemaster:~# vi nginx-netshoot.yaml 
-root@kubemaster:~/app# cat voting-app-deployment.yaml +root@kubemaster:~# cat nginx-netshoot.yaml 
---- +apiVersion: v1 
-apiVersion: apps/v1 +kind: Pod
-kind: Deployment+
 metadata: metadata:
-  name: voting-app-deployment+  name: nginx-netshoot
   labels:   labels:
-    app: demo-voting-app+    app: nginx-netshoot
 spec: spec:
-  replicas3+  containers: 
 +  - name: nginx 
 +    image: nginx:1.19.1 
 +--- 
 +apiVersion: v1 
 +kind: Service 
 +metadata: 
 +  name: service-netshoot 
 +spec: 
 +  type: ClusterIP
   selector:   selector:
-    matchLabels: +    app: nginx-netshoot 
-      name: voting-app-pod +  ports
-      app: demo-voting-app +    - protocolTCP 
-  template+      port80 
-    metadata: +      targetPort: 80
-      name: voting-app-pod +
-      labels: +
-        name: voting-app-pod +
-        app: demo-voting-app +
- +
-    spec+
-      containers+
-      - name: voting-app +
-        image: dockersamples/examplevotingapp_vote +
-        ports: +
-        - containerPort: 80+
 </code> </code>
  
-Éditez le fichier **result-app-deployment.yaml** et modifiez la valeur du champ **replicas** de 1 à 3 :+Créez le pod et le service :
  
 <code> <code>
-root@kubemaster:~/appvi result-app-deployment.yaml +root@kubemaster:~# kubectl create -f nginx-netshoot.yaml 
-root@kubemaster:~/app# cat result-app-deployment.yaml +pod/nginx-netshoot created 
---- +service/service-netshoot created
-apiVersion: apps/v1 +
-kind: Deployment +
-metadata: +
-  name: result-app-deployment +
-  labels: +
-    app: demo-voting-app +
-spec: +
-  replicas: 3 +
-  selector: +
-    matchLabels: +
-      name: result-app-pod +
-      app: demo-voting-app +
-  template: +
-    metadata: +
-      name: result-app-pod +
-      labels: +
-        name: result-app-pod +
-        app: demo-voting-app +
- +
-    spec: +
-      containers: +
-      - name: result-app +
-        image: dockersamples/examplevotingapp_result +
-        ports: +
-        containerPort: 80+
 </code> </code>
  
-Appliquez les modifications à l'aide de la commande **kubectl apply** :+Vérifiez que le service est en cours d'exécution :
  
 <code> <code>
-root@kubemaster:~/myapp# kubectl apply -f voting-app-deployment.yaml +root@kubemaster:~# kubectl get services 
-Warning: kubectl apply should be used on resource created by either kubectl create --save-config or kubectl apply +NAME               TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)   AGE 
-deployment.apps/voting-app-deployment configured +kubernetes         ClusterIP   10.96.0.1       <none>        443/TCP   24d 
- +service-netshoot   ClusterIP   10.107.115.28   <none>        80/TCP    5m18s
-root@kubemaster:~/myapp# kubectl apply -f result-app-deployment.yaml +
-Warning: kubectl apply should be used on resource created by either kubectl create --save-config or kubectl apply +
-deployment.apps/result-app-deployment configured+
 </code> </code>
  
-Contrôlez ensuite les Deployments :+Créez maintenant le fichier **netshoot.yaml** :
  
 <code> <code>
-root@kubemaster:~/myappkubectl get deployments +root@kubemaster:~# vi netshoot.yaml 
-NAME                    READY   UP-TO-DATE   AVAILABLE   AGE +root@kubemaster:~# cat netshoot.yaml 
-postgres-deployment     1/               1           23h +apiVersion: v1 
-redis-deployment        1/1                1           23h +kind: Pod 
-result-app-deployment   3/               3           23h +metadata: 
-voting-app-deployment   3/3                3           23h +  name: netshoot 
-worker-app-deployment   1/               1           23h+spec: 
 +  containers: 
 +  name: netshoot 
 +    image: nicolaka/netshoot 
 +    command: ['sh', '-c', 'while true; do sleep 5; done']
 </code> </code>
  
-ainsi que les PODs :+Créez le pod :
  
 <code> <code>
-root@kubemaster:~/myapp# kubectl get pods -o wide +root@kubemaster:~# kubectl create -f netshoot.yaml 
-NAME                                     READY   STATUS    RESTARTS   AGE     IP                NODE        NOMINATED NODE   READINESS GATES +pod/netshoot created
-postgres-deployment-5b8bd66778-j99zz     1/    Running            169m    192.168.35.83     kubenode2   <none>           <none> +
-redis-deployment-67d4c466c4-9wzfn        1/1     Running            169m    192.168.205.217   kubenode1   <none>           <none> +
-result-app-deployment-b8f9dc967-nzbgd    1/1     Running            169m    192.168.205.218   kubenode1   <none>           <none> +
-result-app-deployment-b8f9dc967-r84k6    1/1     Running            2m36s   192.168.35.86     kubenode2   <none>           <none> +
-result-app-deployment-b8f9dc967-zbsk2    1/1     Running            2m36s   192.168.35.85     kubenode2   <none>           <none> +
-voting-app-deployment-669dccccfb-jpn6h   1/    Running            169m    192.168.35.82     kubenode2   <none>           <none> +
-voting-app-deployment-669dccccfb-ktd7d   1/    Running            2m50s   192.168.35.84     kubenode2   <none>           <none> +
-voting-app-deployment-669dccccfb-x868p   1/    Running            2m50s   192.168.205.219   kubenode1   <none>           <none> +
-worker-app-deployment-559f7749b6-jh86r   1/    Running            169m    192.168.205.216   kubenode1   <none>           <none>+
 </code> </code>
  
-Dans le cas de l'exemple dans ce cours, l'application ressemble maintenant au diagramme suivant :+Vérifiez que le status du pod est **READY** :
  
-{{ :elearning:workbooks:debian:6:avance:app2.png?direct&600 |}}+<code> 
 +root@kubemaster:~# kubectl get pods 
 +NAME                          READY   STATUS      RESTARTS   AGE 
 +netshoot                      1/1     Running              6m7s 
 +nginx-netshoot                1/1     Running              9m32s 
 +postgresql-6f885d8957-tnlbb   1/    Running              98m 
 +sharedvolume                  2/2     Running              8d 
 +troubleshooting               1/    Running              125m 
 +volumepod                     0/    Completed            8d 
 +</code>
  
-Retournez sur le navigateur de votre machine hôte et rafraichissez la page du voting-app :+Entrez dans le conteneur **netshoot** :
  
-{{ :elearning:workbooks:debian:6:avance:kubernetes19.png?direct&800 |}}+<code> 
 +root@kubemaster:~# kubectl exec --stdin --tty netshoot -- /bin/bash 
 +bash-5.1#  
 +</code>
  
-<WRAP center round important> +Testez le bon fonctionnement du service **service-netshoot** :
-**Important** : Notez le POD qui a servi la page. +
-</WRAP>+
  
-Rafraîchissez la page de nouveau :+<code> 
 +bash-5.1# curl service-netshoot 
 +<!DOCTYPE html> 
 +<html> 
 +<head> 
 +<title>Welcome to nginx!</title> 
 +<style> 
 +    body { 
 +        width35em; 
 +        margin: 0 auto; 
 +        font-family: Tahoma, Verdana, Arial, sans-serif; 
 +    } 
 +</style> 
 +</head> 
 +<body> 
 +<h1>Welcome to nginx!</h1> 
 +<p>If you see this page, the nginx web server is successfully installed and 
 +working. Further configuration is required.</p>
  
-{{ :elearning:workbooks:debian:6:avance:kubernetes20.png?direct&800 |}}+<p>For online documentation and support please refer to 
 +<a href="http://nginx.org/">nginx.org</a>.<br/> 
 +Commercial support is available at 
 +<a href="http://nginx.com/">nginx.com</a>.</p>
  
-<WRAP center round important> +<p><em>Thank you for using nginx.</em></p> 
-**Important** : Notez que le POD qui a servi la page a changé+</body
-</WRAP+</html> 
- +</code>
-Notez que ce changement de POD n'indique pas un équilibrage de charge. En effet, il faudrait mettre en place une autre machine virtuelle sous, par exemple, HAProxy pour obtenir l'équilibrage.+
  
-Par contredans le cas d'une application sur GCP par exemple, il convient de modifier les deux fichiers suivants en changeant la valeur de champ **type** de NodePort à **LoadBalancer** puis de configurer une instance du Load Balancer natif de GCP :+Dernièrementutilisez la commande **nslookup** pour obtenir l'adresse IP du service :
  
 <code> <code>
-root@kubemaster:~/app# vi voting-app-service.yaml +bash-5.1nslookup service-netshoot 
-root@kubemaster:~/appcat voting-app-service.yaml +Server        10.96.0.10 
---+Address       10.96.0.10#53
-apiVersionv1 +
-kindService +
-metadata: +
-  name: voting-service +
-  labels: +
-    name: voting-service +
-    app: demo-voting-app+
  
-spec: +Name  service-netshoot.default.svc.cluster.local 
-  type: LoadBalancer +Address10.107.115.28
-  ports: +
-  port: 80 +
-    targetPort80 +
-  selector: +
-    name: voting-app-pod +
-    app: demo-voting-app+
 </code> </code>
  
-<WRAP center round important> +<WRAP center round important 60%
-**Important** : Ce fichier décrit un Service **LoadBalancer**. Notez que le Service expose le port **80** sur tout POD ayant le nom **voting-app-pod**.+**Important** : Pour plus d'information concernant les outils inclus dans le conteneur **[[https://github.com/nicolaka/netshoot|netshoot]]**, consultez la page de **[[https://github.com/nicolaka/netshoot|netshoot]]** sur **GitHub**.
 </WRAP> </WRAP>
- 
-Dernièrement, créez le fichier **result-app-service.yaml** : 
- 
-<code> 
-root@kubemaster:~/app# vi result-app-service.yaml 
-root@kubemaster:~/app# cat result-app-service.yaml 
---- 
-apiVersion: v1 
-kind: Service 
-metadata: 
-  name: result-service 
-  labels: 
-    name: result-service 
-    app: demo-voting-app 
- 
-spec: 
-  type: LoadBalancer 
-  ports: 
-  - port: 80 
-    targetPort: 80 
-  selector: 
-    name: result-app-pod 
-    app: demo-voting-app 
-</code> 
  
 ---- ----
-Copyright © 2022 Hugh Norris +Copyright © 2024 Hugh Norris
Menu