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:k8s02 [2022/09/11 09:32] – admin | elearning:workbooks:kubernetes:k8s02 [2024/12/15 06:47] (Version actuelle) – admin | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| ~~PDF: | ~~PDF: | ||
| - | Version - **2020.03** | + | Version - **2024.01** |
| Dernière mise-à-jour : ~~LASTMOD~~ | Dernière mise-à-jour : ~~LASTMOD~~ | ||
| Ligne 25: | Ligne 25: | ||
| * La Commande top | * La Commande top | ||
| * 1.5 - Travailler avec la commande kubectl | * 1.5 - Travailler avec la commande kubectl | ||
| + | * La Commande apply | ||
| + | * La Commande create | ||
| + | * La Commande get | ||
| + | * Utilisation des Options | ||
| + | * La Commande exec | ||
| + | * Commandes Impératives | ||
| * LAB #2 - Gestion les plugins de kubectl avec la Commande krew | * LAB #2 - Gestion les plugins de kubectl avec la Commande krew | ||
| * 2.1 - Installation de krew | * 2.1 - Installation de krew | ||
| Ligne 31: | Ligne 37: | ||
| * 2.4 - Mise à jour et suppression de plugins | * 2.4 - Mise à jour et suppression de plugins | ||
| * LAB #3 - Gestion des patchs avec la Commande kustomize | * LAB #3 - Gestion des patchs avec la Commande kustomize | ||
| + | |||
| + | =====Ressources===== | ||
| + | |||
| + | ====Lab #1===== | ||
| + | |||
| + | * https:// | ||
| + | * https:// | ||
| + | |||
| + | ====Lab #2==== | ||
| + | |||
| + | * https:// | ||
| + | |||
| + | ====Lab #3==== | ||
| + | |||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| =====LAB #1 - Utilisation de la Commande kubectl===== | =====LAB #1 - Utilisation de la Commande kubectl===== | ||
| Ligne 692: | Ligne 717: | ||
| </ | </ | ||
| - | <WRAP center round important | + | <WRAP center round important |
| **Important** : Notez l' | **Important** : Notez l' | ||
| </ | </ | ||
| Ligne 824: | Ligne 849: | ||
| command: [' | command: [' | ||
| </ | </ | ||
| + | |||
| + | ====La Commande apply==== | ||
| Créez maintenant le pod en utilisant le fichier **pod.yaml** : | Créez maintenant le pod en utilisant le fichier **pod.yaml** : | ||
| Ligne 831: | Ligne 858: | ||
| pod/my-pod created | pod/my-pod created | ||
| </ | </ | ||
| + | |||
| + | ====La Commande create==== | ||
| + | |||
| + | La commande **create** ne peut être utilisée que dans le cas où un objet du même nom n' | ||
| < | < | ||
| - | root@kubemaster: | + | root@kubemaster: |
| - | You must specify the type of resource to get. Use "kubectl api-resources" | + | Error from server (AlreadyExists): |
| + | </ | ||
| - | error: Required | + | Pour consulter la liste des objets qui peuvent être créés, utilisez la commande **kubectl create** |
| - | Use "kubectl | + | |
| - | See 'kubectl get -h' | + | < |
| + | root@kubemaster: | ||
| + | Error: must specify one of -f and -k | ||
| + | |||
| + | Create a resource | ||
| + | |||
| + | JSON and YAML formats are accepted. | ||
| + | |||
| + | Examples: | ||
| + | # Create a pod using the data in pod.json | ||
| + | | ||
| + | |||
| + | # Create a pod based on the JSON passed into stdin | ||
| + | cat pod.json | kubectl create -f - | ||
| + | |||
| + | # Edit the data in registry.yaml in JSON then create the resource | ||
| + | kubectl create -f registry.yaml --edit -o json | ||
| + | |||
| + | Available Commands: | ||
| + | clusterrole | ||
| + | clusterrolebinding | ||
| + | configmap | ||
| + | cronjob | ||
| + | deployment | ||
| + | ingress | ||
| + | job | ||
| + | namespace | ||
| + | poddisruptionbudget | ||
| + | priorityclass | ||
| + | quota | ||
| + | role Create a role with single rule | ||
| + | rolebinding | ||
| + | secret | ||
| + | service | ||
| + | serviceaccount | ||
| + | token | ||
| + | |||
| + | Options: | ||
| + | --allow-missing-template-keys=true: | ||
| + | If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to | ||
| + | golang and jsonpath output formats. | ||
| + | |||
| + | --dry-run=' | ||
| + | Must be " | ||
| + | sending it. If server strategy, submit server-side request without persisting the resource. | ||
| + | |||
| + | --edit=false: | ||
| + | Edit the API resource before creating | ||
| + | |||
| + | --field-manager=' | ||
| + | Name of the manager used to track field ownership. | ||
| + | |||
| + | -f, --filename=[]: | ||
| + | Filename, directory, or URL to files to use to create the resource | ||
| + | |||
| + | -k, --kustomize='': | ||
| + | Process the kustomization directory. This flag can't be used together with -f or -R. | ||
| + | |||
| + | -o, --output='': | ||
| + | Output format. One of: (json, yaml, name, go-template, | ||
| + | jsonpath-as-json, | ||
| + | |||
| + | --raw='': | ||
| + | Raw URI to POST to the server. | ||
| + | |||
| + | -R, --recursive=false: | ||
| + | Process the directory used in -f, --filename recursively. Useful when you want to manage related manifests | ||
| + | organized within the same directory. | ||
| + | |||
| + | --save-config=false: | ||
| + | If true, the configuration of current object will be saved in its annotation. Otherwise, the annotation will | ||
| + | be unchanged. This flag is useful when you want to perform kubectl apply on this object in the future. | ||
| + | |||
| + | -l, --selector='': | ||
| + | Selector (label query) to filter on, supports ' | ||
| + | | ||
| + | |||
| + | --show-managed-fields=false: | ||
| + | If true, keep the managedFields when printing objects in JSON or YAML format. | ||
| + | |||
| + | --template='': | ||
| + | Template string or path to template file to use when -o=go-template, | ||
| + | is golang templates [http:// | ||
| + | |||
| + | --validate='strict': | ||
| + | Must be one of: strict (or true), warn, ignore (or false). | ||
| + | the input and fail the request if invalid. It will perform server side validation if ServerSideFieldValidation | ||
| + | is enabled on the api-server, but will fall back to less reliable client-side validation if not. " | ||
| + | warn about unknown or duplicate fields without blocking the request if server-side field validation is enabled | ||
| + | on the API server, and behave as " | ||
| + | validation, silently dropping any unknown or duplicate fields. | ||
| + | |||
| + | --windows-line-endings=false: | ||
| + | Only relevant if --edit=true. Defaults to the line ending native to your platform. | ||
| + | |||
| + | Usage: | ||
| + | kubectl create -f FILENAME [options] | ||
| + | |||
| + | Use " | ||
| + | Use " | ||
| </ | </ | ||
| + | |||
| + | La commande **apply** est ensuite utilisée pour appliquer des modifications apportées au fichier yaml : | ||
| + | |||
| + | < | ||
| + | root@kubemaster: | ||
| + | pod/my-pod unchanged | ||
| + | </ | ||
| + | |||
| + | ====La Commande get==== | ||
| + | |||
| + | Constatez le statut du pod : | ||
| < | < | ||
| Ligne 849: | Ligne 991: | ||
| myapp-deployment-689f9d59-rnc4r | myapp-deployment-689f9d59-rnc4r | ||
| </ | </ | ||
| + | |||
| + | Rappelez-vous que vous pouvez utiliser une abréviation pour pods : | ||
| < | < | ||
| Ligne 858: | Ligne 1002: | ||
| myapp-deployment-689f9d59-rnc4r | myapp-deployment-689f9d59-rnc4r | ||
| </ | </ | ||
| + | |||
| + | Pour ne voir qu'un seul pod, il convient de préciser son nom en tant qu' | ||
| < | < | ||
| Ligne 864: | Ligne 1010: | ||
| my-pod | my-pod | ||
| </ | </ | ||
| + | |||
| + | ====Utilisation des Options==== | ||
| + | |||
| + | Rappelez-vous que l' | ||
| < | < | ||
| Ligne 873: | Ligne 1023: | ||
| myapp-deployment-689f9d59-rnc4r | myapp-deployment-689f9d59-rnc4r | ||
| </ | </ | ||
| + | |||
| + | L' | ||
| < | < | ||
| Ligne 917: | Ligne 1069: | ||
| --More-- | --More-- | ||
| </ | </ | ||
| + | |||
| + | L' | ||
| < | < | ||
| Ligne 961: | Ligne 1115: | ||
| --More-- | --More-- | ||
| </ | </ | ||
| + | |||
| + | L' | ||
| < | < | ||
| Ligne 970: | Ligne 1126: | ||
| my-pod | my-pod | ||
| </ | </ | ||
| + | |||
| + | L' | ||
| < | < | ||
| Ligne 979: | Ligne 1137: | ||
| </ | </ | ||
| - | k8s-app is a label | + | ====La Commande exec==== |
| - | < | + | La commande **exec** permet d' |
| - | root@kubemaster: | + | |
| - | Error from server (AlreadyExists): | + | |
| - | </ | + | |
| - | + | ||
| - | < | + | |
| - | root@kubemaster:~# kubectl apply -f pod.yaml | + | |
| - | pod/my-pod unchanged | + | |
| - | </ | + | |
| < | < | ||
| Ligne 996: | Ligne 1146: | ||
| </ | </ | ||
| - | busybox is the container name | + | <WRAP center round important 60%> |
| + | **Important** : Notez l' | ||
| + | </ | ||
| - | < | ||
| - | root@kubemaster: | ||
| - | pod " | ||
| - | </ | ||
| - | < | + | ====5.6 |
| - | root@kubemaster: | + | |
| - | Error: must specify one of -f and -k | + | |
| - | Create a resource from a file or from stdin. | + | Avant de poursuivre, supprimez le pod **my-pod** : |
| - | + | ||
| - | JSON and YAML formats are accepted. | + | |
| - | + | ||
| - | Examples: | + | |
| - | # Create a pod using the data in pod.json | + | |
| - | kubectl create | + | |
| - | + | ||
| - | # Create a pod based on the JSON passed into stdin | + | |
| - | cat pod.json | kubectl create -f - | + | |
| - | + | ||
| - | # Edit the data in registry.yaml in JSON then create the resource using the edited data | + | |
| - | kubectl create -f registry.yaml --edit -o json | + | |
| - | + | ||
| - | Available Commands: | + | |
| - | clusterrole | + | |
| - | clusterrolebinding | + | |
| - | configmap | + | |
| - | cronjob | + | |
| - | deployment | + | |
| - | ingress | + | |
| - | job | + | |
| - | namespace | + | |
| - | poddisruptionbudget | + | |
| - | priorityclass | + | |
| - | quota | + | |
| - | role Create a role with single rule | + | |
| - | rolebinding | + | |
| - | secret | + | |
| - | service | + | |
| - | serviceaccount | + | |
| - | token | + | |
| - | + | ||
| - | Options: | + | |
| - | --allow-missing-template-keys=true: | + | |
| - | If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to | + | |
| - | golang and jsonpath output formats. | + | |
| - | + | ||
| - | --dry-run=' | + | |
| - | Must be " | + | |
| - | sending it. If server strategy, submit server-side request without persisting the resource. | + | |
| - | + | ||
| - | --edit=false: | + | |
| - | Edit the API resource before creating | + | |
| - | + | ||
| - | --field-manager=' | + | |
| - | Name of the manager used to track field ownership. | + | |
| - | + | ||
| - | -f, --filename=[]: | + | |
| - | Filename, directory, or URL to files to use to create the resource | + | |
| - | + | ||
| - | -k, --kustomize='': | + | |
| - | Process the kustomization directory. This flag can't be used together with -f or -R. | + | |
| - | + | ||
| - | -o, --output='': | + | |
| - | Output format. One of: (json, yaml, name, go-template, | + | |
| - | jsonpath-as-json, | + | |
| - | + | ||
| - | --raw='': | + | |
| - | Raw URI to POST to the server. | + | |
| - | + | ||
| - | -R, --recursive=false: | + | |
| - | Process the directory used in -f, --filename recursively. Useful when you want to manage related manifests | + | |
| - | organized within the same directory. | + | |
| - | + | ||
| - | --save-config=false: | + | |
| - | If true, the configuration of current object will be saved in its annotation. Otherwise, the annotation will | + | |
| - | be unchanged. This flag is useful when you want to perform kubectl apply on this object in the future. | + | |
| - | + | ||
| - | -l, --selector='': | + | |
| - | Selector (label query) to filter on, supports ' | + | |
| - | objects must satisfy all of the specified label constraints. | + | |
| - | + | ||
| - | --show-managed-fields=false: | + | |
| - | If true, keep the managedFields when printing objects in JSON or YAML format. | + | |
| - | + | ||
| - | --template='': | + | |
| - | Template string or path to template file to use when -o=go-template, | + | |
| - | is golang templates [http:// | + | |
| - | + | ||
| - | --validate=' | + | |
| - | Must be one of: strict (or true), warn, ignore (or false). | + | |
| - | the input and fail the request if invalid. It will perform server side validation if ServerSideFieldValidation | + | |
| - | is enabled on the api-server, but will fall back to less reliable client-side validation if not. " | + | |
| - | warn about unknown or duplicate fields without blocking the request if server-side field validation is enabled | + | |
| - | on the API server, and behave as " | + | |
| - | validation, silently dropping any unknown or duplicate fields. | + | |
| - | + | ||
| - | --windows-line-endings=false: | + | |
| - | Only relevant if --edit=true. Defaults to the line ending native to your platform. | + | |
| - | + | ||
| - | Usage: | + | |
| - | kubectl create -f FILENAME [options] | + | |
| - | + | ||
| - | Use " | + | |
| - | Use " | + | |
| - | </ | + | |
| < | < | ||
| - | kubectl | + | root@kubemaster: |
| + | pod "my-pod" deleted | ||
| </ | </ | ||
| - | Imperitive command | + | Créez ensuite un deployment avec une commande impérative : |
| < | < | ||
| Ligne 1116: | Ligne 1167: | ||
| </ | </ | ||
| - | < | + | En exécutant la même commande impérative, |
| - | kubectl create deployment my-deployment --image=nginx | + | |
| - | </ | + | |
| < | < | ||
| Ligne 1148: | Ligne 1197: | ||
| status: {} | status: {} | ||
| </ | </ | ||
| + | |||
| + | Ces instructions peuvent ensuite être injectées dans un fichier afin d' | ||
| < | < | ||
| Ligne 1752: | Ligne 1803: | ||
| </ | </ | ||
| - | <WRAP center round important> | + | <WRAP center round important |
| **Important** - le contenu de ce fichier crée un **deployment** de 1 **replica** du pod **nginx** à partir de l' | **Important** - le contenu de ce fichier crée un **deployment** de 1 **replica** du pod **nginx** à partir de l' | ||
| </ | </ | ||
| Ligne 1777: | Ligne 1828: | ||
| </ | </ | ||
| - | <WRAP center round important> | + | <WRAP center round important |
| **Important** - le contenu de ce fichier crée un **service** de type **ClusterIP** en utilisant le **deployment** précédent. Le Service ClusterIP permet de regrouper les PODs offrant le même service afin de faciliter la communication. | **Important** - le contenu de ce fichier crée un **service** de type **ClusterIP** en utilisant le **deployment** précédent. Le Service ClusterIP permet de regrouper les PODs offrant le même service afin de faciliter la communication. | ||
| </ | </ | ||
| Ligne 1798: | Ligne 1849: | ||
| </ | </ | ||
| - | <WRAP center round important> | + | <WRAP center round important |
| **Important** - le contenu de ce fichier contient un **patch** pour l' | **Important** - le contenu de ce fichier contient un **patch** pour l' | ||
| </ | </ | ||
| Ligne 1867: | Ligne 1918: | ||
| </ | </ | ||
| - | <WRAP center round important | + | <WRAP center round important |
| **Important** - notez que le fichier généré contient les contenus des **deux** fichiers **deployment.yaml** et **service.yaml** séparés par les caractères **---**. Le contenu du fichier **service.yaml** n'a pas été modifié tandis que l' | **Important** - notez que le fichier généré contient les contenus des **deux** fichiers **deployment.yaml** et **service.yaml** séparés par les caractères **---**. Le contenu du fichier **service.yaml** n'a pas été modifié tandis que l' | ||
| </ | </ | ||
| Ligne 1896: | Ligne 1947: | ||
| </ | </ | ||
| - | Créez le fichier **overlays/ | + | Créez le fichier **dev_kustomization.yaml** : |
| < | < | ||
| - | root@debian10: | + | root@kubemaster: |
| - | root@debian10: | + | root@kubemaster: |
| apiVersion: kustomize.config.k8s.io/ | apiVersion: kustomize.config.k8s.io/ | ||
| kind: Kustomization | kind: Kustomization | ||
| Ligne 1918: | Ligne 1969: | ||
| < | < | ||
| - | root@debian10: | + | root@kubemaster: |
| apiVersion: v1 | apiVersion: v1 | ||
| kind: Service | kind: Service | ||
| Ligne 1973: | Ligne 2024: | ||
| </ | </ | ||
| - | Maintenant créez le fichier **overlays/ | + | Maintenant créez le fichier **prod_kustomization.yaml** : |
| < | < | ||
| - | root@debian10: | + | root@kubemaster: |
| - | root@debian10: | + | root@kubemaster: |
| apiVersion: kustomize.config.k8s.io/ | apiVersion: kustomize.config.k8s.io/ | ||
| kind: Kustomization | kind: Kustomization | ||
| Ligne 1999: | Ligne 2050: | ||
| < | < | ||
| - | root@debian10: | + | root@kubemaster: |
| apiVersion: v1 | apiVersion: v1 | ||
| kind: Service | kind: Service | ||
| Ligne 2135: | Ligne 2186: | ||
| ---- | ---- | ||
| - | Copyright © 2022 Hugh Norris | + | Copyright © 2024 Hugh Norris |