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/04 11:55] – admin | elearning:workbooks:kubernetes:k8s02 [2024/12/15 06:47] (Version actuelle) – admin | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
~~PDF: | ~~PDF: | ||
- | Version - **2022.01** | + | Version - **2024.01** |
Dernière mise-à-jour : ~~LASTMOD~~ | Dernière mise-à-jour : ~~LASTMOD~~ | ||
- | ======DOF303 - Gestion de la Maintenance, des Mises-à-jour | + | ======DOF303 - Les Commandes kubectl, krew et kustomize====== |
=====Contenu du Module===== | =====Contenu du Module===== | ||
- | * **DOF303 - Gestion de la Maintenance, des Mises-à-jour | + | * **DOF303 - Les Commandes kubectl, krew et kustomize** |
* Contenu du Module | * Contenu du Module | ||
- | * LAB #1 - Gestion | + | * LAB #1 - Utilisation |
- | * 1.1 - La Commande | + | * 1.1 - Obtenir de l'Aide sur les Commandes de kubectl |
- | * 1.2 - La Commande | + | * 1.2 - Obtenir de l' |
- | * LAB #2 - Gestion | + | * La Commande |
- | * 2.1 - Mise-à-jour | + | * La Commande cluster-info |
- | * 2.2 - Mise-à-jour des Travailleurs | + | * La Commande api-versions |
- | * LAB #3 - Gestion | + | * La Commande api-resources |
+ | * 1.3 - Obtenir de l' | ||
+ | * La Commande | ||
+ | * La Commande top | ||
+ | * 1.4 - Obtenir de l' | ||
+ | * La Commande describe pod | ||
+ | * La Commande top | ||
+ | * 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 | ||
+ | * 2.1 - Installation de krew | ||
+ | * 2.2 - Consultation | ||
+ | * 2.3 - Installation et utilisation de plugins | ||
+ | * 2.4 - Mise à jour et suppression de plugins | ||
+ | * LAB #3 - Gestion | ||
- | =====LAB #1 - Gestion de la Maintenance===== | + | =====Ressources===== |
- | Afin de procéer à la maintenance d'un noeud, il est souvent necéssaire de le sortir du cluster. Cette opération s' | + | ====Lab #1===== |
- | ====1.1 - La Commande drain==== | + | * https://www.dropbox.com/ |
+ | * https:// | ||
- | Constatez | + | ====Lab #2==== |
+ | |||
+ | * https:// | ||
+ | |||
+ | ====Lab #3==== | ||
+ | |||
+ | * https:// | ||
+ | * https:// | ||
+ | * https:// | ||
+ | * https:// | ||
+ | * https:// | ||
+ | |||
+ | =====LAB #1 - Utilisation de la Commande kubectl===== | ||
+ | |||
+ | ====1.1 - Obtenir de l'Aide sur les Commandes de kubectl==== | ||
+ | |||
+ | Les commandes de **kubectl** sont regroupées par catégorie | ||
< | < | ||
- | root@kubemaster: | + | root@kubemaster: |
- | NAMESPACE | + | kubectl controls the Kubernetes cluster manager. |
- | default | + | |
- | default | + | Find more information at: https://kubernetes.io/ |
- | default | + | |
- | default | + | Basic Commands (Beginner): |
- | kube-system | + | |
- | kube-system | + | expose |
- | kube-system | + | run |
- | kube-system | + | set Set specific features on objects |
- | kube-system | + | |
- | kube-system | + | Basic Commands (Intermediate): |
- | kube-system | + | explain |
- | kube-system | + | get |
- | kube-system | + | edit Edit a resource on the server |
- | kube-system | + | delete |
- | kube-system | + | |
- | kube-system | + | Deploy Commands: |
- | kube-system | + | rollout |
+ | scale | ||
+ | | ||
+ | |||
+ | Cluster Management Commands: | ||
+ | certificate | ||
+ | cluster-info | ||
+ | | ||
+ | | ||
+ | | ||
+ | drain | ||
+ | taint | ||
+ | |||
+ | Troubleshooting and Debugging Commands: | ||
+ | describe | ||
+ | logs Print the logs for a container in a pod | ||
+ | attach | ||
+ | exec Execute a command in a container | ||
+ | port-forward | ||
+ | proxy | ||
+ | cp Copy files and directories to and from containers | ||
+ | | ||
+ | debug | ||
+ | |||
+ | Advanced Commands: | ||
+ | | ||
+ | apply | ||
+ | | ||
+ | | ||
+ | wait Experimental: | ||
+ | kustomize | ||
+ | |||
+ | Settings Commands: | ||
+ | label | ||
+ | | ||
+ | completion | ||
+ | |||
+ | Other Commands: | ||
+ | alpha | ||
+ | api-resources | ||
+ | api-versions | ||
+ | | ||
+ | plugin | ||
+ | version | ||
+ | |||
+ | Usage: | ||
+ | kubectl [flags] [options] | ||
+ | |||
+ | Use " | ||
+ | Use " | ||
</ | </ | ||
- | <WRAP center round important 60%> | + | Plus d' |
- | **Important** : Notez que sur **kubenode1.ittraining.loc**, | + | |
- | </ | + | |
- | Procédez maintenant au drain de kubenode1.ittraining.loc : | ||
- | |||
- | < | ||
- | root@kubemaster: | ||
- | node/ | ||
- | error: unable to drain node " | ||
- | There are pending nodes to be drained: | ||
- | | ||
- | cannot delete Pods declare no controller (use --force to override): default/ | ||
- | cannot delete DaemonSet-managed Pods (use --ignore-daemonsets to ignore): kube-system/ | ||
< | < | ||
+ | root@kubemaster: | ||
+ | Create a resource from a file or from stdin. | ||
- | Notez que la commande retourne deux erreurs : | + | JSON and YAML formats are accepted. |
- | * cannot delete Pods declare no controller (use --force to override): default/ | + | Examples: |
- | | + | |
+ | kubectl create | ||
| | ||
- | La première erreur est due au fait que l' | + | # Create a pod based on the JSON passed into stdin |
+ | cat pod.json | kubectl create | ||
+ | |||
+ | # Edit the data in registry.yaml in JSON then create the resource using the edited data | ||
+ | kubectl create -f registry.yaml --edit -o json | ||
- | <WRAP center round important 60%> | + | Available Commands: |
- | **Important** | + | clusterrole |
- | </ | + | clusterrolebinding |
+ | configmap | ||
+ | cronjob | ||
+ | deployment | ||
+ | ingress | ||
+ | job | ||
+ | namespace | ||
+ | poddisruptionbudget | ||
+ | priorityclass | ||
+ | quota | ||
+ | role Create a role with single rule | ||
+ | rolebinding | ||
+ | secret | ||
+ | service | ||
+ | serviceaccount | ||
+ | | ||
- | La deuxième erreur est due au fait que l' | + | 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. | ||
- | <WRAP center round important 60%> | + | --dry-run=' |
- | **Important** | + | Must be " |
- | </ | + | |
- | Exécutez donc la commande de nouveau en ajoutant les deux options **--ignore-daemonsets** et **--force** | + | |
+ | Edit the API resource before creating | ||
- | < | + | |
- | root@kubemaster: | + | Name of the manager used to track field ownership. |
- | node/ | + | |
- | WARNING: deleting Pods that declare no controller: default/ | + | |
- | evicting pod default/ | + | |
- | evicting pod default/ | + | |
- | pod/nginx evicted | + | |
- | pod/ | + | |
- | node/ | + | |
- | </ | + | |
- | <WRAP center round important 60%> | + | -f, --filename=[]: |
- | **Important** | + | |
- | </ | + | |
- | Consultez de nouveau l'état des pods : | + | -k, --kustomize=' |
+ | Process the kustomization directory. This flag can't be used together with -f or -R. | ||
- | < | + | |
- | root@kubemaster: | + | |
- | NAMESPACE | + | |
- | default | + | |
- | default | + | |
- | default | + | |
- | kube-system | + | |
- | kube-system | + | |
- | kube-system | + | |
- | kube-system | + | |
- | kube-system | + | |
- | kube-system | + | |
- | kube-system | + | |
- | kube-system | + | |
- | kube-system | + | |
- | kube-system | + | |
- | kube-system | + | |
- | kube-system | + | |
- | kube-system | + | |
- | </ | + | |
- | <WRAP center round important 60%> | + | |
- | **Important** : Notez que le pod **nginx** a été détruit tandis que le pod **myapp-deployment-57c6cb89d9-f69nk** a été **expulsé**. Un nouveau pod dénommé **myapp-deployment-57c6cb89d9-l7lkd** a été créé sur **kubenode2.ittraining.loc** afin de maintenir le nombre à **3**. Les deux pods **calico-node-5htrc** et **kube-proxy-sn26v** ont été ignorés. | + | Raw URI to POST to the server. Uses the transport specified by the kubeconfig file. |
- | </ | + | |
- | Constatez maintenant l' | + | -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: |
- | root@kubemaster:~# kubectl get nodes | + | If true, the configuration of current object will be saved in its annotation. Otherwise, the annotation will |
- | NAME STATUS | + | be unchanged. This flag is useful when you want to perform kubectl apply on this object in the future. |
- | kubemaster.ittraining.loc | + | |
- | kubenode1.ittraining.loc Ready,SchedulingDisabled | + | |
- | kubenode2.ittraining.loc Ready < | + | |
- | </ | + | |
- | <WRAP center round important 60%> | + | -l, --selector='' |
- | **Important** | + | Selector (label query) to filter on, supports ' |
- | </ | + | |
- | ====1.2 - La Commande uncordon==== | + | --show-managed-fields=false: |
+ | If true, keep the managedFields when printing objects in JSON or YAML format. | ||
- | Pour permettre le noeud de recevoir de nouveau des pods, il convient d'utiliser la commande suivante | + | --template='': |
+ | Template string or path to template file to use when -o=go-template, | ||
+ | is golang templates [http:// | ||
- | < | + | --validate=' |
- | root@kubemaster:~# kubectl uncordon kubenode1.ittraining.loc | + | Must be one of: strict (or true), warn, ignore (or false). " |
- | node/ | + | 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 " | ||
+ | | ||
+ | |||
+ | --windows-line-endings=false: | ||
+ | Only relevant if --edit=true. Defaults to the line ending native to your platform. | ||
- | Constatez de nouveau l' | + | Usage: |
+ | kubectl create -f FILENAME [options] | ||
- | <code> | + | Use " |
- | root@kubemaster: | + | Use "kubectl |
- | NAME STATUS | + | |
- | kubemaster.ittraining.loc | + | |
- | kubenode1.ittraining.loc | + | |
- | kubenode2.ittraining.loc | + | |
</ | </ | ||
- | Dernièrement | + | Dernièrement |
< | < | ||
- | root@kubemaster: | + | root@kubemaster: |
- | NAME READY | + | The following options can be passed to any command: |
- | myapp-deployment-57c6cb89d9-dh4cb | + | |
- | myapp-deployment-57c6cb89d9-f69nk | + | |
- | myapp-deployment-57c6cb89d9-l7lkd | + | |
- | </ | + | |
- | <WRAP center round important 60%> | + | --add-dir-header=false: |
- | **Important** | + | If true, adds the file directory to the header of the log messages (DEPRECATED: will be removed in a future |
- | </WRAP> | + | |
+ | https:// | ||
- | =====LAB #2 - Gestion des Mises-à-jour===== | + | --alsologtostderr=false: |
+ | log to standard error as well as files (no effect when -logtostderr=true) (DEPRECATED: | ||
+ | future release, see | ||
+ | https:// | ||
- | ====2.1 | + | |
+ | Username to impersonate for the operation. User could be a regular user or a service account in a namespace. | ||
- | Afin de mettre à jour kubeadm, il convient de faire un drain du **Contrôleur** | + | --as-group=[]: |
+ | Group to impersonate for the operation, this flag can be repeated to specify multiple groups. | ||
- | < | + | |
- | root@kubemaster: | + | UID to impersonate for the operation. |
- | node/ | + | |
- | WARNING: ignoring DaemonSet-managed Pods: kube-system/ | + | |
- | evicting pod kube-system/ | + | |
- | evicting pod kube-system/ | + | |
- | evicting pod kube-system/ | + | |
- | pod/ | + | |
- | pod/ | + | |
- | pod/ | + | |
- | node/ | + | |
- | </ | + | |
- | Afin de connaître la ou les version(s) supérieure(s) à celle installée, utilisez la commande suivante | + | --cache-dir='/ |
+ | Default cache directory | ||
- | < | + | --certificate-authority='': |
+ | Path to a cert file for the certificate authority | ||
- | root@kubemaster: | + | |
- | | + | Path to a client certificate file for TLS |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | --Plus-- | + | |
- | [q] | + | |
- | </ | + | |
- | <WRAP center round important 60%> | + | |
- | **Important** : Notez que la version la plus récente est la **1.25.0-00**. | + | Path to a client key file for TLS |
- | </ | + | |
- | Procédez maintenant à la mise-à-jour de kubeadm | + | |
+ | The name of the kubeconfig cluster to use | ||
- | < | + | |
- | root@kubemaster: | + | The name of the kubeconfig context to use |
- | Atteint:1 http:// | + | |
- | Ign:2 http:// | + | |
- | Atteint:3 http:// | + | |
- | Atteint:4 http:// | + | |
- | Réception de:5 https:// | + | |
- | Atteint:6 https:// | + | |
- | 44,8 ko réceptionnés en 0s (80,5 ko/s) | + | |
- | Lecture des listes de paquets... Fait | + | |
- | Lecture des listes de paquets... Fait | + | |
- | Construction de l'arbre des dépendances | + | |
- | Lecture des informations d'état... Fait | + | |
- | Les paquets suivants ont été installés automatiquement et ne sont plus nécessaires | + | |
- | | + | |
- | Veuillez utiliser « apt autoremove » pour les supprimer. | + | |
- | Les paquets retenus suivants seront changés : | + | |
- | kubeadm | + | |
- | Les paquets suivants seront mis à jour : | + | |
- | kubeadm | + | |
- | 1 mis à jour, 0 nouvellement installés, 0 à enlever et 5 non mis à jour. | + | |
- | Il est nécessaire de prendre 9 213 ko dans les archives. | + | |
- | Après cette opération, 586 ko d' | + | |
- | Réception de:1 https:// | + | |
- | 9 213 ko réceptionnés en 0s (15,3 Mo/s) | + | |
- | apt-listchanges : Lecture des fichiers de modifications (« changelog »)... | + | |
- | (Lecture de la base de données... 137041 fichiers et répertoires déjà installés.) | + | |
- | Préparation du dépaquetage de .../ | + | |
- | Dépaquetage de kubeadm (1.25.0-00) sur (1.24.2-00) ... | + | |
- | Paramétrage de kubeadm (1.25.0-00) ... | + | |
- | </ | + | |
- | <WRAP center round important 60%> | + | |
- | **Important** : Notez que l' | + | If true, the server' |
- | </ | + | |
- | Vérifiez que la version désirée a été installée | + | --kubeconfig='' |
+ | Path to the kubeconfig file to use for CLI requests. | ||
- | < | + | --log-backtrace-at=:0: |
- | root@kubemaster: | + | when logging hits line file:N, emit a stack trace (DEPRECATED: will be removed in a future release, see |
- | kubeadm version: & | + | https://github.com/ |
- | </code> | + | |
- | Afin de connaître les version des composants du Control Plane compatibles avec la version 1.25.0 de kubeadm, utilisez la commande **kubeadm upgrade plan** | + | --log-dir='': |
+ | If non-empty, write log files in this directory (no effect when -logtostderr=true) (DEPRECATED: will be | ||
+ | removed in a future release, see | ||
+ | https:// | ||
- | < | + | --log-file='': |
- | root@kubemaster:~# kubeadm upgrade plan | + | If non-empty, use this log file (no effect when -logtostderr=true) (DEPRECATED: will be removed in a future |
- | [upgrade/ | + | |
- | [upgrade/config] Reading configuration from the cluster... | + | https://github.com/ |
- | [upgrade/config] FYI: You can look at this config file with ' | + | |
- | [upload-config] Storing the configuration used in ConfigMap " | + | |
- | [preflight] Running pre-flight checks. | + | |
- | [upgrade] Running cluster health checks | + | |
- | [upgrade] Fetching available versions to upgrade to | + | |
- | [upgrade/ | + | |
- | [upgrade/ | + | |
- | [upgrade/ | + | |
- | [upgrade/ | + | |
- | Components that must be upgraded manually after you have upgraded the control plane with ' | + | --log-file-max-size=1800: |
- | COMPONENT | + | |
- | kubelet | + | value is 0, the maximum file size is unlimited. (DEPRECATED: |
+ | https:// | ||
- | Upgrade to the latest version in the v1.24 series: | + | --log-flush-frequency=5s: |
+ | Maximum number of seconds between log flushes | ||
- | COMPONENT | + | --logtostderr=true: |
- | kube-apiserver | + | log to standard error instead of files (DEPRECATED: |
- | kube-controller-manager | + | https:// |
- | kube-scheduler | + | |
- | kube-proxy v1.24.2 | + | |
- | CoreDNS | + | |
- | etcd 3.5.3-0 3.5.4-0 | + | |
- | You can now apply the upgrade by executing the following command: | + | --match-server-version=false: |
+ | Require server version to match client version | ||
- | kubeadm upgrade apply v1.24.4 | + | -n, --namespace='': |
+ | If present, the namespace scope for this CLI request | ||
- | _____________________________________________________________________ | + | --one-output=false: |
+ | If true, only write logs to their native severity level (vs also writing to each lower severity level; no | ||
+ | effect when -logtostderr=true) (DEPRECATED: | ||
+ | https:// | ||
- | Components that must be upgraded manually after you have upgraded the control plane with 'kubeadm upgrade apply': | + | --password='': |
- | COMPONENT | + | |
- | kubelet | + | |
- | Upgrade to the latest stable version: | + | --profile=' |
+ | Name of profile to capture. One of (none|cpu|heap|goroutine|threadcreate|block|mutex) | ||
- | COMPONENT | + | |
- | kube-apiserver | + | Name of the file to write the profile to |
- | kube-controller-manager | + | |
- | kube-scheduler | + | |
- | kube-proxy | + | |
- | CoreDNS | + | |
- | etcd 3.5.3-0 | + | |
- | You can now apply the upgrade by executing the following command: | + | --request-timeout=' |
+ | The length of time to wait before giving up on a single server request. Non-zero values should contain a | ||
+ | corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. | ||
- | kubeadm upgrade apply v1.25.0 | + | -s, --server='': |
+ | The address and port of the Kubernetes API server | ||
- | _____________________________________________________________________ | + | --skip-headers=false: |
+ | If true, avoid header prefixes in the log messages (DEPRECATED: | ||
+ | https:// | ||
+ | --skip-log-headers=false: | ||
+ | If true, avoid headers when opening log files (no effect when -logtostderr=true) (DEPRECATED: | ||
+ | in a future release, see | ||
+ | https:// | ||
- | The table below shows the current state of component configs as understood by this version of kubeadm. | + | --stderrthreshold=2: |
- | Configs that have a " | + | logs at or above this threshold go to stderr when writing |
- | resetting | + | |
- | upgrade to is denoted | + | https:// |
- | API GROUP | + | --tls-server-name='': |
- | kubeproxy.config.k8s.io | + | |
- | kubelet.config.k8s.io | + | |
- | _____________________________________________________________________ | + | |
- | </ | + | --token='': |
+ | Bearer token for authentication to the API server | ||
- | Procédez donc à la mise-à-jour de kubeadm vers la version **1.25.0** | + | |
+ | The name of the kubeconfig user to use | ||
- | < | + | |
- | root@kubemaster: | + | |
- | [upgrade/ | + | |
- | [upgrade/ | + | |
- | [upgrade/ | + | |
- | [preflight] Running pre-flight checks. | + | |
- | [upgrade] Running cluster health checks | + | |
- | [upgrade/ | + | |
- | [upgrade/ | + | |
- | [upgrade/ | + | |
- | [upgrade] Are you sure you want to proceed? [y/N]: y | + | |
- | </ | + | |
- | A l'issu de processus, vous verrez les deux lignes suivantes | + | -v, --v=0: |
+ | number for the log level verbosity | ||
- | < | + | --vmodule=: |
- | ... | + | |
- | [upgrade/ | + | |
- | [upgrade/ | + | --warnings-as-errors=false: |
- | root@kubemaster:~# | + | Treat warnings received from the server as errors and exit with a non-zero exit code |
</ | </ | ||
- | Mettez-à-jour maintenant **kubelet** | + | ====1.2 |
+ | |||
+ | ===La Commande version=== | ||
+ | |||
+ | Commencez par obtenir l' | ||
< | < | ||
- | root@kubemaster: | + | root@kubemaster: |
- | ... | + | Flag --short has been deprecated, and will be removed in the future. The --short output will become the default. |
+ | Client Version: v1.25.0 | ||
+ | Kustomize Version: v4.5.7 | ||
+ | Server Version: v1.25.0 | ||
</ | </ | ||
- | Au cas où le fichier du service de kubelet a subi des modifications, | + | ===La Commande cluster-info=== |
+ | |||
+ | Consultez ensuite les informations concernant | ||
< | < | ||
- | root@kubemaster: | + | root@kubemaster: |
+ | Kubernetes control plane is running at https:// | ||
+ | CoreDNS is running at https:// | ||
- | root@kubemaster: | + | To further debug and diagnose cluster problems, use ' |
</ | </ | ||
- | Annulez le drain de kubemaster | + | ===La Commande api-versions=== |
+ | |||
+ | Afin de connaître les versions des API compatibles avec la version de Kubernetes installée, exécutez la commande **api-versions** | ||
< | < | ||
- | root@kubemaster: | + | root@kubemaster: |
- | node/kubemaster.ittraining.loc uncordoned | + | admissionregistration.k8s.io/v1 |
+ | apiextensions.k8s.io/ | ||
+ | apiregistration.k8s.io/ | ||
+ | apps/v1 | ||
+ | authentication.k8s.io/ | ||
+ | authorization.k8s.io/ | ||
+ | autoscaling/ | ||
+ | autoscaling/ | ||
+ | autoscaling/ | ||
+ | batch/v1 | ||
+ | certificates.k8s.io/ | ||
+ | coordination.k8s.io/ | ||
+ | crd.projectcalico.org/ | ||
+ | discovery.k8s.io/ | ||
+ | events.k8s.io/ | ||
+ | flowcontrol.apiserver.k8s.io/ | ||
+ | flowcontrol.apiserver.k8s.io/ | ||
+ | networking.k8s.io/ | ||
+ | node.k8s.io/v1 | ||
+ | policy/v1 | ||
+ | rbac.authorization.k8s.io/v1 | ||
+ | scheduling.k8s.io/ | ||
+ | storage.k8s.io/ | ||
+ | storage.k8s.io/ | ||
+ | v1 | ||
</ | </ | ||
- | Constatez maintenant l' | + | ===La Commande api-resources=== |
+ | |||
+ | La commande **api-resources** permet de consulter la liste des ressources du cluster, à savoir | ||
+ | |||
+ | * le nom de la ressource - **NAME**, | ||
+ | * le nom court à utiliser avec kubectl - **SHORTNAMES**, | ||
+ | * le groupe API auquel la ressource appartient - **APIVERSION**, | ||
+ | * si oui ou non la ressource est liée à un namespace - **NAMESPACED**, | ||
+ | * le type KIND de la ressource - **KIND**. | ||
< | < | ||
- | root@kubemaster: | + | root@kubemaster: |
- | NAME | + | NAME |
- | kubemaster.ittraining.loc | + | bindings |
- | kubenode1.ittraining.loc Ready < | + | componentstatuses |
- | kubenode2.ittraining.loc Ready < | + | configmaps |
+ | endpoints | ||
+ | events | ||
+ | limitranges | ||
+ | namespaces | ||
+ | nodes | ||
+ | persistentvolumeclaims | ||
+ | persistentvolumes | ||
+ | pods po | ||
+ | podtemplates | ||
+ | replicationcontrollers | ||
+ | resourcequotas | ||
+ | secrets | ||
+ | serviceaccounts | ||
+ | services | ||
+ | mutatingwebhookconfigurations | ||
+ | validatingwebhookconfigurations | ||
+ | customresourcedefinitions | ||
+ | apiservices | ||
+ | controllerrevisions | ||
+ | daemonsets | ||
+ | deployments | ||
+ | replicasets | ||
+ | statefulsets | ||
+ | tokenreviews | ||
+ | localsubjectaccessreviews | ||
+ | selfsubjectaccessreviews | ||
+ | selfsubjectrulesreviews | ||
+ | subjectaccessreviews | ||
+ | horizontalpodautoscalers | ||
+ | cronjobs | ||
+ | jobs | ||
+ | certificatesigningrequests | ||
+ | leases | ||
+ | bgpconfigurations | ||
+ | bgppeers | ||
+ | blockaffinities | ||
+ | caliconodestatuses | ||
+ | clusterinformations | ||
+ | felixconfigurations | ||
+ | globalnetworkpolicies | ||
+ | globalnetworksets | ||
+ | hostendpoints | ||
+ | ipamblocks | ||
+ | ipamconfigs | ||
+ | ipamhandles | ||
+ | ippools | ||
+ | ipreservations | ||
+ | kubecontrollersconfigurations | ||
+ | networkpolicies | ||
+ | networksets | ||
+ | endpointslices | ||
+ | events | ||
+ | flowschemas | ||
+ | prioritylevelconfigurations | ||
+ | ingressclasses | ||
+ | ingresses | ||
+ | networkpolicies | ||
+ | runtimeclasses | ||
+ | poddisruptionbudgets | ||
+ | clusterrolebindings | ||
+ | clusterroles | ||
+ | rolebindings | ||
+ | roles rbac.authorization.k8s.io/ | ||
+ | priorityclasses | ||
+ | csidrivers | ||
+ | csinodes | ||
+ | csistoragecapacities | ||
+ | storageclasses | ||
+ | volumeattachments | ||
</ | </ | ||
- | <WRAP center round important 60%> | + | ====1.3 - Obtenir de l' |
- | **Important** : Notez que le Control Plane est à la version | + | |
- | </ | + | |
- | ====2.2 - Mise-à-jour des Travailleurs==== | + | ===La Commande describe node=== |
- | Afin de mettre | + | De l' |
+ | |||
+ | * la section **Labels: | ||
+ | * la ligne **Unschedulable: | ||
< | < | ||
- | root@kubemaster: | + | root@kubemaster: |
- | node/kubenode1.ittraining.loc cordoned | + | Name: |
- | Warning: ignoring DaemonSet-managed | + | Roles: |
- | evicting pod kube-system/ | + | Labels: |
- | evicting pod kube-system/ | + | beta.kubernetes.io/ |
- | pod/calico-kube-controllers-6799f5f4b4-6ng7z evicted | + | kubernetes.io/ |
- | pod/coredns-565d847f94-rh7vb evicted | + | kubernetes.io/ |
- | node/kubenode1.ittraining.loc drained | + | kubernetes.io/ |
+ | node-role.kubernetes.io/ | ||
+ | node.kubernetes.io/ | ||
+ | Annotations: | ||
+ | | ||
+ | projectcalico.org/ | ||
+ | | ||
+ | volumes.kubernetes.io/ | ||
+ | CreationTimestamp: | ||
+ | Taints: | ||
+ | Unschedulable: | ||
+ | Lease: | ||
+ | HolderIdentity: | ||
+ | AcquireTime: | ||
+ | RenewTime: | ||
+ | Conditions: | ||
+ | Type | ||
+ | | ||
+ | | ||
+ | MemoryPressure | ||
+ | DiskPressure | ||
+ | PIDPressure | ||
+ | Ready True Sun, 04 Sep 2022 16:52:48 +0200 Sun, 04 Sep 2022 12:15:32 +0200 | ||
+ | ... | ||
</ | </ | ||
- | Conectez-vous à kubenode1 | + | Dans la deuxième partie de la sortie, on peut constater |
+ | |||
+ | * la section **Addresses: | ||
< | < | ||
- | root@kubemaster:~# ssh -l trainee kubenode1 | + | ... |
- | trainee@kubenode1' | + | Addresses: |
- | Linux kubenode1.ittraining.loc 4.9.0-19-amd64 #1 SMP Debian | + | |
+ | | ||
+ | Capacity: | ||
+ | cpu: | ||
+ | ephemeral-storage: | ||
+ | hugepages-2Mi: 0 | ||
+ | memory: | ||
+ | pods: 110 | ||
+ | Allocatable: | ||
+ | cpu: | ||
+ | ephemeral-storage: | ||
+ | hugepages-2Mi: 0 | ||
+ | memory: | ||
+ | pods: 110 | ||
+ | ... | ||
+ | </ | ||
- | The programs included with the Debian GNU/Linux system are free software; | + | Dans la troisième partie de la sortie, on peut constater : |
- | the exact distribution terms for each program are described in the | + | |
- | individual files in / | + | |
- | Debian GNU/ | + | * la section **System Info:** contenant de l' |
- | permitted by applicable law. | + | * la section **Non-terminated Pods** contenant de l' |
- | Last login: Sun Sep | + | |
- | trainee@kubenode1:~$ su - | + | < |
- | Mot de passe : fenestros | + | ... |
- | root@kubenode1: | + | System Info: |
+ | Machine ID: | ||
+ | System UUID: 68639C3A-D77A-4C61-B7E8-4F4F70419B8A | ||
+ | Boot ID: 9bd56aa5-b94c-40d3-804a-a54bd8daf305 | ||
+ | Kernel Version: | ||
+ | OS Image: | ||
+ | | ||
+ | | ||
+ | Container Runtime Version: | ||
+ | Kubelet Version: | ||
+ | Kube-Proxy Version: | ||
+ | PodCIDR: 192.168.0.0/24 | ||
+ | PodCIDRs: 192.168.0.0/ | ||
+ | Non-terminated Pods: (7 in total) | ||
+ | | ||
+ | --------- | ||
+ | kube-system | ||
+ | kube-system | ||
+ | kube-system | ||
+ | kube-system | ||
+ | kube-system | ||
+ | kube-system | ||
+ | kube-system | ||
+ | ... | ||
</ | </ | ||
- | Mettez-à-jour le paquet | + | Dans la dernière partie de la sortie, on peut constater : |
+ | |||
+ | | ||
< | < | ||
- | root@kubenode1:~# apt-get update && apt-get install | + | Allocated resources: |
- | ... | + | (Total limits may be over 100 percent, i.e., overcommitted.) |
+ | Resource | ||
+ | | ||
+ | cpu | ||
+ | memory | ||
+ | ephemeral-storage | ||
+ | | ||
+ | Events: | ||
+ | Type Reason | ||
+ | ---- ------ | ||
+ | Normal | ||
</ | </ | ||
- | Mettez-à-jour la configuration de kubelet | + | ===La Commande top=== |
+ | |||
+ | La commande **top** nécessite | ||
< | < | ||
- | root@kubenode1:~# kubeadm upgrade node | + | root@kubemaster:~# wget https://github.com/ |
- | [upgrade] Reading configuration from the cluster... | + | |
- | [upgrade] FYI: You can look at this config file with ' | + | |
- | [preflight] Running pre-flight checks | + | |
- | [preflight] Skipping prepull. Not a control plane node. | + | |
- | [upgrade] Skipping phase. Not a control plane node. | + | |
- | [kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml" | + | |
- | [upgrade] The configuration for this node was successfully updated! | + | |
- | [upgrade] Now you should go ahead and upgrade the kubelet package using your package manager. | + | |
</ | </ | ||
- | Mettez-à-jour maintenant | + | Modifiez la section |
< | < | ||
- | root@kubenode1:~# apt-get update && apt-get install | + | root@kubemaster:~# vi components.yaml |
+ | root@kubemaster: | ||
+ | ... | ||
+ | spec: | ||
+ | containers: | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | - --kubelet-preferred-address-types=InternalIP, | ||
+ | - --kubelet-use-node-status-port | ||
... | ... | ||
</ | </ | ||
- | Au cas où le fichier du service de kubelet a subi des modifications, | + | Déployez |
< | < | ||
- | root@kubenode1:~# systemctl daemon-reload | + | root@kubemaster:~# kubectl apply -f components.yaml |
- | + | serviceaccount/ | |
- | root@kubenode1:~# systemctl restart kubelet | + | clusterrole.rbac.authorization.k8s.io/ |
+ | clusterrole.rbac.authorization.k8s.io/ | ||
+ | rolebinding.rbac.authorization.k8s.io/ | ||
+ | clusterrolebinding.rbac.authorization.k8s.io/ | ||
+ | clusterrolebinding.rbac.authorization.k8s.io/ | ||
+ | service/ | ||
+ | deployment.apps/ | ||
+ | apiservice.apiregistration.k8s.io/ | ||
</ | </ | ||
- | Retournez à la machine **kubemaster** | + | Vérifiez l' |
< | < | ||
- | root@kubenode1:~# exit | + | root@kubemaster:~# kubectl get deployments --all-namespaces |
- | déconnexion | + | NAMESPACE |
- | trainee@kubenode1: | + | default |
- | déconnexion | + | kube-system |
- | Connection to kubenode1 closed. | + | kube-system |
- | root@kubemaster: | + | kube-system |
</ | </ | ||
- | Annulez | + | Pour connaître l' |
< | < | ||
- | root@kubemaster: | + | root@kubemaster: |
- | node/kubenode1.ittraining.loc | + | NAME CPU(cores) |
+ | kubemaster.ittraining.loc | ||
+ | kubenode1.ittraining.loc | ||
+ | kubenode2.ittraining.loc | ||
</ | </ | ||
- | Constatez maintenant | + | Pour voir l'évolution de l' |
< | < | ||
- | root@kubemaster: | + | root@kubemaster: |
- | NAME STATUS | + | Every 2,0s: kubectl top nodes |
- | kubemaster.ittraining.loc | + | |
- | kubenode1.ittraining.loc | + | NAME CPU(cores) |
- | kubenode2.ittraining.loc | + | kubemaster.ittraining.loc |
+ | kubenode1.ittraining.loc | ||
+ | kubenode2.ittraining.loc | ||
+ | ... | ||
+ | ^C | ||
+ | root@kubemaster: | ||
</ | </ | ||
<WRAP center round important 60%> | <WRAP center round important 60%> | ||
- | **Important** : Notez que le Control Plane et kubenode1 sont à la version 1.25.0 tandis que kubenode2 est à la version 1.24.2. | + | **Important** : Notez l' |
</ | </ | ||
- | Faites un drain du kubenode2 | + | Il est possible de trier la sortie par ordre décroissant de l' |
< | < | ||
- | root@kubemaster: | + | root@kubemaster: |
- | node/ | + | NAME CPU(cores) |
- | Warning: ignoring DaemonSet-managed Pods: kube-system/ | + | kubemaster.ittraining.loc |
- | evicting pod kube-system/ | + | kubenode1.ittraining.loc |
- | evicting pod default/ | + | kubenode2.ittraining.loc |
- | evicting pod default/ | + | |
- | evicting pod default/ | + | |
- | evicting pod kube-system/ | + | |
- | pod/ | + | |
- | pod/ | + | |
- | pod/ | + | |
- | pod/ | + | |
- | pod/ | + | |
- | node/kubenode2.ittraining.loc | + | |
</ | </ | ||
- | Connectez-vous à kubenode2 | + | Dernièrement, |
< | < | ||
- | root@kubemaster: | + | root@kubemaster: |
- | The authenticity of host ' | + | NAME CPU(cores) CPU% |
- | ECDSA key fingerprint is SHA256: | + | kubemaster.ittraining.loc |
- | Are you sure you want to continue connecting | + | kubenode1.ittraining.loc 70m 1% |
- | Warning: Permanently added ' | + | kubenode2.ittraining.loc |
- | trainee@kubenode2' | + | </ |
- | Linux kubenode2.ittraining.loc | + | |
- | The programs included with the Debian GNU/Linux system are free software; | + | ====1.4 - Obtenir de l' |
- | the exact distribution terms for each program are described in the | + | |
- | individual files in / | + | |
- | Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent | + | ===La Commande describe pod=== |
- | permitted by applicable law. | + | |
- | Last login: Sun Sep 4 09:42:58 2022 from 192.168.56.1 | + | Tout comme avec les noeuds, des informations concernant un pod spécifique peuvent être obtenues en utilisant la commande **kubectl describe** : |
- | trainee@kubenode2:~$ su - | + | |
- | Mot de passe : fenestros | + | < |
- | root@kubenode2:~# | + | root@kubemaster: |
+ | Name: | ||
+ | Namespace: | ||
+ | Priority: | ||
+ | Service Account: | ||
+ | Node: | ||
+ | Start Time: | ||
+ | Labels: | ||
+ | pod-template-hash=689f9d59 | ||
+ | type=front-end | ||
+ | Annotations: | ||
+ | cni.projectcalico.org/ | ||
+ | | ||
+ | Status: | ||
+ | IP: | ||
+ | IPs: | ||
+ | IP: | ||
+ | Controlled By: ReplicaSet/ | ||
+ | Containers: | ||
+ | nginx-container: | ||
+ | Container ID: | ||
+ | Image: | ||
+ | Image ID: | ||
+ | Port: < | ||
+ | Host Port: < | ||
+ | State: | ||
+ | Started: | ||
+ | Ready: | ||
+ | Restart Count: | ||
+ | Environment: | ||
+ | Mounts: | ||
+ | / | ||
+ | Conditions: | ||
+ | | ||
+ | Initialized | ||
+ | Ready True | ||
+ | ContainersReady | ||
+ | PodScheduled | ||
+ | Volumes: | ||
+ | kube-api-access-fjdsw: | ||
+ | Type: Projected (a volume that contains injected data from multiple sources) | ||
+ | TokenExpirationSeconds: | ||
+ | ConfigMapName: | ||
+ | ConfigMapOptional: < | ||
+ | DownwardAPI: | ||
+ | QoS Class: | ||
+ | Node-Selectors: | ||
+ | Tolerations: | ||
+ | | ||
+ | Events: | ||
</ | </ | ||
- | Mettez-à-jour le paquet **kubeadm** | + | ===La Commande top=== |
+ | |||
+ | Il est possible de voir l' | ||
< | < | ||
- | root@kubenode2:~# apt-get update && apt-get install | + | root@kubemaster:~# kubectl top pods |
- | ... | + | NAME CPU(cores) |
+ | myapp-deployment-689f9d59-c25f9 | ||
+ | myapp-deployment-689f9d59-nn9sw | ||
+ | myapp-deployment-689f9d59-rnc4r | ||
</ | </ | ||
- | Mettez-à-jour | + | Triez maintenant |
< | < | ||
- | root@kubenode2:~# kubeadm upgrade node | + | root@kubemaster:~# kubectl |
- | [upgrade] Reading configuration from the cluster... | + | NAME CPU(cores) |
- | [upgrade] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -o yaml' | + | myapp-deployment-689f9d59-c25f9 |
- | [preflight] Running pre-flight checks | + | myapp-deployment-689f9d59-nn9sw |
- | [preflight] Skipping prepull. Not a control plane node. | + | myapp-deployment-689f9d59-rnc4r |
- | [upgrade] Skipping phase. Not a control plane node. | + | |
- | [kubelet-start] Writing kubelet configuration to file "/ | + | |
- | [upgrade] The configuration for this node was successfully updated! | + | |
- | [upgrade] Now you should go ahead and upgrade the kubelet package using your package manager. | + | |
</ | </ | ||
- | Mettez-à-jour | + | Triez maintenant |
< | < | ||
- | root@kubenode2:~# apt-get update && apt-get install | + | root@kubemaster:~# kubectl top pods --sort-by memory |
- | ... | + | NAME CPU(cores) |
+ | myapp-deployment-689f9d59-nn9sw | ||
+ | myapp-deployment-689f9d59-rnc4r | ||
+ | myapp-deployment-689f9d59-c25f9 | ||
</ | </ | ||
- | Au cas où le fichier | + | ====1.5 - Travailler avec la commande kubectl==== |
+ | |||
+ | Créez | ||
< | < | ||
- | root@kubenode2:~# systemctl daemon-reload | + | root@kubemaster:~# vi pod.yaml |
+ | root@kubemaster: | ||
+ | apiVersion: v1 | ||
+ | kind: Pod | ||
+ | metadata: | ||
+ | name: my-pod | ||
+ | spec: | ||
+ | containers: | ||
+ | - name: busybox | ||
+ | image: radial/ | ||
+ | command: [' | ||
+ | </ | ||
- | root@kubenode2:~# systemctl restart kubelet | + | ====La Commande apply==== |
+ | |||
+ | Créez maintenant le pod en utilisant le fichier **pod.yaml** : | ||
+ | |||
+ | < | ||
+ | root@kubemaster:~# kubectl apply -f pod.yaml | ||
+ | pod/my-pod created | ||
</ | </ | ||
- | Retournez à la machine | + | ====La Commande create==== |
+ | |||
+ | La commande | ||
< | < | ||
- | root@kubenode2:~# exit | + | root@kubemaster:~# kubectl create -f pod.yaml |
- | déconnexion | + | Error from server (AlreadyExists): error when creating "pod.yaml": pods " |
- | trainee@kubenode2:~$ exit | + | |
- | déconnexion | + | |
- | Connection to kubenode2 closed. | + | |
- | root@kubemaster:~# | + | |
</ | </ | ||
- | Annulez le drain de kubenode1 | + | Pour consulter la liste des objets qui peuvent être créés, utilisez la commande **kubectl create** |
< | < | ||
- | root@kubemaster: | + | root@kubemaster: |
- | node/kubenode2.ittraining.loc uncordoned | + | Error: must specify one of -f and -k |
+ | |||
+ | Create a resource from a file or from stdin. | ||
+ | |||
+ | JSON and YAML formats are accepted. | ||
+ | |||
+ | Examples: | ||
+ | # Create a pod using the data in pod.json | ||
+ | kubectl create -f ./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 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 " | ||
</ | </ | ||
- | Constatez maintenant l' | + | La commande **apply** est ensuite utilisée pour appliquer |
< | < | ||
- | root@kubemaster: | + | root@kubemaster: |
- | NAME STATUS | + | pod/my-pod unchanged |
- | kubemaster.ittraining.loc | + | |
- | kubenode1.ittraining.loc | + | |
- | kubenode2.ittraining.loc | + | |
</ | </ | ||
- | <WRAP center round important 60%> | + | ====La Commande get==== |
- | **Important** : Notez que tout a été mis-à-jour. | + | |
- | </ | + | |
- | =====LAB #3 - Gestion de la Sauvegarde===== | + | Constatez le statut du pod : |
< | < | ||
+ | root@kubemaster: | ||
+ | NAME READY | ||
+ | my-pod | ||
+ | myapp-deployment-689f9d59-c25f9 | ||
+ | myapp-deployment-689f9d59-nn9sw | ||
+ | myapp-deployment-689f9d59-rnc4r | ||
+ | </ | ||
+ | Rappelez-vous que vous pouvez utiliser une abréviation pour pods : | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | NAME READY | ||
+ | my-pod | ||
+ | myapp-deployment-689f9d59-c25f9 | ||
+ | myapp-deployment-689f9d59-nn9sw | ||
+ | myapp-deployment-689f9d59-rnc4r | ||
</ | </ | ||
+ | |||
+ | Pour ne voir qu'un seul pod, il convient de préciser son nom en tant qu' | ||
< | < | ||
+ | root@kubemaster: | ||
+ | NAME | ||
+ | my-pod | ||
+ | </ | ||
+ | ====Utilisation des Options==== | ||
+ | |||
+ | Rappelez-vous que l' | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | NAME READY | ||
+ | my-pod | ||
+ | myapp-deployment-689f9d59-c25f9 | ||
+ | myapp-deployment-689f9d59-nn9sw | ||
+ | myapp-deployment-689f9d59-rnc4r | ||
</ | </ | ||
+ | |||
+ | L' | ||
< | < | ||
+ | root@kubemaster: | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | ": | ||
+ | "while true; do sleep 3600; done\" | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | "while true; do sleep 3600; done" | ||
+ | ], | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | --More-- | ||
+ | </ | ||
+ | L' | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | apiVersion: v1 | ||
+ | items: | ||
+ | - apiVersion: v1 | ||
+ | kind: Pod | ||
+ | metadata: | ||
+ | annotations: | ||
+ | cni.projectcalico.org/ | ||
+ | cni.projectcalico.org/ | ||
+ | cni.projectcalico.org/ | ||
+ | kubectl.kubernetes.io/ | ||
+ | {" | ||
+ | ers": | ||
+ | creationTimestamp: | ||
+ | name: my-pod | ||
+ | namespace: default | ||
+ | resourceVersion: | ||
+ | uid: 628ca9e4-2fbe-4fc9-b0fa-9a05ef942a07 | ||
+ | spec: | ||
+ | containers: | ||
+ | - command: | ||
+ | - sh | ||
+ | - -c | ||
+ | - while true; do sleep 3600; done | ||
+ | image: radial/ | ||
+ | imagePullPolicy: | ||
+ | name: busybox | ||
+ | resources: {} | ||
+ | terminationMessagePath: | ||
+ | terminationMessagePolicy: | ||
+ | volumeMounts: | ||
+ | - mountPath: / | ||
+ | name: kube-api-access-qwzzv | ||
+ | readOnly: true | ||
+ | dnsPolicy: ClusterFirst | ||
+ | enableServiceLinks: | ||
+ | nodeName: kubenode2.ittraining.loc | ||
+ | preemptionPolicy: | ||
+ | priority: 0 | ||
+ | restartPolicy: | ||
+ | --More-- | ||
</ | </ | ||
+ | |||
+ | L' | ||
< | < | ||
+ | root@kubemaster: | ||
+ | NAME READY | ||
+ | myapp-deployment-689f9d59-c25f9 | ||
+ | myapp-deployment-689f9d59-nn9sw | ||
+ | myapp-deployment-689f9d59-rnc4r | ||
+ | my-pod | ||
+ | </ | ||
+ | L' | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | NAME READY | ||
+ | calico-node-5htrc | ||
+ | calico-node-dc7hd | ||
+ | calico-node-qk5kt | ||
</ | </ | ||
+ | |||
+ | ====La Commande exec==== | ||
+ | |||
+ | La commande **exec** permet d' | ||
< | < | ||
+ | root@kubemaster: | ||
+ | Hello, world! | ||
+ | </ | ||
+ | <WRAP center round important 60%> | ||
+ | **Important** : Notez l' | ||
+ | </ | ||
+ | |||
+ | |||
+ | ====5.6 - Commandes Impératives ==== | ||
+ | |||
+ | Avant de poursuivre, supprimez le pod **my-pod** : | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | pod " | ||
</ | </ | ||
+ | |||
+ | Créez ensuite un deployment avec une commande impérative : | ||
< | < | ||
+ | root@kubemaster: | ||
+ | deployment.apps/ | ||
+ | </ | ||
+ | En exécutant la même commande impérative, | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | W0910 15: | ||
+ | apiVersion: apps/v1 | ||
+ | kind: Deployment | ||
+ | metadata: | ||
+ | creationTimestamp: | ||
+ | labels: | ||
+ | app: my-deployment | ||
+ | name: my-deployment | ||
+ | spec: | ||
+ | replicas: 1 | ||
+ | selector: | ||
+ | matchLabels: | ||
+ | app: my-deployment | ||
+ | strategy: {} | ||
+ | template: | ||
+ | metadata: | ||
+ | creationTimestamp: | ||
+ | labels: | ||
+ | app: my-deployment | ||
+ | spec: | ||
+ | containers: | ||
+ | - image: nginx | ||
+ | name: nginx | ||
+ | resources: {} | ||
+ | status: {} | ||
</ | </ | ||
+ | |||
+ | Ces instructions peuvent ensuite être injectées dans un fichier afin d' | ||
< | < | ||
+ | root@kubemaster: | ||
+ | W0910 15: | ||
+ | </ | ||
+ | < | ||
+ | root@kubemaster: | ||
+ | apiVersion: apps/v1 | ||
+ | kind: Deployment | ||
+ | metadata: | ||
+ | creationTimestamp: | ||
+ | labels: | ||
+ | app: my-deployment | ||
+ | name: my-deployment | ||
+ | spec: | ||
+ | replicas: 1 | ||
+ | selector: | ||
+ | matchLabels: | ||
+ | app: my-deployment | ||
+ | strategy: {} | ||
+ | template: | ||
+ | metadata: | ||
+ | creationTimestamp: | ||
+ | labels: | ||
+ | app: my-deployment | ||
+ | spec: | ||
+ | containers: | ||
+ | - image: nginx | ||
+ | name: nginx | ||
+ | resources: {} | ||
+ | status: {} | ||
</ | </ | ||
+ | |||
+ | =====LAB #2 - Géstion les plugins de kubectl avec la Commande krew===== | ||
+ | |||
+ | Les plugins de kubectl étendent ses fonctionnalités. Le gestionnaire des plugins **krew** est disponible pour macOS(tm), Windows(tm) et Linux. Un plugin est un simple exécutable écrit, par exemple, en **bash** ou en **Go**. | ||
+ | |||
+ | ====2.1 - Installation de krew==== | ||
+ | |||
+ | Afin d' | ||
< | < | ||
+ | root@kubemaster: | ||
+ | </ | ||
+ | Installez ensuite krew avec la commande suivante : | ||
+ | |||
+ | < | ||
+ | ( | ||
+ | set -x; cd " | ||
+ | curl -fsSLO " | ||
+ | tar zxvf krew-linux_amd64.tar.gz && | ||
+ | KREW=./ | ||
+ | " | ||
+ | ) | ||
+ | </ | ||
+ | |||
+ | Vous obtiendrez : | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | > set -x; cd " | ||
+ | > curl -fsSLO " | ||
+ | > tar zxvf krew-linux_amd64.tar.gz && | ||
+ | > | ||
+ | > " | ||
+ | > ) | ||
+ | ++ mktemp -d | ||
+ | + cd / | ||
+ | + curl -fsSLO https:// | ||
+ | + tar zxvf krew-linux_amd64.tar.gz | ||
+ | ./LICENSE | ||
+ | ./ | ||
+ | ++ uname | ||
+ | ++ tr ' | ||
+ | ++ uname -m | ||
+ | ++ sed -e s/ | ||
+ | + KREW=./ | ||
+ | + ./ | ||
+ | Adding " | ||
+ | Updated the local copy of plugin index. | ||
+ | Installing plugin: krew | ||
+ | Installed plugin: krew | ||
+ | \ | ||
+ | | Use this plugin: | ||
+ | | ||
+ | | Documentation: | ||
+ | | ||
+ | | Caveats: | ||
+ | | \ | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | / | ||
+ | / | ||
</ | </ | ||
+ | |||
+ | Ensuite ajoutez **$HOME/ | ||
< | < | ||
+ | root@kubemaster: | ||
+ | </ | ||
+ | Afin de ne pas avoir besoin de redéfinir le PATH après chaque ouverture de session, ajoutez la ligne à la fin du fichier **.bashrc** : | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
</ | </ | ||
+ | |||
+ | ====2.2 - Consultation de la liste des plugins ==== | ||
+ | |||
+ | Mettez à jour la liste des plugins : | ||
< | < | ||
+ | root@kubemaster: | ||
+ | Updated the local copy of plugin index. | ||
+ | </ | ||
+ | Pour visualiser la liste des plugins, utiisez la commande **search** : | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | NAME DESCRIPTION | ||
+ | access-matrix | ||
+ | accurate | ||
+ | advise-policy | ||
+ | advise-psp | ||
+ | allctx | ||
+ | apparmor-manager | ||
+ | assert | ||
+ | auth-proxy | ||
+ | aws-auth | ||
+ | azad-proxy | ||
+ | bd-xray | ||
+ | blame Show who edited resource fields. | ||
+ | bulk-action | ||
+ | ca-cert | ||
+ | capture | ||
+ | cert-manager | ||
+ | change-ns | ||
+ | cilium | ||
+ | cluster-group | ||
+ | clusternet | ||
+ | cm Provides commands for OCM/ | ||
+ | cnpg Manage your CloudNativePG clusters | ||
+ | config-cleanup | ||
+ | config-registry | ||
+ | cost View cluster cost information | ||
+ | creyaml | ||
+ | ctx | ||
+ | custom-cols | ||
+ | cyclonus | ||
+ | datadog | ||
+ | datree | ||
+ | dds | ||
+ | debug-shell | ||
+ | deprecations | ||
+ | df-pv Show disk usage (like unix df) for persistent v... no | ||
+ | direct-csi | ||
+ | directpv | ||
+ | doctor | ||
+ | dtlogin | ||
+ | duck List custom resources with ducktype support | ||
+ | edit-status | ||
+ | eds | ||
+ | eksporter | ||
+ | emit-event | ||
+ | evict-pod | ||
+ | example | ||
+ | exec-as | ||
+ | exec-cronjob | ||
+ | explore | ||
+ | fields | ||
+ | flame | ||
+ | fleet Shows config and resources of a fleet of clusters | ||
+ | flyte | ||
+ | fuzzy Fuzzy and partial string search for kubectl | ||
+ | gadget | ||
+ | get-all | ||
+ | gke-credentials | ||
+ | gopass | ||
+ | graph | ||
+ | grep Filter Kubernetes resources by matching their n... no | ||
+ | gs Handle custom resources with Giant Swarm no | ||
+ | hlf | ||
+ | hns | ||
+ | htpasswd | ||
+ | ice View configuration settings of containers insid... | ||
+ | iexec | ||
+ | images | ||
+ | ingress-nginx | ||
+ | ingress-rule | ||
+ | ipick A kubectl wrapper for interactive resource sele... | ||
+ | istiolog | ||
+ | janitor | ||
+ | kadalu | ||
+ | karbon | ||
+ | karmada | ||
+ | konfig | ||
+ | krew Package manager for kubectl plugins. | ||
+ | kruise | ||
+ | ks Simple management of KubeSphere components | ||
+ | ktop A top tool to display workload metrics | ||
+ | kubesec-scan | ||
+ | kudo Declaratively build, install, and run operators... | ||
+ | kuota-calc | ||
+ | kurt Find what's restarting and why no | ||
+ | kuttl | ||
+ | kyverno | ||
+ | lineage | ||
+ | linstor | ||
+ | liqo Install and manage Liqo on your clusters | ||
+ | log2rbac | ||
+ | match-name | ||
+ | mc Run kubectl commands against multiple clusters ... no | ||
+ | minio | ||
+ | moco Interact with MySQL operator MOCO. no | ||
+ | modify-secret | ||
+ | mtail Tail logs from multiple pods matching label sel... | ||
+ | multiforward | ||
+ | multinet | ||
+ | neat Remove clutter from Kubernetes manifests to mak... | ||
+ | net-forward | ||
+ | node-admin | ||
+ | node-restart | ||
+ | node-shell | ||
+ | np-viewer | ||
+ | ns Switch between Kubernetes namespaces | ||
+ | nsenter | ||
+ | oidc-login | ||
+ | open-svc | ||
+ | openebs | ||
+ | operator | ||
+ | oulogin | ||
+ | outdated | ||
+ | passman | ||
+ | pexec | ||
+ | pod-dive | ||
+ | pod-inspect | ||
+ | pod-lens | ||
+ | pod-logs | ||
+ | pod-shell | ||
+ | podevents | ||
+ | popeye | ||
+ | preflight | ||
+ | print-env | ||
+ | profefe | ||
+ | promdump | ||
+ | prompt | ||
+ | prune-unused | ||
+ | psp-util | ||
+ | pv-migrate | ||
+ | pvmigrate | ||
+ | rabbitmq | ||
+ | rbac-lookup | ||
+ | rbac-tool | ||
+ | rbac-view | ||
+ | realname-diff | ||
+ | reap Delete unused Kubernetes resources. | ||
+ | relay | ||
+ | reliably | ||
+ | rename-pvc | ||
+ | resource-capacity | ||
+ | resource-snapshot | ||
+ | resource-versions | ||
+ | restart | ||
+ | rm-standalone-pods | ||
+ | rolesum | ||
+ | roll Rolling restart of all persistent pods in a nam... | ||
+ | rook-ceph | ||
+ | safe Prompts before running edit commands | ||
+ | schemahero | ||
+ | score | ||
+ | secretdata | ||
+ | service-tree | ||
+ | shovel | ||
+ | sick-pods | ||
+ | skew Find if your cluster/ | ||
+ | slice Split a multi-YAML file into individual files. | ||
+ | snap Delete half of the pods in a namespace or cluster | ||
+ | sniff Start a remote packet capture on pods using tcp... | ||
+ | socks5-proxy | ||
+ | sort-manifests | ||
+ | split-yaml | ||
+ | spy pod debugging tool for kubernetes clusters with... | ||
+ | sql Query the cluster via pseudo-SQL | ||
+ | ssh-jump | ||
+ | sshd Run SSH server in a Pod no | ||
+ | ssm-secret | ||
+ | starboard | ||
+ | status | ||
+ | stern Multi pod and container log tailing | ||
+ | strace | ||
+ | sudo Run Kubernetes commands impersonated as group s... no | ||
+ | support-bundle | ||
+ | switch-config | ||
+ | tail Stream logs from multiple pods and containers u... no | ||
+ | tap | ||
+ | tmux-exec | ||
+ | topology | ||
+ | trace Trace Kubernetes pods and nodes with system tools no | ||
+ | tree Show a tree of object hierarchies through owner... | ||
+ | tunnel | ||
+ | unused-volumes | ||
+ | vela Easily interact with KubeVela | ||
+ | view-allocations | ||
+ | view-cert | ||
+ | view-secret | ||
+ | view-serviceaccount-kubeconfig | ||
+ | view-utilization | ||
+ | view-webhook | ||
+ | viewnode | ||
+ | virt Control KubeVirt virtual machines using virtctl | ||
+ | volsync | ||
+ | vpa-recommendation | ||
+ | warp Sync and execute local files in Pod no | ||
+ | whisper-secret | ||
+ | who-can | ||
+ | whoami | ||
</ | </ | ||
+ | |||
+ | ====2.3 - Installation et utilisation de plugins==== | ||
+ | |||
+ | Installez les plugins **ctx**, **ns**, **view-allocations** et **pod-logs** : | ||
< | < | ||
+ | root@kubemaster: | ||
+ | Updated the local copy of plugin index. | ||
+ | Installing plugin: ctx | ||
+ | Installed plugin: ctx | ||
+ | \ | ||
+ | | Use this plugin: | ||
+ | | ||
+ | | Documentation: | ||
+ | | ||
+ | | Caveats: | ||
+ | | \ | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | / | ||
+ | / | ||
+ | WARNING: You installed plugin " | ||
+ | These plugins are not audited for security by the Krew maintainers. | ||
+ | Run them at your own risk. | ||
+ | Installing plugin: ns | ||
+ | Installed plugin: ns | ||
+ | \ | ||
+ | | Use this plugin: | ||
+ | | ||
+ | | Documentation: | ||
+ | | ||
+ | | Caveats: | ||
+ | | \ | ||
+ | | ||
+ | | ||
+ | | ||
+ | | / | ||
+ | / | ||
+ | WARNING: You installed plugin " | ||
+ | These plugins are not audited for security by the Krew maintainers. | ||
+ | Run them at your own risk. | ||
+ | Installing plugin: view-allocations | ||
+ | Installed plugin: view-allocations | ||
+ | \ | ||
+ | | Use this plugin: | ||
+ | | ||
+ | | Documentation: | ||
+ | | ||
+ | / | ||
+ | WARNING: You installed plugin " | ||
+ | These plugins are not audited for security by the Krew maintainers. | ||
+ | Run them at your own risk. | ||
+ | Installing plugin: pod-logs | ||
+ | Installed plugin: pod-logs | ||
+ | \ | ||
+ | | Use this plugin: | ||
+ | | ||
+ | | Documentation: | ||
+ | | ||
+ | / | ||
+ | WARNING: You installed plugin " | ||
+ | These plugins are not audited for security by the Krew maintainers. | ||
+ | Run them at your own risk. | ||
+ | </ | ||
+ | Le plugin **ctx** permet de basculer entre les **contextes** facilement. Un contexte est un élément qui regroupe les paramètres d' | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | kubernetes-admin@kubernetes | ||
</ | </ | ||
+ | |||
+ | Le plugin **ns** permet de basculer entre les **namespaces** facilement. | ||
+ | |||
+ | Les Namespaces : | ||
+ | |||
+ | * peuvent être considérées comme des clusters virtuels, | ||
+ | * permettent l' | ||
+ | * permettent le regroupement d' | ||
+ | * sont utilisés avec des applications, | ||
+ | |||
+ | Listez les namespaces dans le cluster : | ||
< | < | ||
+ | root@kubemaster: | ||
+ | default | ||
+ | kube-node-lease | ||
+ | kube-public | ||
+ | kube-system | ||
+ | </ | ||
+ | Le plugin **view-allocations** permet de visualiser les allocations de ressources telles le CPU, la mémoire, le stockage etc : | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | | ||
+ | cpu (13%) 1.6 __ | ||
+ | ├─ kubemaster.ittraining.loc | ||
+ | │ ├─ calico-node-688lw | ||
+ | │ ├─ coredns-6d4b75cb6d-dw4ph | ||
+ | │ ├─ coredns-6d4b75cb6d-ms2jm | ||
+ | │ ├─ etcd-kubemaster.ittraining.loc | ||
+ | │ ├─ kube-apiserver-kubemaster.ittraining.loc | ||
+ | │ ├─ kube-controller-manager-kubemaster.ittraining.loc | ||
+ | │ └─ kube-scheduler-kubemaster.ittraining.loc | ||
+ | ├─ kubenode1.ittraining.loc | ||
+ | │ └─ calico-node-5mrjl | ||
+ | └─ kubenode2.ittraining.loc | ||
+ | | ||
+ | ephemeral-storage | ||
+ | ├─ kubemaster.ittraining.loc | ||
+ | ├─ kubenode1.ittraining.loc | ||
+ | └─ kubenode2.ittraining.loc | ||
+ | memory | ||
+ | ├─ kubemaster.ittraining.loc | ||
+ | │ ├─ coredns-6d4b75cb6d-dw4ph | ||
+ | │ ├─ coredns-6d4b75cb6d-ms2jm | ||
+ | │ └─ etcd-kubemaster.ittraining.loc | ||
+ | ├─ kubenode1.ittraining.loc | ||
+ | └─ kubenode2.ittraining.loc | ||
+ | pods (5%) 17.0 (5%) 17.0 330.0 313.0 | ||
+ | ├─ kubemaster.ittraining.loc | ||
+ | ├─ kubenode1.ittraining.loc | ||
+ | └─ kubenode2.ittraining.loc | ||
</ | </ | ||
+ | |||
+ | Le plugin **pod-logs** vous fourni avec une liste de pods en cours d' | ||
< | < | ||
+ | root@kubemaster: | ||
+ | 1) | ||
+ | 2) | ||
+ | 3) | ||
+ | 4) | ||
+ | 5) | ||
+ | 6) | ||
+ | 7) | ||
+ | 8) | ||
+ | 9) | ||
+ | 10) etcd-kubemaster.ittraining.loc | ||
+ | 11) kube-apiserver-kubemaster.ittraining.loc | ||
+ | 12) kube-controller-manager-kubemaster.ittraining.loc | ||
+ | 13) kube-proxy-bwctz | ||
+ | 14) kube-proxy-j89vg | ||
+ | 15) kube-proxy-jx76x | ||
+ | 16) kube-scheduler-kubemaster.ittraining.loc | ||
+ | 17) metrics-server-7cb867d5dc-g55k5 | ||
+ | Select a Pod: | ||
+ | </ | ||
+ | Choisissez le pod **17**. Vous verrez la sortie de la commande logs : | ||
+ | |||
+ | < | ||
+ | Select a Pod: 17 | ||
+ | I0713 03: | ||
+ | I0713 03: | ||
+ | I0713 03: | ||
+ | I0713 03: | ||
+ | I0713 03: | ||
+ | I0713 03: | ||
+ | I0713 03: | ||
+ | I0713 03: | ||
+ | I0713 03: | ||
+ | I0713 03: | ||
+ | I0713 03: | ||
+ | I0713 03: | ||
+ | I0713 03: | ||
</ | </ | ||
+ | |||
+ | Pour lister les plugins installés, utilisez la commande **list** : | ||
< | < | ||
+ | root@kubemaster: | ||
+ | PLUGIN | ||
+ | ctx | ||
+ | krew v0.4.3 | ||
+ | ns v0.9.4 | ||
+ | pod-logs | ||
+ | view-allocations | ||
+ | </ | ||
+ | ====2.4 - Mise à jour et suppression de plugins==== | ||
+ | |||
+ | Pour mettre à jour les plugins installés, utilisez la commande **upgrade** : | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | Updated the local copy of plugin index. | ||
+ | Upgrading plugin: ctx | ||
+ | Skipping plugin ctx, it is already on the newest version | ||
+ | Upgrading plugin: krew | ||
+ | Skipping plugin krew, it is already on the newest version | ||
+ | Upgrading plugin: ns | ||
+ | Skipping plugin ns, it is already on the newest version | ||
+ | Upgrading plugin: pod-logs | ||
+ | Skipping plugin pod-logs, it is already on the newest version | ||
+ | Upgrading plugin: view-allocations | ||
+ | Skipping plugin view-allocations, | ||
</ | </ | ||
+ | |||
+ | Pour supprimer un plugin, utilisez la commande **remove** : | ||
< | < | ||
+ | root@kubemaster: | ||
+ | Uninstalled plugin: pod-logs | ||
+ | root@kubemaster: | ||
+ | PLUGIN | ||
+ | ctx | ||
+ | krew v0.4.3 | ||
+ | ns v0.9.4 | ||
+ | view-allocations | ||
</ | </ | ||
+ | |||
+ | =====LAB #3 - Géstion des patchs avec la Commande kustomize==== | ||
+ | |||
+ | Commencez par installer l' | ||
< | < | ||
+ | root@kubemaster: | ||
+ | </ | ||
+ | Créez ensuite le répertoire **kustomize** contenant le répertoire **base** et placez-vous dans ce dernier : | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | root@kubemaster: | ||
+ | root@kubemaster: | ||
</ | </ | ||
+ | |||
+ | Créez le manifest **deployment.yaml** : | ||
< | < | ||
+ | root@kubemaster: | ||
+ | root@kubemaster: | ||
+ | apiVersion: apps/v1 | ||
+ | kind: Deployment | ||
+ | metadata: | ||
+ | name: nginx | ||
+ | labels: | ||
+ | app: nginx | ||
+ | spec: | ||
+ | replicas: 1 | ||
+ | selector: | ||
+ | matchLabels: | ||
+ | app: nginx | ||
+ | template: | ||
+ | metadata: | ||
+ | labels: | ||
+ | app: nginx | ||
+ | spec: | ||
+ | affinity: | ||
+ | podAntiAffinity: | ||
+ | requiredDuringSchedulingIgnoredDuringExecution: | ||
+ | - labelSelector: | ||
+ | matchExpressions: | ||
+ | - key: app | ||
+ | operator: In | ||
+ | values: | ||
+ | - nginx | ||
+ | topologyKey: | ||
+ | containers: | ||
+ | - image: nginx: | ||
+ | imagePullPolicy: | ||
+ | name: nginx | ||
+ | </ | ||
+ | <WRAP center round important 60%> | ||
+ | **Important** - le contenu de ce fichier crée un **deployment** de 1 **replica** du pod **nginx** à partir de l' | ||
+ | </ | ||
+ | |||
+ | Créez ensuite le manifest **service.yaml** : | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | root@kubemaster: | ||
+ | apiVersion: v1 | ||
+ | kind: Service | ||
+ | metadata: | ||
+ | name: nginx | ||
+ | labels: | ||
+ | app: nginx | ||
+ | spec: | ||
+ | type: ClusterIP | ||
+ | ports: | ||
+ | - port: 80 | ||
+ | protocol: TCP | ||
+ | targetPort: 80 | ||
+ | selector: | ||
+ | app: nginx | ||
</ | </ | ||
+ | |||
+ | <WRAP center round important 60%> | ||
+ | **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. | ||
+ | </ | ||
+ | |||
+ | Dernièrement, | ||
< | < | ||
+ | root@kubemaster: | ||
+ | root@kubemaster: | ||
+ | apiVersion: kustomize.config.k8s.io/ | ||
+ | kind: Kustomization | ||
+ | |||
+ | images: | ||
+ | - name: nginx | ||
+ | newTag: 1.19.1 | ||
+ | resources: | ||
+ | - deployment.yaml | ||
+ | - service.yaml | ||
</ | </ | ||
+ | |||
+ | <WRAP center round important 60%> | ||
+ | **Important** - le contenu de ce fichier contient un **patch** pour l' | ||
+ | </ | ||
+ | |||
+ | Consultez donc l' | ||
< | < | ||
+ | root@kubemaster: | ||
+ | root@kubemaster: | ||
+ | . | ||
+ | └── base | ||
+ | ├── deployment.yaml | ||
+ | ├── kustomization.yaml | ||
+ | └── service.yaml | ||
+ | 1 directory, 3 files | ||
</ | </ | ||
+ | |||
+ | Exécutez maintenant la commande **kustomize** pour créer un **patch** pour les fichiers se trouvant dans le répertoire **base** : | ||
< | < | ||
+ | root@kubemaster: | ||
+ | apiVersion: v1 | ||
+ | kind: Service | ||
+ | metadata: | ||
+ | labels: | ||
+ | app: nginx | ||
+ | name: nginx | ||
+ | spec: | ||
+ | ports: | ||
+ | - port: 80 | ||
+ | protocol: TCP | ||
+ | targetPort: 80 | ||
+ | selector: | ||
+ | app: nginx | ||
+ | type: ClusterIP | ||
+ | --- | ||
+ | apiVersion: apps/v1 | ||
+ | kind: Deployment | ||
+ | metadata: | ||
+ | labels: | ||
+ | app: nginx | ||
+ | name: nginx | ||
+ | spec: | ||
+ | replicas: 1 | ||
+ | selector: | ||
+ | matchLabels: | ||
+ | app: nginx | ||
+ | template: | ||
+ | metadata: | ||
+ | labels: | ||
+ | app: nginx | ||
+ | spec: | ||
+ | affinity: | ||
+ | podAntiAffinity: | ||
+ | requiredDuringSchedulingIgnoredDuringExecution: | ||
+ | - labelSelector: | ||
+ | matchExpressions: | ||
+ | - key: app | ||
+ | operator: In | ||
+ | values: | ||
+ | - nginx | ||
+ | topologyKey: | ||
+ | containers: | ||
+ | - image: nginx: | ||
+ | imagePullPolicy: | ||
+ | name: nginx | ||
+ | </ | ||
+ | <WRAP center round important 60%> | ||
+ | **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' | ||
+ | </ | ||
+ | |||
+ | Imaginons maintenant que vous souhaitez déployer deux environnements **différents** de la même application, | ||
+ | |||
+ | Créez les répertoires **kustomize/ | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | root@kubemaster: | ||
</ | </ | ||
+ | |||
+ | Consultez l' | ||
< | < | ||
+ | root@kubemaster: | ||
+ | . | ||
+ | ├── base | ||
+ | │ | ||
+ | │ | ||
+ | │ | ||
+ | └── overlays | ||
+ | ├── development | ||
+ | └── production | ||
+ | 4 directories, | ||
</ | </ | ||
+ | |||
+ | Créez le fichier **dev_kustomization.yaml** : | ||
< | < | ||
+ | root@kubemaster: | ||
+ | root@kubemaster: | ||
+ | apiVersion: kustomize.config.k8s.io/ | ||
+ | kind: Kustomization | ||
+ | |||
+ | bases: | ||
+ | - ../ | ||
+ | |||
+ | nameSuffix: -development # < | ||
+ | |||
+ | commonLabels: | ||
+ | environment: | ||
+ | namespace: nginx-dev # < | ||
</ | </ | ||
- | < | + | Appliquez ces modifications : |
+ | < | ||
+ | root@kubemaster: | ||
+ | apiVersion: v1 | ||
+ | kind: Service | ||
+ | metadata: | ||
+ | labels: | ||
+ | app: nginx | ||
+ | environment: | ||
+ | name: nginx-development # < | ||
+ | namespace: nginx-dev # < | ||
+ | spec: | ||
+ | ports: | ||
+ | - port: 80 | ||
+ | protocol: TCP | ||
+ | targetPort: 80 | ||
+ | selector: | ||
+ | app: nginx | ||
+ | environment: | ||
+ | type: ClusterIP | ||
+ | --- | ||
+ | apiVersion: apps/v1 | ||
+ | kind: Deployment | ||
+ | metadata: | ||
+ | labels: | ||
+ | app: nginx | ||
+ | environment: | ||
+ | name: nginx-development | ||
+ | namespace: nginx-dev | ||
+ | spec: | ||
+ | replicas: 1 | ||
+ | selector: | ||
+ | matchLabels: | ||
+ | app: nginx | ||
+ | environment: | ||
+ | template: | ||
+ | metadata: | ||
+ | labels: | ||
+ | app: nginx | ||
+ | environment: | ||
+ | spec: | ||
+ | affinity: | ||
+ | podAntiAffinity: | ||
+ | requiredDuringSchedulingIgnoredDuringExecution: | ||
+ | - labelSelector: | ||
+ | matchExpressions: | ||
+ | - key: app | ||
+ | operator: In | ||
+ | values: | ||
+ | - nginx | ||
+ | topologyKey: | ||
+ | containers: | ||
+ | - image: nginx: | ||
+ | imagePullPolicy: | ||
+ | name: nginx | ||
</ | </ | ||
+ | |||
+ | Maintenant créez le fichier **prod_kustomization.yaml** : | ||
< | < | ||
+ | root@kubemaster: | ||
+ | root@kubemaster: | ||
+ | apiVersion: kustomize.config.k8s.io/ | ||
+ | kind: Kustomization | ||
+ | bases: | ||
+ | - ../../base # < | ||
+ | |||
+ | nameSuffix: -production # < | ||
+ | |||
+ | commonLabels: | ||
+ | environment: | ||
+ | |||
+ | namespace: nginx-prod # < | ||
+ | |||
+ | images: | ||
+ | - name: nginx | ||
+ | newTag: 1.19.2 # < | ||
</ | </ | ||
+ | |||
+ | Appliquez ces modifications : | ||
< | < | ||
+ | root@kubemaster: | ||
+ | apiVersion: v1 | ||
+ | kind: Service | ||
+ | metadata: | ||
+ | labels: | ||
+ | app: nginx | ||
+ | environment: | ||
+ | name: nginx-production # < | ||
+ | namespace: nginx-prod # < | ||
+ | spec: | ||
+ | ports: | ||
+ | - port: 80 | ||
+ | protocol: TCP | ||
+ | targetPort: 80 | ||
+ | selector: | ||
+ | app: nginx | ||
+ | environment: | ||
+ | type: ClusterIP | ||
+ | --- | ||
+ | apiVersion: apps/v1 | ||
+ | kind: Deployment | ||
+ | metadata: | ||
+ | labels: | ||
+ | app: nginx | ||
+ | environment: | ||
+ | name: nginx-production | ||
+ | namespace: nginx-prod | ||
+ | spec: | ||
+ | replicas: 1 | ||
+ | selector: | ||
+ | matchLabels: | ||
+ | app: nginx | ||
+ | environment: | ||
+ | template: | ||
+ | metadata: | ||
+ | labels: | ||
+ | app: nginx | ||
+ | environment: | ||
+ | spec: | ||
+ | affinity: | ||
+ | podAntiAffinity: | ||
+ | requiredDuringSchedulingIgnoredDuringExecution: | ||
+ | - labelSelector: | ||
+ | matchExpressions: | ||
+ | - key: app | ||
+ | operator: In | ||
+ | values: | ||
+ | - nginx | ||
+ | topologyKey: | ||
+ | containers: | ||
+ | - image: nginx: | ||
+ | imagePullPolicy: | ||
+ | name: nginx | ||
+ | </ | ||
+ | Créez maintenant le namespace **nginx-prod** : | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | namespace/ | ||
</ | </ | ||
+ | |||
+ | Installez l' | ||
< | < | ||
+ | root@kubemaster: | ||
+ | service/ | ||
+ | deployment.apps/ | ||
+ | </ | ||
+ | |||
+ | Constatez le résultat de l' | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | NAME READY | ||
+ | nginx-production-75d9486bb9-7xpr6 | ||
+ | |||
+ | root@kubemaster: | ||
+ | NAME | ||
+ | nginx-production | ||
+ | root@kubemaster: | ||
+ | NAME | ||
+ | nginx-production | ||
</ | </ | ||
+ | |||
+ | Supprimez le deployment et le service nginx-production : | ||
< | < | ||
+ | root@kubemaster: | ||
+ | deployment.apps " | ||
+ | |||
+ | root@kubemaster: | ||
+ | No resources found in nginx-prod namespace. | ||
+ | |||
+ | root@kubemaster: | ||
+ | NAME | ||
+ | nginx-production | ||
+ | |||
+ | root@kubemaster: | ||
+ | No resources found in nginx-prod namespace. | ||
+ | |||
+ | root@kubemaster: | ||
+ | service " | ||
+ | root@kubemaster: | ||
+ | No resources found in nginx-prod namespace. | ||
</ | </ | ||
+ | |||
+ | Installez l' | ||
< | < | ||
+ | root@kubemaster: | ||
+ | namespace/ | ||
+ | root@kubemaster: | ||
+ | service/ | ||
+ | deployment.apps/ | ||
+ | </ | ||
+ | Constatez le résultat : | ||
+ | |||
+ | < | ||
+ | root@kubemaster: | ||
+ | NAME | ||
+ | nginx-development-5f8d7bdd88-fsnc6 | ||
+ | |||
+ | root@kubemaster: | ||
+ | NAME READY | ||
+ | nginx-development | ||
+ | |||
+ | root@kubemaster: | ||
+ | NAME TYPE CLUSTER-IP | ||
+ | nginx-development | ||
</ | </ | ||
---- | ---- | ||
- | Copyright © 2022 Hugh Norris | + | Copyright © 2024 Hugh Norris |