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:k8s07 [2020/12/13 14:45] – admin | elearning:workbooks:kubernetes:k8s07 [2024/12/15 06:55] (Version actuelle) – admin | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
~~PDF: | ~~PDF: | ||
- | Version - **2020.02** | + | Version - **2024.01** |
Dernière mise-à-jour : ~~LASTMOD~~ | Dernière mise-à-jour : ~~LASTMOD~~ | ||
- | ======DOF308 - Utilisation de la Commande kubectl====== | + | |
+ | ======DOF308 - Introduction à la Sécurisation de K8s====== | ||
=====Contenu du Module===== | =====Contenu du Module===== | ||
- | * **DOF308 - Utilisation de la Commande kubectl** | + | * **DOF308 - Introduction à la Sécurisation de K8s** |
* Contenu du Module | * Contenu du Module | ||
- | * LAB #1 - Travailler avec kubectl | + | * LAB #1 - Role Based Acces Control et Certificats TLS |
- | * 1.1 - Équivalences entre la commande docker et la commande kubectl | + | * 1.1 - Présentation |
- | * 1.2 - Obtenir de l'Aide sur les Commandes de kubectl | + | * 1.2 - Le Fichier / |
- | * 1.3 - Obtenir de l'Information sur le Cluster | + | * 1.3 - Création d'un serviceAccount |
- | * La Commande version | + | * 1.4 - Création d'un Utilisateur |
- | * La Commande cluster-info | + | * 1.5 - Certificats TLS |
- | * La Commande api-versions | + | * LAB #2 - Implémentation de la Sécurité au niveau des Pods |
- | * La Commande api-resources | + | * 2.1 - Présentation |
- | * 1.4 - Travailler avec les Nœuds | + | * 2.2 - Kubernetes Security Context |
- | * La Commande describe | + | * ReadOnlyRootFilesystem |
- | * La Commande top | + | * drop |
- | * Les Commandes cordon et uncordon | + | * 2.3 - Kubernetes Network Policies |
- | * La Commande drain | + | * 2.4 - Kubernetes Resource Allocation Management |
- | * La Commande delete | + | |
- | * 1.5 - Gestion des Applications | + | |
- | * La Commande expose | + | |
- | * La Commande get | + | |
- | * La Commande set | + | |
- | * La Commande rollout | + | |
- | * 1.6 - Déboguer une Application | + | |
- | * La Commande logs | + | |
- | * La Commande exec | + | |
- | * 1.7 - Gérer les Plugins de kubectl | + | |
- | * La Commande krew | + | |
- | * 1.8 - Gérer des patchs | + | |
- | * La Commande kustomize | + | |
- | * 1.9 - Alias utile | + | |
- | * L' | + | |
- | * L' | + | |
- | * L' | + | |
- | * L' | + | |
- | * L' | + | |
- | * L' | + | |
- | * L' | + | |
- | * L' | + | |
- | * L' | + | |
- | =====Préparation===== | + | =====Ressources===== |
- | ====Présentation de kind==== | + | ====Lab #1==== |
- | kind est un outil utilisé pour exécuter un cluster Kubernetes localement en utilisant des conteneurs Docker en tant que nœuds. kind a été développé pour tester Kubernetes lui-même mais peut aussi être utilisé pour du développement local. | + | * https://www.dropbox.com/ |
+ | * https:// | ||
- | Le site web de kind est **[[https:// | + | ====Lab #2==== |
- | ====Installation de Docker-CE dans la VM Debian_10==== | + | * https:// |
+ | * https:// | ||
+ | * https:// | ||
+ | * https:// | ||
+ | * https:// | ||
- | Commencez par augmenter la RAM de la machine virtuelle Debian_10 : | + | =====LAB #1 - Role Based Acces Control et Certificats TLS===== |
- | < | + | ====1.1 |
- | desktop@serverXX: | + | |
- | </ | + | |
- | Configurez ensuite la redirection de port pour le service ssh : | + | Un objet Kubernetes est soit lié à un Namespace soit non-lié à un Namespace. |
- | < | + | Kubernetes utilise l'API **rbac.authorization.k8s.io** pour gérer les autorisations. Les acteurs jouant un rôle dans cette API sont : |
- | desktop@serverXX:~$ VBoxManage modifyvm " | + | |
- | </ | + | |
- | Démarrez | + | * **Namespaces**, |
+ | * peuvent être considérées comme des clusters virtuels, | ||
+ | * permettent l' | ||
+ | * permettent le regroupement d' | ||
+ | * sont utilisés avec des applications, | ||
- | < | + | * **Subjects**, |
- | desktop@serverXX: | + | |
- | Waiting for VM " | + | * //ServiceAccounts// - permettent la mise en place de permissions au niveau des entités logiciels. Kubernetes crée un certain nombre de serviceAccounts automatiquement mais l'Administrateur peut en créer d' |
- | VM " | + | * //User Groups// - Kubernetes regroupe des utilisateurs en utilisant des propriétés communes telles le préfixe d'un serviceAccount ou le champ de l' |
- | </ | + | |
- | + | ||
- | Patientez 2 minutes puis connectez-vous à la machine virtuelle : | + | |
- | + | ||
- | < | + | |
- | desktop@serverXX: | + | |
- | trainee@localhost' | + | |
- | Linux debian10 4.19.0-6-amd64 #1 SMP Debian 4.19.67-2+deb10u2 (2019-11-11) x86_64 | + | |
- | + | ||
- | The programs included with the Debian GNU/Linux system are free software; | + | |
- | the exact distribution terms for each program are described in the | + | |
- | individual files in / | + | |
- | + | ||
- | Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent | + | |
- | permitted by applicable law. | + | |
- | Last login: Mon Nov 30 15:50:01 2020 from 10.0.2.2 | + | |
- | </ | + | |
- | + | ||
- | Installez ensuite Docker-CE : | + | |
- | + | ||
- | < | + | |
- | trainee@debian10: | + | |
- | Password: fenestros | + | |
- | root@debian10: | + | |
- | + | ||
- | root@debian10: | + | |
- | ... | + | |
- | root@debian10: | + | |
- | ... | + | |
- | root@debian10: | + | |
- | ... | + | |
- | root@debian10: | + | |
- | ... | + | |
- | root@debian10: | + | |
- | root@debian10: | + | |
- | { | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | | + | |
- | }, | + | |
- | " | + | |
- | } | + | |
- | root@debian10: | + | |
- | root@debian10: | + | |
- | root@debian10: | + | |
- | root@debian10: | + | |
- | Client: Docker Engine - Community | + | |
- | | + | |
- | API version: | + | |
- | Go version: | + | |
- | Git commit: | + | |
- | | + | |
- | | + | |
- | | + | |
- | + | ||
- | Server: Docker Engine - Community | + | |
- | | + | |
- | Version: | + | |
- | API version: | + | |
- | Go version: | + | |
- | Git commit: | + | |
- | Built: | + | |
- | OS/ | + | |
- | Experimental: | + | |
- | | + | |
- | Version: | + | |
- | GitCommit: | + | |
- | | + | |
- | Version: | + | |
- | GitCommit: | + | |
- | | + | |
- | Version: | + | |
- | GitCommit: | + | |
- | </ | + | |
- | + | ||
- | ====Installation de kubelet, kubeadm et kubectl==== | + | |
- | + | ||
- | Ajoutez | + | |
- | + | ||
- | < | + | |
- | root@debian10: | + | |
- | OK | + | |
- | </ | + | |
- | + | ||
- | Ajoutez le dépôt | + | |
- | + | ||
- | < | + | |
- | root@debian10: | + | |
- | deb https:// | + | |
- | </ | + | |
- | + | ||
- | Procédez à l'installation de kubeadm, kubelet et kubectl : | + | |
- | + | ||
- | < | + | |
- | root@debian10: | + | |
- | </ | + | |
- | + | ||
- | Bloquez les mises-à-jour de kubeadm, kubelet et kubectl : | + | |
- | + | ||
- | < | + | |
- | root@debian10: | + | |
- | kubelet set on hold. | + | |
- | kubeadm set on hold. | + | |
- | kubectl set on hold. | + | |
- | </ | + | |
- | + | ||
- | + | ||
- | + | ||
- | ====Installation de kind et Démarrage du Cluster==== | + | |
- | + | ||
- | Installez | + | |
- | + | ||
- | < | + | |
- | root@debian10: | + | |
- | % Total % Received % Xferd Average Speed | + | |
- | | + | |
- | 100 97 100 97 0 | + | |
- | 100 | + | |
- | 100 7247k 100 7247k 0 | + | |
- | root@debian10: | + | |
- | root@debian10: | + | |
- | root@debian10: | + | |
- | / | + | |
- | </ | + | |
- | + | ||
- | Re-démarrez la machine virtuelle : | + | |
- | + | ||
- | < | + | |
- | root@debian10: | + | |
- | </ | + | |
- | + | ||
- | Connectez-vous à la machine virtuelle Debian_10 : | + | |
- | + | ||
- | < | + | |
- | desktop@serverXX: | + | |
- | trainee@localhost's password: trainee | + | |
- | Linux debian10 4.19.0-6-amd64 #1 SMP Debian 4.19.67-2+deb10u2 (2019-11-11) x86_64 | + | |
- | + | ||
- | The programs included with the Debian GNU/Linux system are free software; | + | |
- | the exact distribution terms for each program are described in the | + | |
- | individual files in / | + | |
- | + | ||
- | Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent | + | |
- | permitted by applicable law. | + | |
- | Last login: Mon Nov 30 13:47:09 2020 from 10.0.2.2 | + | |
- | </ | + | |
- | + | ||
- | Devenez | + | |
- | + | ||
- | < | + | |
- | trainee@debian10: | + | |
- | Password: fenestros | + | |
- | root@debian10: | + | |
- | root@debian10: | + | |
- | kind: Cluster | + | |
- | apiVersion: kind.x-k8s.io/v1alpha4 | + | |
- | kubeadmConfigPatches: | + | |
- | - | | + | |
- | apiVersion: kubelet.config.k8s.io/v1beta1 | + | |
- | kind: KubeletConfiguration | + | |
- | evictionHard: | + | |
- | nodefs.available: | + | |
- | kubeadmConfigPatchesJSON6902: | + | |
- | - group: kubeadm.k8s.io | + | |
- | version: v1beta2 | + | |
- | kind: ClusterConfiguration | + | |
- | patch: | | + | |
- | - op: add | + | |
- | path: /apiServer/ | + | |
- | value: my-hostname | + | |
- | nodes: | + | |
- | - role: control-plane | + | |
- | - role: worker | + | |
- | - role: worker | + | |
- | - role: worker | + | |
- | </ | + | |
- | + | ||
- | Créez | + | |
- | + | ||
- | < | + | |
- | root@debian10: | + | |
- | Creating cluster " | + | |
- | ✓ Ensuring node image (kindest/ | + | |
- | ✓ Preparing nodes 📦 📦 📦 📦 | + | |
- | ✓ Writing configuration 📜 | + | |
- | ✓ Starting control-plane 🕹️ | + | |
- | ✓ Installing CNI 🔌 | + | |
- | ✓ Installing StorageClass 💾 | + | |
- | ✓ Joining worker nodes 🚜 | + | |
- | Set kubectl context to " | + | |
- | You can now use your cluster with: | + | |
- | + | ||
- | kubectl cluster-info --context kind-kind | + | |
- | + | ||
- | Not sure what to do next? 😅 Check out https:// | + | |
- | </ | + | |
- | + | ||
- | =====LAB #1 - Travailler avec kubectl===== | + | |
- | ====1.1 | + | * **Resources**, |
+ | * ce sont des entités auxquelles auront accès les Subjects, | ||
+ | * une ressource est une entité telle un pod, un deployment ou des sous-ressources telles les journaux d'un pod, | ||
+ | * le Pod Security Policy (PSP) est aussi considéré comme une ressource. | ||
- | Un pré-requis pour travailler avec Kubernetes est de bien comprendre la commande | + | |
+ | * //Roles// - permettent | ||
+ | * On ajoute des permissions, | ||
+ | * // | ||
+ | * définir | ||
+ | * définir des permissions pour des ressources à être utilisées dans tous les Namespaces | ||
+ | * définir des permissions pour des ressources du cluster. | ||
- | Pour obtenir de l'information concernant | + | Un exemple d'un Role pour accorder les permissions dans le Namespace default est : |
< | < | ||
- | # docker info | + | apiVersion: rbac.authorization.k8s.io/ |
+ | kind: Role | ||
+ | metadata: | ||
+ | namespace: default | ||
+ | name: pod-reader | ||
+ | rules: | ||
+ | - apiGroups: ["" | ||
+ | resources: [" | ||
+ | verbs: [" | ||
</ | </ | ||
- | devient : | + | <WRAP center round important> |
- | + | **Important** | |
- | <file> | + | |
- | # kubectl cluster-info | + | |
- | </ | + | |
- | + | ||
- | Pour obtenir l' | + | |
- | + | ||
- | < | + | |
- | # docker version | + | |
- | </ | + | |
- | + | ||
- | devient | + | |
- | + | ||
- | < | + | |
- | # kubectl info | + | |
- | </ | + | |
- | + | ||
- | Pour lancer un conteneur nginx en exposant le port 80, la commande docker | + | |
- | + | ||
- | < | + | |
- | # docker run -d --restart=always --name nginx -p 80:80 nginx | + | |
- | </file> | + | |
- | + | ||
- | devient deux commandes : | + | |
- | + | ||
- | < | + | |
- | # kubectl create deployment --image=nginx nginx | + | |
- | </file> | + | |
- | + | ||
- | et : | + | |
- | + | ||
- | < | + | |
- | # kubectl expose deployment nginx --port=80 --name=nginx | + | |
- | </ | + | |
- | + | ||
- | Pour voir les traces en continue des logs du conteneur nginx, la commande docker : | + | |
- | + | ||
- | < | + | |
- | # docker logs -f nginx | + | |
- | </ | + | |
- | + | ||
- | où nginx est le nom du conteneur, | + | |
- | + | ||
- | devient : | + | |
- | + | ||
- | < | + | |
- | # kubectl logs -f nginx | + | |
- | </ | + | |
- | + | ||
- | où nginx est le nom du pod. | + | |
- | + | ||
- | <WRAP center round tip 40%> | + | |
- | Un POD est un objet qui encapsule un conteneur. Le conteneur est un instance d'une application. La relation entre un POD et un conteneur d' | + | |
</ | </ | ||
- | Pour se place dans le conteneur nginx, la commande docker | + | Un example d'un ClusterRole pour accorder des permissions de lecture des secrets |
< | < | ||
- | # docker exec -it nginx /bin/bash | + | apiVersion: rbac.authorization.k8s.io/v1 |
+ | kind: ClusterRole | ||
+ | metadata: | ||
+ | name: secret-reader | ||
+ | rules: | ||
+ | - apiGroups: ["" | ||
+ | resources: [" | ||
+ | verbs: [" | ||
</ | </ | ||
- | où nginx est le nom du conteneur, | + | * **RoleBindings** et **ClusterRoleBindings**, |
+ | * permettent d' | ||
+ | * **RoleBindings** sont spécifiques à un NameSpace, | ||
+ | * **ClusterRoleBindings** s' | ||
- | devient : | + | ====1.2 - Le Fichier / |
- | < | + | L' |
- | # kubectl exec -it nginx | + | |
- | </ | + | |
- | + | ||
- | où nginx est le nom du pod. | + | |
- | + | ||
- | Pour obtenir | + | |
- | + | ||
- | < | + | |
- | # docker ps -a | + | |
- | </ | + | |
- | + | ||
- | devient : | + | |
- | + | ||
- | < | + | |
- | # kubectl get pods | + | |
- | </ | + | |
- | + | ||
- | Pour arrêter et supprimer | + | |
- | + | ||
- | < | + | |
- | # docker stop nginx | + | |
- | # docker rm nginx | + | |
- | </file> | + | |
- | + | ||
- | deviennent : | + | |
- | + | ||
- | < | + | |
- | # kubectl delete deployment nginx | + | |
- | </file> | + | |
- | + | ||
- | où nginx est le nom de déploiement et, | + | |
- | + | ||
- | < | + | |
- | # kubectl delete pod nginx | + | |
- | </file> | + | |
- | + | ||
- | <WRAP center round tip 40%> | + | |
- | Un Deployment sous Kubernetes est un objet hiérarchiquement supérieur à un ReplicaSet. Un ReplicaSet remplit la même fonction qu'un Contrôleur de Réplication. ReplicaSets sont la façon la plus récente de gérer la réplication. Un Contrôleur de Réplication permet d' | + | |
- | </WRAP> | + | |
- | + | ||
- | ====1.2 - Obtenir de l'Aide sur les Commandes de kubectl==== | + | |
- | + | ||
- | Les commandes de **kubectl** sont regroupées par catégorie | + | |
< | < | ||
- | root@debian10:~# kubectl | + | root@kubemaster:~# cat / |
- | kubectl controls the Kubernetes cluster manager. | + | apiVersion: v1 |
- | + | kind: Pod | |
- | Find more information at: https://kubernetes.io/ | + | metadata: |
- | + | annotations: | |
- | Basic Commands (Beginner): | + | kubeadm.kubernetes.io/ |
- | create | + | |
- | | + | |
- | | + | |
- | set Set specific features on objects | + | tier: control-plane |
- | + | | |
- | Basic Commands (Intermediate): | + | |
- | | + | spec: |
- | | + | |
- | | + | |
- | | + | - kube-apiserver |
- | + | - --advertise-address=192.168.56.2 | |
- | Deploy Commands: | + | - --allow-privileged=true |
- | | + | - --authorization-mode=Node,RBAC |
- | | + | - --client-ca-file=/ |
- | | + | - --enable-admission-plugins=NodeRestriction |
- | + | - --enable-bootstrap-token-auth=true | |
- | Cluster Management Commands: | + | - --etcd-cafile=/ |
- | | + | - --etcd-certfile=/ |
- | cluster-info Display | + | - --etcd-keyfile=/ |
- | | + | - --etcd-servers=https:// |
- | | + | - --kubelet-client-certificate=/ |
- | | + | - --kubelet-client-key=/ |
- | | + | - --kubelet-preferred-address-types=InternalIP,ExternalIP,Hostname |
- | | + | - --proxy-client-cert-file=/ |
- | + | - --proxy-client-key-file=/ | |
- | Troubleshooting and Debugging Commands: | + | - --requestheader-allowed-names=front-proxy-client |
- | | + | - --requestheader-client-ca-file=/ |
- | | + | - --requestheader-extra-headers-prefix=X-Remote-Extra- |
- | | + | - --requestheader-group-headers=X-Remote-Group |
- | | + | - --requestheader-username-headers=X-Remote-User |
- | port-forward | + | - --secure-port=6443 |
- | | + | - --service-account-issuer=https:// |
- | | + | - --service-account-key-file=/ |
- | | + | - --service-account-signing-key-file=/ |
- | + | - --service-cluster-ip-range=10.96.0.0/ | |
- | Advanced Commands: | + | - --tls-cert-file=/ |
- | | + | - --tls-private-key-file=/ |
- | | + | image: k8s.gcr.io/ |
- | | + | imagePullPolicy: |
- | | + | livenessProbe: |
- | | + | failureThreshold: |
- | | + | httpGet: |
- | | + | |
- | + | path: /livez | |
- | Settings Commands: | + | port: 6443 |
- | | + | scheme: HTTPS |
- | | + | |
- | | + | |
- | + | | |
- | Other Commands: | + | name: kube-apiserver |
- | | + | |
- | api-resources Print the supported API resources on the server | + | |
- | | + | httpGet: |
- | | + | host: 192.168.56.2 |
- | | + | path: /readyz |
- | | + | port: 6443 |
- | + | scheme: HTTPS | |
- | Usage: | + | periodSeconds: |
- | | + | timeoutSeconds: |
- | + | | |
- | Use " | + | |
- | Use " | + | |
+ | | ||
+ | | ||
+ | httpGet: | ||
+ | host: 192.168.56.2 | ||
+ | path: /livez | ||
+ | | ||
+ | scheme: HTTPS | ||
+ | initialDelaySeconds: | ||
+ | periodSeconds: | ||
+ | timeoutSeconds: | ||
+ | volumeMounts: | ||
+ | | ||
+ | name: ca-certs | ||
+ | | ||
+ | - mountPath: / | ||
+ | name: etc-ca-certificates | ||
+ | | ||
+ | - mountPath: / | ||
+ | name: k8s-certs | ||
+ | | ||
+ | - mountPath: / | ||
+ | name: usr-local-share-ca-certificates | ||
+ | readOnly: true | ||
+ | - mountPath: / | ||
+ | name: usr-share-ca-certificates | ||
+ | readOnly: true | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | type: RuntimeDefault | ||
+ | | ||
+ | | ||
+ | path: / | ||
+ | type: DirectoryOrCreate | ||
+ | | ||
+ | - hostPath: | ||
+ | path: / | ||
+ | type: DirectoryOrCreate | ||
+ | name: etc-ca-certificates | ||
+ | - hostPath: | ||
+ | path: /etc/ | ||
+ | type: DirectoryOrCreate | ||
+ | name: k8s-certs | ||
+ | | ||
+ | path: / | ||
+ | type: DirectoryOrCreate | ||
+ | name: usr-local-share-ca-certificates | ||
+ | | ||
+ | path: / | ||
+ | type: DirectoryOrCreate | ||
+ | name: usr-share-ca-certificates | ||
+ | status: {} | ||
</ | </ | ||
- | Plus d'informations sur chaque commande peut être obtenue en passant l' | + | ====1.3 - Création |
- | < | + | Il est préférable de créer un serviceAccount par service. Ceci permet une configuration plus fine de la sécurité concernant le service. Si un serviceAccount n'est pas spécifié lors de la création des pods, ces pods se verront attribués le serviceAccount par défaut du Namespace. |
- | root@debian10: | + | |
- | Create a resource from a file or from stdin. | + | |
- | JSON and YAML formats are accepted. | + | Imaginons que vous souhaitez que votre application interagisse avec l' |
- | + | ||
- | Examples: | + | |
- | # Create a pod using the data in pod.json. | + | |
- | kubectl create -f ./ | + | |
- | + | ||
- | # Create a pod based on the JSON passed into stdin. | + | |
- | cat pod.json | kubectl create -f - | + | |
- | + | ||
- | # Edit the data in docker-registry.yaml in JSON then create the resource using the edited data. | + | |
- | kubectl create -f docker-registry.yaml --edit -o json | + | |
- | + | ||
- | Available Commands: | + | |
- | clusterrole | + | |
- | clusterrolebinding | + | |
- | configmap | + | |
- | cronjob | + | |
- | deployment | + | |
- | job | + | |
- | namespace | + | |
- | poddisruptionbudget Create a pod disruption budget with the specified name. | + | |
- | priorityclass | + | |
- | quota | + | |
- | role Create a role with single rule. | + | |
- | rolebinding | + | |
- | secret | + | |
- | service | + | |
- | serviceaccount | + | |
- | + | ||
- | Options: | + | |
- | --allow-missing-template-keys=true: | + | |
- | the template. Only applies to golang and jsonpath output formats. | + | |
- | --dry-run='none': Must be " | + | |
- | sent, without sending it. If server strategy, submit server-side request without persisting the resource. | + | |
- | --edit=false: | + | |
- | --field-manager='kubectl-create': | + | |
- | -f, --filename=[]: | + | |
- | -k, --kustomize='': | + | |
- | -o, --output='': | + | |
- | json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-as-json|jsonpath-file. | + | |
- | --raw='': | + | |
- | --record=false: | + | |
- | command. If set to true, record the command. If not set, default | + | |
- | already exists. | + | |
- | -R, --recursive=false: | + | |
- | related manifests organized within the same directory. | + | |
- | --save-config=false: | + | |
- | annotation will be unchanged. This flag is useful when you want to perform kubectl apply on this object in the future. | + | |
- | -l, --selector='': | + | |
- | --template='': | + | |
- | template format is golang templates [http:// | + | |
- | --validate=true: | + | |
- | --windows-line-endings=false: | + | |
- | + | ||
- | Usage: | + | |
- | kubectl create -f FILENAME [options] | + | |
- | + | ||
- | Use " | + | |
- | Use " | + | |
- | </ | + | |
- | + | ||
- | Dernièrement les commandes kubectl peuvent recevoir des options. Pour visualiser les options qui peuvent être passées à toutes les commandes kubectl, saisissez la commande suivante | + | |
< | < | ||
- | root@debian10:~# kubectl | + | root@kubemaster:~# kubectl |
- | The following options | + | no |
- | + | ||
- | | + | |
- | --alsologtostderr=false: | + | |
- | | + | |
- | --as-group=[]: Group to impersonate for the operation, this flag can be repeated to specify multiple groups. | + | |
- | --cache-dir='/ | + | |
- | | + | |
- | --client-certificate='': | + | |
- | --client-key='': | + | |
- | --cluster='': | + | |
- | --context='': | + | |
- | --insecure-skip-tls-verify=false: | + | |
- | make your HTTPS connections insecure | + | |
- | --kubeconfig='': | + | |
- | --log-backtrace-at=: | + | |
- | --log-dir='': | + | |
- | --log-file='': | + | |
- | --log-file-max-size=1800: | + | |
- | the maximum file size is unlimited. | + | |
- | --log-flush-frequency=5s: | + | |
- | --logtostderr=true: | + | |
- | --match-server-version=false: | + | |
- | -n, --namespace='': | + | |
- | --password='': | + | |
- | --profile=' | + | |
- | --profile-output=' | + | |
- | --request-timeout=' | + | |
- | should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. | + | |
- | -s, --server='': | + | |
- | --skip-headers=false: | + | |
- | --skip-log-headers=false: | + | |
- | --stderrthreshold=2: | + | |
- | --tls-server-name='': | + | |
- | used to contact the server is used | + | |
- | --token='': | + | |
- | --user='': | + | |
- | --username='': | + | |
- | -v, --v=0: number for the log level verbosity | + | |
- | --vmodule=: comma-separated list of pattern=N settings for file-filtered logging | + | |
- | --warnings-as-errors=false: | + | |
</ | </ | ||
- | ====1.3 - Obtenir de l' | + | <WRAP center round important> |
- | + | **Important** : le format | |
- | ===La Commande version=== | + | |
- | + | ||
- | Commencez par obtenir l' | + | |
- | + | ||
- | <code> | + | |
- | root@debian10: | + | |
- | Client Version: v1.20.0 | + | |
- | Server Version: v1.19.1 | + | |
- | </ | + | |
- | + | ||
- | ===La Commande cluster-info=== | + | |
- | + | ||
- | Consultez ensuite les informations concernant le cluster : | + | |
- | + | ||
- | < | + | |
- | root@debian10: | + | |
- | Kubernetes control plane is running at https:// | + | |
- | KubeDNS is running at https:// | + | |
- | + | ||
- | To further debug and diagnose cluster problems, use ' | + | |
- | </ | + | |
- | + | ||
- | ===La Commande api-versions=== | + | |
- | + | ||
- | Afin de connaître les versions des API compatibles avec la version de Kubernetes installée, exécutez la commande | + | |
- | + | ||
- | < | + | |
- | root@debian10: | + | |
- | admissionregistration.k8s.io/ | + | |
- | admissionregistration.k8s.io/ | + | |
- | apiextensions.k8s.io/ | + | |
- | apiextensions.k8s.io/ | + | |
- | apiregistration.k8s.io/ | + | |
- | apiregistration.k8s.io/ | + | |
- | apps/v1 | + | |
- | authentication.k8s.io/ | + | |
- | authentication.k8s.io/ | + | |
- | authorization.k8s.io/ | + | |
- | authorization.k8s.io/ | + | |
- | autoscaling/ | + | |
- | autoscaling/ | + | |
- | autoscaling/ | + | |
- | batch/v1 | + | |
- | batch/ | + | |
- | certificates.k8s.io/ | + | |
- | certificates.k8s.io/ | + | |
- | coordination.k8s.io/ | + | |
- | coordination.k8s.io/ | + | |
- | discovery.k8s.io/ | + | |
- | events.k8s.io/ | + | |
- | events.k8s.io/ | + | |
- | extensions/ | + | |
- | networking.k8s.io/ | + | |
- | networking.k8s.io/ | + | |
- | node.k8s.io/ | + | |
- | policy/ | + | |
- | rbac.authorization.k8s.io/ | + | |
- | rbac.authorization.k8s.io/ | + | |
- | scheduling.k8s.io/ | + | |
- | scheduling.k8s.io/ | + | |
- | storage.k8s.io/ | + | |
- | storage.k8s.io/ | + | |
- | v1 | + | |
- | </ | + | |
- | + | ||
- | ===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 - **APIGROUP**, | + | |
- | * si oui ou non la ressource est liée à un namespace - **NAMESPACED**, | + | |
- | * le type KIND de la ressource - **KIND**. | + | |
- | + | ||
- | < | + | |
- | root@debian10: | + | |
- | NAME SHORTNAMES | + | |
- | bindings | + | |
- | componentstatuses | + | |
- | 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 | + | |
- | endpointslices | + | |
- | events | + | |
- | ingresses | + | |
- | ingressclasses | + | |
- | ingresses | + | |
- | networkpolicies | + | |
- | runtimeclasses | + | |
- | poddisruptionbudgets | + | |
- | podsecuritypolicies | + | |
- | clusterrolebindings | + | |
- | clusterroles | + | |
- | rolebindings | + | |
- | roles rbac.authorization.k8s.io/ | + | |
- | priorityclasses | + | |
- | csidrivers | + | |
- | csinodes | + | |
- | storageclasses | + | |
- | volumeattachments | + | |
- | </ | + | |
- | + | ||
- | ====1.4 -Travailler avec les Nœuds==== | + | |
- | + | ||
- | Pour consulter les nœuds du cluster utilisez la commande **get nodes** : | + | |
- | + | ||
- | < | + | |
- | root@debian10: | + | |
- | NAME | + | |
- | kind-control-plane | + | |
- | kind-worker | + | |
- | kind-worker2 | + | |
- | kind-worker3 | + | |
- | </ | + | |
- | + | ||
- | ===La Commande describe node=== | + | |
- | + | ||
- | De l'information sur le nœud peut être obtenue grâce à la commande | + | |
- | + | ||
- | * la section **Labels: | + | |
- | * la ligne **Unschedulable: | + | |
- | + | ||
- | < | + | |
- | root@debian10: | + | |
- | Name: | + | |
- | Roles: | + | |
- | Labels: | + | |
- | beta.kubernetes.io/ | + | |
- | kubernetes.io/ | + | |
- | kubernetes.io/ | + | |
- | kubernetes.io/ | + | |
- | node-role.kubernetes.io/ | + | |
- | Annotations: | + | |
- | node.alpha.kubernetes.io/ | + | |
- | volumes.kubernetes.io/ | + | |
- | CreationTimestamp: | + | |
- | Taints: | + | |
- | Unschedulable: | + | |
- | Lease: | + | |
- | HolderIdentity: | + | |
- | AcquireTime: | + | |
- | RenewTime: | + | |
- | Conditions: | + | |
- | Type | + | |
- | ---- | + | |
- | MemoryPressure | + | |
- | DiskPressure | + | |
- | PIDPressure | + | |
- | Ready True Fri, 11 Dec 2020 12:09:12 +0100 Fri, 11 Dec 2020 12:09:12 +0100 | + | |
- | ... | + | |
- | </ | + | |
- | + | ||
- | Dans la deuxième partie de la sortie, on peut constater : | + | |
- | + | ||
- | | + | |
- | + | ||
- | < | + | |
- | ... | + | |
- | Addresses: | + | |
- | InternalIP: | + | |
- | Hostname: | + | |
- | Capacity: | + | |
- | cpu: 1 | + | |
- | ephemeral-storage: | + | |
- | hugepages-2Mi: | + | |
- | memory: | + | |
- | pods: 110 | + | |
- | Allocatable: | + | |
- | cpu: 1 | + | |
- | ephemeral-storage: | + | |
- | hugepages-2Mi: | + | |
- | memory: | + | |
- | pods: 110 | + | |
- | ... | + | |
- | </ | + | |
- | + | ||
- | Dans la troisième partie de la sortie, on peut constater : | + | |
- | + | ||
- | * la section **System Info:** contenant de l' | + | |
- | * la section **Non-terminated Pods** contenant de l' | + | |
- | + | ||
- | < | + | |
- | ... | + | |
- | System Info: | + | |
- | Machine ID: | + | |
- | System UUID: 734424d3-5513-4e2d-a7e3-7f4429493214 | + | |
- | Boot ID: 05357148-f589-4478-b096-5b18c0ddc66f | + | |
- | Kernel Version: | + | |
- | OS Image: | + | |
- | Operating System: | + | |
- | Architecture: | + | |
- | Container Runtime Version: | + | |
- | Kubelet Version: | + | |
- | Kube-Proxy Version: | + | |
- | PodCIDR: | + | |
- | PodCIDRs: | + | |
- | ProviderID: | + | |
- | Non-terminated Pods: (9 in total) | + | |
- | Namespace | + | |
- | --------- | + | |
- | kube-system | + | |
- | kube-system | + | |
- | kube-system | + | |
- | kube-system | + | |
- | kube-system | + | |
- | kube-system | + | |
- | kube-system | + | |
- | kube-system | + | |
- | local-path-storage | + | |
- | ... | + | |
- | </ | + | |
- | + | ||
- | Dans la dernière partie de la sortie, on peut constater | + | |
- | + | ||
- | * la section **Allocated resources: | + | |
- | + | ||
- | < | + | |
- | Allocated resources: | + | |
- | (Total limits may be over 100 percent, i.e., overcommitted.) | + | |
- | Resource | + | |
- | -------- | + | |
- | cpu 850m (85%) 100m (10%) | + | |
- | memory | + | |
- | ephemeral-storage | + | |
- | hugepages-2Mi | + | |
- | Events: | + | |
- | Type Reason | + | |
- | ---- ------ | + | |
- | Normal | + | |
- | Normal | + | |
- | Normal | + | |
- | Normal | + | |
- | Normal | + | |
- | Normal | + | |
- | Normal | + | |
- | Normal | + | |
- | Normal | + | |
- | Normal | + | |
- | </ | + | |
- | + | ||
- | ===La Commande top=== | + | |
- | + | ||
- | La commande **top** nécessite à ce que l'API **Metrics** soit disponible dans le cluster. Pour déployer le serveur Metrics, téléchargez le fichier **components.yaml** : | + | |
- | + | ||
- | < | + | |
- | root@debian10: | + | |
- | --2020-12-11 12: | + | |
- | Resolving github.com (github.com)... 140.82.121.4 | + | |
- | Connecting to github.com (github.com)|140.82.121.4|: | + | |
- | HTTP request sent, awaiting response... 302 Found | + | |
- | Location: https:// | + | |
- | --2020-12-11 12: | + | |
- | Reusing existing connection to github.com: | + | |
- | HTTP request sent, awaiting response... 302 Found | + | |
- | Location: https:// | + | |
- | --2020-12-11 12: | + | |
- | Resolving github-production-release-asset-2e65be.s3.amazonaws.com (github-production-release-asset-2e65be.s3.amazonaws.com)... 52.217.104.236 | + | |
- | Connecting to github-production-release-asset-2e65be.s3.amazonaws.com (github-production-release-asset-2e65be.s3.amazonaws.com)|52.217.104.236|: | + | |
- | HTTP request sent, awaiting response... 200 OK | + | |
- | Length: 3962 (3.9K) [application/ | + | |
- | Saving to: ‘components.yaml’ | + | |
- | + | ||
- | components.yaml | + | |
- | + | ||
- | 2020-12-11 12:18:05 (162 MB/s) - ‘components.yaml’ saved [3962/ | + | |
- | </ | + | |
- | + | ||
- | Modifiez la section **containers** du fichier **components.yaml** : | + | |
- | + | ||
- | < | + | |
- | root@debian10: | + | |
- | root@debian10: | + | |
- | ... | + | |
- | spec: | + | |
- | containers: | + | |
- | - args: | + | |
- | - --cert-dir=/ | + | |
- | - --secure-port=4443 | + | |
- | - --kubelet-insecure-tls | + | |
- | - --kubelet-preferred-address-types=InternalIP, | + | |
- | - --kubelet-use-node-status-port | + | |
- | ... | + | |
- | </ | + | |
- | + | ||
- | Déployez le serveur Metrics : | + | |
- | + | ||
- | < | + | |
- | root@debian10: | + | |
- | serviceaccount/ | + | |
- | 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/ | + | |
- | </ | + | |
- | + | ||
- | Vérifiez l' | + | |
- | + | ||
- | < | + | |
- | root@debian10: | + | |
- | NAMESPACE | + | |
- | kube-system | + | |
- | kube-system | + | |
- | local-path-storage | + | |
- | </ | + | |
- | + | ||
- | Pour connaître l' | + | |
- | + | ||
- | < | + | |
- | root@debian10: | + | |
- | NAME | + | |
- | kind-control-plane | + | |
- | kind-worker | + | |
- | kind-worker2 | + | |
- | kind-worker3 | + | |
- | </ | + | |
- | + | ||
- | Pour voir l' | + | |
- | + | ||
- | < | + | |
- | root@debian10: | + | |
- | Every 2.0s: kubectl top nodes | + | |
- | + | ||
- | NAME | + | |
- | kind-control-plane | + | |
- | kind-worker | + | |
- | kind-worker2 | + | |
- | kind-worker3 | + | |
- | ... | + | |
- | ^C | + | |
- | </ | + | |
- | + | ||
- | <WRAP center round important 40%> | + | |
- | **Important** : Notez l' | + | |
</ | </ | ||
- | ===Les Commandes cordon et uncordon=== | + | Créez maintenant le fichier |
- | + | ||
- | Afin d' | + | |
< | < | ||
- | root@debian10:~# kubectl cordon | + | root@kubemaster:~# vi flask.yaml |
- | node/kind-worker cordoned | + | root@kubemaster: |
+ | apiVersion: v1 | ||
+ | kind: Namespace | ||
+ | metadata: | ||
+ | name: flask | ||
+ | --- | ||
+ | apiVersion: v1 | ||
+ | kind: ServiceAccount | ||
+ | metadata: | ||
+ | name: flask-backend | ||
+ | namespace: flask | ||
+ | --- | ||
+ | kind: Role | ||
+ | apiVersion: rbac.authorization.k8s.io/v1 | ||
+ | metadata: | ||
+ | name: flask-backend-role | ||
+ | namespace: flask | ||
+ | rules: | ||
+ | - apiGroups: ["" | ||
+ | resources: [" | ||
+ | verbs: [" | ||
+ | --- | ||
+ | kind: RoleBinding | ||
+ | apiVersion: rbac.authorization.k8s.io/ | ||
+ | metadata: | ||
+ | name: flask-backend-role-binding | ||
+ | namespace: flask | ||
+ | subjects: | ||
+ | - kind: ServiceAccount | ||
+ | name: flask-backend | ||
+ | namespace: flask | ||
+ | roleRef: | ||
+ | kind: Role | ||
+ | name: flask-backend-role | ||
+ | apiGroup: rbac.authorization.k8s.io | ||
</ | </ | ||
- | Consultez la ligne **Unschedulable: | + | Ce fichier crée : |
- | < | + | * un Namespace appelé **flask**, |
- | root@debian10: | + | * un serviceAccount appelé **flask-backend** pour le Namespace **flask**, |
- | Unschedulable: | + | * un Role appelé **flask-backend-role** qui accorde les permissions **get**, **watch** et **list** sur les pods dans le Namespace **flask**, |
- | </ | + | * un RoleBinding appelé **flask-backend-role-binding** qui accorde les permissions définies dans le Role **flask-backend-role** au Subject de type serviceAccount appelé **flask-backend**. |
- | <WRAP center round important 40%> | + | Appliquez |
- | **Important** : Dans le cas d'un cluster à plusieurs nœuds, si le nœud concerné par la commande kubectl cordon redémarre, tous les pods seront ré-alloués aux autres nœuds. | + | |
- | </ | + | |
- | + | ||
- | Pour autoriser de nouveau un nœud à recevoir de nouveaux pods, utilisez la commande **uncordon** | + | |
< | < | ||
- | root@debian10:~# kubectl | + | root@kubemaster:~# kubectl |
- | node/kind-worker uncordoned | + | namespace/flask created |
- | root@debian10: | + | serviceaccount/ |
- | Unschedulable: | + | role.rbac.authorization.k8s.io/ |
+ | rolebinding.rbac.authorization.k8s.io/ | ||
</ | </ | ||
- | ===La Commande drain === | + | Créez maintenant le fichier |
- | + | ||
- | La commande | + | |
- | + | ||
- | Commencez par constater quels pods sont sur le nœud | + | |
< | < | ||
- | root@debian10:~# kubectl get pods --all-namespaces -o wide | + | root@kubemaster:~# vi deployment.yaml |
- | NAMESPACE | + | root@kubemaster:~# cat deployment.yaml |
- | 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 | + | |
- | kube-system | + | |
- | kube-system | + | |
- | local-path-storage | + | |
- | </ | + | |
- | + | ||
- | <WRAP center round important 40%> | + | |
- | **Important** : Dans le cas ci-dessus les pods **kindnet-5dk8c**, | + | |
- | </ | + | |
- | + | ||
- | Utilisez la commande drain pour expulser les pods sur le nœud **kind-worker** : | + | |
- | + | ||
- | < | + | |
- | root@debian10: | + | |
- | node/ | + | |
- | WARNING: ignoring DaemonSet-managed Pods: kube-system/ | + | |
- | evicting pod kube-system/ | + | |
- | pod/ | + | |
- | node/ | + | |
- | </ | + | |
- | + | ||
- | Constatez de nouveau quels pods sont sur le nœud **kind-worker** : | + | |
- | + | ||
- | < | + | |
- | root@debian10: | + | |
- | NAMESPACE | + | |
- | 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 | + | |
- | kube-system | + | |
- | kube-system | + | |
- | local-path-storage | + | |
- | </ | + | |
- | + | ||
- | <WRAP center round important 40%> | + | |
- | **Important** : Notez que seul le pod **metrics-server-594b87569-9fcsq** a été expulsé. En effet les deux pods **kube-proxy-nrkql** et **kindnet-5dk8c** ont été créés par des DaemonSets. Un DaemonSet ne peut pas être supprimé d'un nœud Kubernetes, d'où l' | + | |
- | </ | + | |
- | + | ||
- | Constatez maintenant l' | + | |
- | + | ||
- | < | + | |
- | root@debian10: | + | |
- | NAME | + | |
- | kind-control-plane | + | |
- | kind-worker | + | |
- | kind-worker2 | + | |
- | kind-worker3 | + | |
- | </ | + | |
- | + | ||
- | <WRAP center round important 40%> | + | |
- | **Important** : Notez la présence de **SchedulingDisabled** dans la colonne **STATUS**. | + | |
- | </ | + | |
- | + | ||
- | ===La Commande delete === | + | |
- | + | ||
- | Pour supprimer un nœud du cluster, utilisez la commande **delete** : | + | |
- | + | ||
- | < | + | |
- | root@debian10: | + | |
- | node " | + | |
- | </ | + | |
- | + | ||
- | En saisissant la commande **get nodes**, vous constaterez que le nœud semble avoir été supprimé : | + | |
- | + | ||
- | < | + | |
- | root@debian10: | + | |
- | NAME | + | |
- | kind-control-plane | + | |
- | kind-worker2 | + | |
- | kind-worker3 | + | |
- | </ | + | |
- | + | ||
- | En réalité, le nœud n'est pas supprimé tant que tous les pods du nœud n'ont pas été détruits : | + | |
- | + | ||
- | < | + | |
- | root@debian10: | + | |
- | NAMESPACE | + | |
- | 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 | + | |
- | kube-system | + | |
- | kube-system | + | |
- | local-path-storage | + | |
- | </ | + | |
- | + | ||
- | Après la destruction des pods, le nœud est effectivement détruit : | + | |
- | + | ||
- | < | + | |
- | root@debian10: | + | |
- | NAMESPACE | + | |
- | 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 | + | |
- | local-path-storage | + | |
- | </ | + | |
- | + | ||
- | ====1.5 - Gestion des Applications==== | + | |
- | + | ||
- | ===La Commande expose=== | + | |
- | + | ||
- | Créez un deployment à partir de l' | + | |
- | + | ||
- | < | + | |
- | root@debian10: | + | |
- | deployment.apps/nginx created | + | |
- | root@debian10: | + | |
- | NAME READY | + | |
- | nginx | + | |
- | root@debian10: | + | |
- | NAME | + | |
- | nginx-6799fc88d8-sgc8w | + | |
- | </ | + | |
- | + | ||
- | Exposez maintenant le port 80 du pod grâce à la commande **expose** : | + | |
- | + | ||
- | < | + | |
- | root@debian10: | + | |
- | service/ | + | |
- | root@debian10: | + | |
- | Name: nginx | + | |
- | Namespace: | + | |
- | Labels: | + | |
- | Annotations: | + | |
- | Selector: | + | |
- | Type: ClusterIP | + | |
- | IP Families: | + | |
- | IP: 10.96.114.21 | + | |
- | IPs: < | + | |
- | Port: < | + | |
- | TargetPort: | + | |
- | Endpoints: | + | |
- | Session Affinity: | + | |
- | Events: | + | |
- | </ | + | |
- | + | ||
- | ===La Commande get=== | + | |
- | + | ||
- | Visualisez le service avec la commande **get** : | + | |
- | + | ||
- | < | + | |
- | root@debian10: | + | |
- | NAME | + | |
- | kubernetes | + | |
- | nginx ClusterIP | + | |
- | </ | + | |
- | + | ||
- | La commande **get** peut être utilisée pour créer une fichier au format YAML pour une création ultérieure du service : | + | |
- | + | ||
- | < | + | |
- | root@debian10: | + | |
- | root@debian10:~# cat service.yaml | + | |
- | apiVersion: v1 | + | |
- | kind: Service | + | |
- | metadata: | + | |
- | creationTimestamp: | + | |
- | labels: | + | |
- | app: nginx | + | |
- | managedFields: | + | |
- | | + | |
- | fieldsType: FieldsV1 | + | |
- | fieldsV1: | + | |
- | f: | + | |
- | f:labels: | + | |
- | .: {} | + | |
- | f:app: {} | + | |
- | f:spec: | + | |
- | f:ports: | + | |
- | .: {} | + | |
- | k: | + | |
- | .: {} | + | |
- | f:port: {} | + | |
- | f:protocol: {} | + | |
- | f: | + | |
- | f: | + | |
- | .: {} | + | |
- | f:app: {} | + | |
- | f: | + | |
- | f:type: {} | + | |
- | manager: kubectl-expose | + | |
- | operation: Update | + | |
- | time: " | + | |
- | name: nginx | + | |
- | namespace: default | + | |
- | resourceVersion: | + | |
- | selfLink: / | + | |
- | uid: 4ef7c806-d88b-43fb-b53c-2bf418583290 | + | |
- | spec: | + | |
- | clusterIP: 10.96.114.21 | + | |
- | ports: | + | |
- | - port: 80 | + | |
- | protocol: TCP | + | |
- | targetPort: 80 | + | |
- | selector: | + | |
- | app: nginx | + | |
- | sessionAffinity: | + | |
- | type: ClusterIP | + | |
- | status: | + | |
- | loadBalancer: | + | |
- | </ | + | |
- | + | ||
- | La commande **get** peut aussi être utilisée pour créer une fichier au format YAML pour une création ultérieure du deployment : | + | |
- | + | ||
- | < | + | |
- | root@debian10: | + | |
- | root@debian10: | + | |
apiVersion: apps/v1 | apiVersion: apps/v1 | ||
- | kind: Deployment | + | kind: Deployment |
metadata: | metadata: | ||
- | | + | |
- | | + | |
- | creationTimestamp: | + | |
- | | + | |
labels: | labels: | ||
- | app: nginx | + | app: myapp |
- | managedFields: | + | type: front-end |
- | - apiVersion: apps/v1 | + | |
- | | + | |
- | fieldsV1: | + | |
- | f: | + | |
- | f:labels: | + | |
- | .: {} | + | |
- | f:app: {} | + | |
- | f:spec: | + | |
- | f: | + | |
- | f:replicas: {} | + | |
- | f: | + | |
- | f: | + | |
- | f: | + | |
- | .: {} | + | |
- | f:app: {} | + | |
- | f: | + | |
- | f: | + | |
- | .: {} | + | |
- | f:maxSurge: {} | + | |
- | f: | + | |
- | f:type: {} | + | |
- | f: | + | |
- | f: | + | |
- | f:labels: | + | |
- | .: {} | + | |
- | f:app: {} | + | |
- | f:spec: | + | |
- | f: | + | |
- | k: | + | |
- | .: {} | + | |
- | f:image: {} | + | |
- | f: | + | |
- | f:name: {} | + | |
- | f: | + | |
- | f: | + | |
- | f: | + | |
- | f: | + | |
- | f: | + | |
- | f: | + | |
- | f: | + | |
- | f: | + | |
- | manager: kubectl-create | + | |
- | operation: Update | + | |
- | time: " | + | |
- | - apiVersion: apps/v1 | + | |
- | fieldsType: FieldsV1 | + | |
- | fieldsV1: | + | |
- | f: | + | |
- | f: | + | |
- | .: {} | + | |
- | f: | + | |
- | f:status: | + | |
- | f: | + | |
- | f: | + | |
- | .: {} | + | |
- | k: | + | |
- | .: {} | + | |
- | f: | + | |
- | f: | + | |
- | f:message: {} | + | |
- | f:reason: {} | + | |
- | f:status: {} | + | |
- | f:type: {} | + | |
- | k: | + | |
- | .: {} | + | |
- | f: | + | |
- | f: | + | |
- | f:message: {} | + | |
- | f:reason: {} | + | |
- | f:status: {} | + | |
- | f:type: {} | + | |
- | f: | + | |
- | f: | + | |
- | f:replicas: {} | + | |
- | f: | + | |
- | manager: kube-controller-manager | + | |
- | operation: Update | + | |
- | time: " | + | |
- | name: nginx | + | |
- | namespace: default | + | |
- | resourceVersion: | + | |
- | selfLink: / | + | |
- | uid: ebd84992-0957-460e-bbdb-ab9a8e80f099 | + | |
spec: | spec: | ||
- | progressDeadlineSeconds: | ||
- | replicas: 1 | ||
- | revisionHistoryLimit: | ||
- | selector: | ||
- | matchLabels: | ||
- | app: nginx | ||
- | strategy: | ||
- | rollingUpdate: | ||
- | maxSurge: 25% | ||
- | maxUnavailable: | ||
- | type: RollingUpdate | ||
template: | template: | ||
+ | |||
metadata: | metadata: | ||
- | | + | |
labels: | labels: | ||
- | app: nginx | + | app: myapp |
+ | type: front-end | ||
spec: | spec: | ||
+ | serviceAccount: | ||
containers: | containers: | ||
- | - image: nginx | + | - name: nginx-container |
- | imagePullPolicy: | + | |
- | | + | |
- | resources: {} | + | |
- | terminationMessagePath: | + | |
- | | + | |
- | dnsPolicy: ClusterFirst | + | |
- | restartPolicy: | + | |
- | schedulerName: | + | |
- | securityContext: | + | |
- | terminationGracePeriodSeconds: | + | |
- | status: | + | |
- | availableReplicas: | + | |
- | conditions: | + | |
- | - lastTransitionTime: | + | |
- | lastUpdateTime: | + | |
- | message: Deployment has minimum availability. | + | |
- | reason: MinimumReplicasAvailable | + | |
- | status: " | + | |
- | type: Available | + | |
- | - lastTransitionTime: | + | |
- | lastUpdateTime: | + | |
- | message: ReplicaSet "nginx-6799fc88d8" | + | |
- | reason: NewReplicaSetAvailable | + | |
- | status: " | + | |
- | type: Progressing | + | |
- | observedGeneration: | + | |
- | readyReplicas: | + | |
- | replicas: 1 | + | |
- | updatedReplicas: | + | |
- | </ | + | |
- | Éditez le fichier **deployment.yaml** pour augmenter le nombre de replicas : | ||
- | |||
- | < | ||
- | root@debian10: | ||
- | root@debian10: | ||
- | .. | ||
- | spec: | ||
- | progressDeadlineSeconds: | ||
replicas: 3 | replicas: 3 | ||
- | .. | + | selector: |
+ | matchLabels: | ||
+ | type: front-end | ||
</ | </ | ||
- | Appliquez le fichier deployment.yaml | + | Exécutez kubectl |
< | < | ||
- | root@debian10:~# kubectl | + | root@kubemaster:~# kubectl |
- | Warning: resource deployments/ | + | deployment.apps/myapp-deployment |
- | deployment.apps/ | + | |
</ | </ | ||
- | Vérifiez | + | Vérifiez |
< | < | ||
- | root@debian10:~# kubectl get deployment | + | root@kubemaster:~# kubectl get deployment |
- | NAME READY | + | NAME |
- | nginx 3/3 | + | myapp-deployment |
- | root@debian10: | + | |
- | NAME | + | |
- | nginx-6799fc88d8-gg4gt | + | |
- | nginx-6799fc88d8-qs8bq | + | |
- | nginx-6799fc88d8-sgc8w | + | |
</ | </ | ||
- | ===La Commande set=== | + | Vérifiez maintenant que le serviceAccount |
- | + | ||
- | Utilisez la commande | + | |
< | < | ||
- | root@debian10:~# kubectl | + | root@kubemaster:~# kubectl |
- | deployment.apps/ | + | yes |
</ | </ | ||
- | Vérifiez l'utilisation de l' | + | Notez cependant que le serviceAccount **flask-backend** n'a pas la permission **create** dans le Namespace |
< | < | ||
- | root@debian10:~# kubectl | + | root@kubemaster:~# kubectl |
- | Name: | + | no |
- | Namespace: | + | |
- | CreationTimestamp: | + | |
- | Labels: | + | |
- | Annotations: | + | |
- | kubernetes.io/ | + | |
- | Selector: app=nginx | + | |
- | Replicas: 3 desired | 1 updated | 4 total | 3 available | 1 unavailable | + | |
- | StrategyType: RollingUpdate | + | |
- | MinReadySeconds: | + | |
- | RollingUpdateStrategy: | + | |
- | Pod Template: | + | |
- | Labels: | + | |
- | Containers: | + | |
- | | + | |
- | Image: | + | |
- | Port: < | + | |
- | Host Port: < | + | |
- | Environment: | + | |
- | Mounts: | + | |
- | Volumes: | + | |
- | Conditions: | + | |
- | Type | + | |
- | ---- | + | |
- | | + | |
- | Progressing | + | |
- | OldReplicaSets: | + | |
- | NewReplicaSet: | + | |
- | Events: | + | |
- | Type Reason | + | |
- | ---- ------ | + | |
- | Normal | + | |
- | Normal | + | |
- | Normal | + | |
- | Normal | + | |
- | Normal | + | |
- | Normal | + | |
- | Normal | + | |
- | Normal | + | |
</ | </ | ||
- | <WRAP center round important 40%> | + | et que le serviceAccount |
- | **Important** : Notez la ligne **Image: | + | |
- | </ | + | |
- | + | ||
- | Comme attendu, la commande **set** n'a pas mis à jour le fichier | + | |
< | < | ||
- | root@debian10:~$ cat deployment.yaml | + | root@kubemaster:~# kubectl auth can-i list pods -n default |
- | ... | + | no |
- | spec: | + | |
- | containers: | + | |
- | | + | |
- | imagePullPolicy: | + | |
- | name: nginx | + | |
- | resources: {} | + | |
- | terminationMessagePath: | + | |
- | terminationMessagePolicy: | + | |
- | ... | + | |
- | </ | + | |
- | + | ||
- | Mettez donc à jour le fichier : | + | |
- | + | ||
- | < | + | |
- | root@debian10: | + | |
- | root@debian10: | + | |
- | ... | + | |
- | spec: | + | |
- | containers: | + | |
- | | + | |
- | imagePullPolicy: Always | + | |
- | name: nginx | + | |
- | resources: {} | + | |
- | terminationMessagePath: | + | |
- | terminationMessagePolicy: | + | |
- | ... | + | |
</ | </ | ||
- | ===La Commande rollout=== | + | ====1.4 - Création d'un Utilisateur==== |
- | Vérifiez | + | Les utilisateurs font partis du contexte de configuration qui définit le nom du cluster et le nom du Namespace |
< | < | ||
- | root@debian10:~# kubectl | + | root@kubemaster:~# kubectl |
- | deployment " | + | CURRENT |
+ | * | ||
</ | </ | ||
- | Faites un roll back : | + | <WRAP center round important> |
+ | **Important** | ||
+ | </ | ||
- | < | + | En regardant le contexte courant, on voit que l' |
- | root@debian10:~# kubectl rollout undo deployment nginx | + | |
- | deployment.apps/ | + | |
- | </ | + | |
- | Vérifiez maintenant le statut du deployment avec la commande **describe** : | + | |
+ | | ||
< | < | ||
- | root@debian10:~# kubectl | + | root@kubemaster:~# kubectl |
- | Name: nginx | + | apiVersion: v1 |
- | Namespace: | + | clusters: |
- | CreationTimestamp: Fri, 11 Dec 2020 15:54:24 +0100 | + | - cluster: |
- | Labels: app=nginx | + | certificate-authority-data: DATA+OMITTED |
- | Annotations: | + | |
- | Selector: | + | |
- | Replicas: | + | contexts: |
- | StrategyType: | + | - context: |
- | MinReadySeconds: | + | |
- | RollingUpdateStrategy: | + | |
- | Pod Template: | + | name: kubernetes-admin@kubernetes |
- | | + | current-context: kubernetes-admin@kubernetes |
- | | + | kind: Config |
- | nginx: | + | preferences: {} |
- | | + | users: |
- | | + | - name: kubernetes-admin |
- | Host Port: < | + | |
- | | + | |
- | | + | |
- | | + | |
- | Conditions: | + | |
- | | + | |
- | ---- | + | |
- | | + | |
- | | + | |
- | OldReplicaSets: | + | |
- | NewReplicaSet: | + | |
- | Events: | + | |
- | | + | |
- | | + | |
- | Normal | + | |
- | Normal | + | |
- | Normal | + | |
- | Normal | + | |
- | Normal | + | |
- | Normal | + | |
- | Normal | + | |
- | Normal | + | |
- | Normal | + | |
- | Normal | + | |
- | Normal | + | |
- | Normal | + | |
</ | </ | ||
- | <WRAP center round important | + | <WRAP center round important> |
- | **Important** : Notez la ligne **Image: | + | **Important** : Le mot **REDACTED** indique que les valeurs sont cachées pour des raisons de sécurité. |
</ | </ | ||
- | Consultez | + | Pour créer un nouveau utilisateur il faut commencer par créer une clef privée pour l'utilisateur |
< | < | ||
- | root@debian10:~# kubectl rollout history deployment nginx | + | root@kubemaster:~# openssl genrsa -out trainee.key 2048 |
- | deployment.apps/ | + | Generating RSA private key, 2048 bit long modulus |
- | REVISION | + | ....................................+++ |
- | 2 | + | ..............+++ |
- | 3 < | + | e is 65537 (0x10001) |
</ | </ | ||
- | Revenez à la révision numéro **2** : | + | Créez maintenant un CSR : |
< | < | ||
- | root@debian10:~# kubectl rollout undo deployment nginx --to-revision=2 | + | root@kubemaster:~# openssl req -new -key trainee.key |
- | deployment.apps/nginx rolled back | + | |
- | root@debian10: | + | |
- | Name: | + | |
- | Namespace: | + | |
- | CreationTimestamp: | + | |
- | Labels: | + | |
- | Annotations: | + | |
- | kubernetes.io/ | + | |
- | Selector: | + | |
- | Replicas: | + | |
- | StrategyType: | + | |
- | MinReadySeconds: | + | |
- | RollingUpdateStrategy: | + | |
- | Pod Template: | + | |
- | Labels: | + | |
- | Containers: | + | |
- | | + | |
- | Image: | + | |
- | Port: < | + | |
- | Host Port: < | + | |
- | Environment: | + | |
- | Mounts: | + | |
- | Volumes: | + | |
- | Conditions: | + | |
- | Type | + | |
- | ---- | + | |
- | Available | + | |
- | Progressing | + | |
- | OldReplicaSets: | + | |
- | NewReplicaSet: | + | |
- | Events: | + | |
- | Type Reason | + | |
- | ---- ------ | + | |
- | Normal | + | |
- | Normal | + | |
- | Normal | + | |
- | Normal | + | |
- | Normal | + | |
- | Normal | + | |
- | Normal | + | |
- | Normal | + | |
- | Normal | + | |
- | Normal | + | |
- | Normal | + | |
- | Normal | + | |
</ | </ | ||
- | <WRAP center round important | + | <WRAP center round important> |
- | **Important** : Notez la ligne **Image: | + | **Important** : Notez que Kubernetes utilisera |
</ | </ | ||
- | ===La Commande delete=== | + | Le CSR doit être signé par le CA racine de Kubernetes |
- | + | ||
- | Supprimez maintenant | + | |
< | < | ||
- | root@debian10:~# kubectl delete deployment nginx | + | root@kubemaster:~# ls -l / |
- | deployment.apps " | + | -rw-r--r-- 1 root root 1099 juil. 12 13:23 / |
- | root@debian10:~# kubectl get deployments | + | -rw------- 1 root root 1679 juil. 12 13:23 / |
- | No resources found in default namespace. | + | |
</ | </ | ||
- | ====1.6 - Déboguer une Application==== | + | Signez |
- | + | ||
- | Vous venez de supprimer le deployment **nginx**. Créez | + | |
< | < | ||
- | root@debian10:~# vi deployment-postgresql.yaml | + | root@kubemaster:~# openssl x509 -req -in trainee.csr -CA / |
- | root@debian10: | + | Signature ok |
- | apiVersion: apps/v1 | + | subject=/ |
- | kind: Deployment | + | Getting CA Private Key |
- | metadata: | + | |
- | name: postgresql | + | |
- | labels: | + | |
- | app: postgresql | + | |
- | spec: | + | |
- | replicas: 1 | + | |
- | selector: | + | |
- | matchLabels: | + | |
- | app: postgresql | + | |
- | template: | + | |
- | metadata: | + | |
- | labels: | + | |
- | app: postgresql | + | |
- | spec: | + | |
- | containers: | + | |
- | | + | |
- | | + | |
- | name: postgresql | + | |
</ | </ | ||
- | Deployez ensuite l' | + | Visualisez le certificat de trainee |
< | < | ||
- | oot@debian10:~# kubectl apply -f deployment-postgresql.yaml | + | root@kubemaster:~# openssl x509 -in trainee.crt -text |
- | deployment.apps/postgresql created | + | Certificate: |
+ | Data: | ||
+ | Version: 1 (0x0) | ||
+ | Serial Number: | ||
+ | b6: | ||
+ | Signature Algorithm: sha256WithRSAEncryption | ||
+ | Issuer: CN = kubernetes | ||
+ | Validity | ||
+ | Not Before: Jul 14 07:49:14 2022 GMT | ||
+ | Not After : Aug 13 07:49:14 2022 GMT | ||
+ | Subject: CN = trainee, O = examplegroup | ||
+ | Subject Public Key Info: | ||
+ | Public Key Algorithm: rsaEncryption | ||
+ | Public-Key: (2048 bit) | ||
+ | Modulus: | ||
+ | 00: | ||
+ | 64: | ||
+ | ee: | ||
+ | 38: | ||
+ | cb: | ||
+ | 58: | ||
+ | 06: | ||
+ | 82: | ||
+ | 37: | ||
+ | b5: | ||
+ | d2: | ||
+ | 29: | ||
+ | c2: | ||
+ | 11: | ||
+ | 19: | ||
+ | 06: | ||
+ | 48: | ||
+ | 69:69 | ||
+ | Exponent: 65537 (0x10001) | ||
+ | Signature Algorithm: sha256WithRSAEncryption | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | -----BEGIN CERTIFICATE----- | ||
+ | MIICujCCAaICCQC291mPdRm8EDANBgkqhkiG9w0BAQsFADAVMRMwEQYDVQQDEwpr | ||
+ | dWJlcm5ldGVzMB4XDTIyMDcxNDA3NDkxNFoXDTIyMDgxMzA3NDkxNFowKTEQMA4G | ||
+ | A1UEAwwHdHJhaW5lZTEVMBMGA1UECgwMZXhhbXBsZWdyb3VwMIIBIjANBgkqhkiG | ||
+ | 9w0BAQEFAAOCAQ8AMIIBCgKCAQEAmy3ofbrpn7PajxQTIYNkxm57LO5P5nFlp+TK | ||
+ | aiPuz+FDGOCwH+// | ||
+ | 9sJRfEKVFqxgDh1NCaoGKVF58UVwSLkc4gX8XDOC14JfojETtSNMEL+lik83KtbM | ||
+ | rMfArZdxlZ4mT2C1QYp7xXk4AiiwiIQjCxjSwvmf/ | ||
+ | z1ZeqboG2IPCPB04zPr9aRdOw3553TQRmv9dMuRoqA/ | ||
+ | n+Stv98GyCjHpHjyMbJsx56QuL9I1K79Zek4/ | ||
+ | SIb3DQEBCwUAA4IBAQBtyA3NfDRcCGeYtq6AJuhz8RQ7AgndtG3xf7sSihaG1ta+ | ||
+ | rZKZqCOh197U6QPsb7kZRi3Y9DBxjPBuQ63YEEYVq59GwVZMbIGrut1beGpXgtMa | ||
+ | 1xpfY8pOD/ | ||
+ | DM6HkZwl93KnRJ02QYdIYXExmiSuNk9AyPMIMvWxnfWKCnGA5nDZr+GWVYGfoZU5 | ||
+ | U7Ub8zc+UNWha9FL0cZ1+2PwYwbOmfvDFcFRO+3ZyGhDZjzvkrqupQ0CSI1CGnAi | ||
+ | E3VHrWnVSBFrsSSAftYN95IMuyiRbtRMoRTJLUcs | ||
+ | -----END CERTIFICATE----- | ||
</ | </ | ||
- | En consultant le pod créé, vous verrez qu'il y a une erreur de type **ErrImagePull** | + | Créez un deuxième utilisateur dans la même Organisation |
< | < | ||
- | root@debian10:~# kubectl get pods | + | root@kubemaster:~# openssl genrsa -out stagiaire.key 2048 |
- | NAME READY | + | Generating RSA private key, 2048 bit long modulus |
- | postgresql-586d47479b-kf24b | + | ................................................................................................................................+++ |
- | </ | + | .................+++ |
+ | e is 65537 (0x10001) | ||
- | Consultez la section **Events** de la sortie de la commande **describe** pour voir ce que se passe : | + | root@kubemaster:~# openssl req -new -key stagiaire.key -out stagiaire.csr -subj "/ |
- | < | + | root@kubemaster:~# openssl x509 -req -in stagiaire.csr -CA /etc/kubernetes/pki/ca.crt -CAkey |
- | root@debian10:~# kubectl describe pod postgresql-586d47479b-kf24b | + | Signature ok |
- | ... | + | subject=/CN=stagiaire/ |
- | Events: | + | Getting CA Private Key |
- | Type | + | |
- | | + | |
- | Normal | + | |
- | Normal | + | |
- | Warning | + | |
- | | + | |
- | | + | |
- | | + | |
</ | </ | ||
- | Comme vous pouvez constater, il existe trois avertissements | + | Créez maintenant |
- | + | ||
- | < | + | |
- | Warning | + | |
- | Warning | + | |
- | Normal | + | |
- | Warning | + | |
- | </ | + | |
- | + | ||
- | Le premier des trois avertissements nous dit clairement qu'il y a un problème au niveau du tag de l' | + | |
- | + | ||
- | Modifiez donc le tage dans ce fichier à ** 10.13.0** : | + | |
< | < | ||
- | root@debian10:~# vi deployment-postgresql.yaml | + | root@kubemaster:~# kubectl config set-credentials trainee --client-certificate=trainee.crt --client-key=trainee.key |
- | root@debian10: | + | User " |
- | 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/ | + | |
- | imagePullPolicy: | + | |
- | name: postgresql | + | |
- | </ | + | |
- | Appliquez maintenant le fichier : | + | root@kubemaster:~# kubectl |
- | + | Context " | |
- | < | + | |
- | root@debian10:~# kubectl | + | |
- | deployment.apps/ | + | |
</ | </ | ||
- | En consultant | + | Vérifiez que le contexte soit présent |
< | < | ||
- | root@debian10:~# kubectl get pods | + | root@kubemaster:~# kubectl |
- | NAME | + | CURRENT |
- | postgresql-586d47479b-kf24b | + | * |
- | postgresql-5cc57c477d-dr7nx | + | |
- | root@debian10:~# kubectl get pods | + | |
- | NAME READY | + | |
- | postgresql-586d47479b-kf24b | + | |
- | postgresql-5cc57c477d-dr7nx | + | |
- | root@debian10:~# kubectl get pods | + | |
- | NAME READY | + | |
- | postgresql-586d47479b-kf24b | + | |
- | postgresql-5cc57c477d-dr7nx | + | |
</ | </ | ||
- | Consultez la section **Events** | + | Utilisez le contexte |
< | < | ||
- | root@debian10:~# kubectl | + | root@kubemaster:~# kubectl |
- | ... | + | Switched |
- | Events: | + | |
- | Type | + | |
- | ---- | + | |
- | Normal | + | |
- | Normal | + | |
- | Normal | + | |
- | Normal | + | |
- | Normal | + | |
- | Normal | + | |
- | Warning | + | |
- | </ | + | |
- | Cette fois-ci, la section **Events** nous donne aucune indication concernant le problème ! | + | root@kubemaster:~# kubectl |
- | + | CURRENT | |
- | ===La Commande logs=== | + | |
- | + | * | |
- | Pour obtenir plus d' | + | |
- | + | root@kubemaster:~# kubectl get pods | |
- | < | + | Error from server (Forbidden): pods is forbidden: User " |
- | root@debian10:~# kubectl | + | |
- | postgresql 14: | + | |
- | postgresql 14:56:53.17 Welcome to the Bitnami postgresql container | + | |
- | postgresql 14:56:53.18 Subscribe to project updates by watching https:// | + | |
- | postgresql 14:56:53.18 Submit issues and feature requests at https:// | + | |
- | postgresql 14: | + | |
- | postgresql 14:56:53.21 INFO ==> ** Starting PostgreSQL setup ** | + | |
- | postgresql 14:56:53.23 INFO ==> Validating settings | + | |
- | postgresql 14:56:53.23 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. | + | |
- | postgresql 14:56:53.23 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. | + | |
</ | </ | ||
- | La sortie de la commande | + | <WRAP center round important> |
+ | **Important** : Notez que trainee ne peut pas lister les pods parce que les permissions RBAC n'ont pas été définies. | ||
+ | </ | ||
- | < | + | Retournez au contexte de l' |
- | ... | + | |
- | postgresql 14:56:53.23 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. | + | |
- | </ | + | |
- | + | ||
- | Mettez à jour donc le fichier **deployment-postgresql.yaml** | + | |
< | < | ||
- | root@debian10:~# vi deployment-postgresql.yaml | + | root@kubemaster:~# kubectl config use-context kubernetes-admin@kubernetes |
- | root@debian10:~# cat deployment-postgresql.yaml | + | Switched to context |
- | 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/ | + | |
- | imagePullPolicy: | + | |
- | name: postgresql | + | |
- | env: | + | |
- | - name: POSTGRESQL_PASSWORD | + | |
- | value: | + | |
- | </ | + | |
- | Appliquez la configuration : | + | root@kubemaster:~# kubectl |
- | + | CURRENT | |
- | < | + | * |
- | root@debian10:~# kubectl | + | |
- | deployment.apps/ | + | |
</ | </ | ||
- | Constatez l' | + | Créez maintenant un **clusterrolebinding** au groupe **examplegroup** |
< | < | ||
- | root@debian10:~# kubectl | + | root@kubemaster:~# kubectl |
- | NAME READY | + | clusterrolebinding.rbac.authorization.k8s.io/examplegroup-admin-binding created |
- | postgresql-6c99978556-kqkp4 | + | |
- | + | ||
- | root@debian10: | + | |
- | NAME | + | |
- | postgresql | + | |
</ | </ | ||
- | Utilisez | + | Utilisez de nouveau le contexte de trainee |
< | < | ||
- | root@debian10:~# kubectl | + | root@kubemaster:~# kubectl |
- | postgresql 14:58:48.79 | + | Switched |
- | postgresql 14:58:48.79 Welcome | + | |
- | postgresql 14:58:48.79 Subscribe to project updates by watching https:// | + | |
- | postgresql 14:58:48.79 Submit issues and feature requests at https:// | + | |
- | postgresql 14:58:48.79 | + | |
- | postgresql 14:58:48.81 INFO ==> ** Starting PostgreSQL setup ** | + | |
- | postgresql 14:58:48.83 INFO ==> Validating settings in POSTGRESQL_* env vars.. | + | |
- | postgresql 14:58:48.84 INFO ==> Loading custom pre-init scripts... | + | |
- | postgresql 14:58:48.85 INFO ==> Initializing PostgreSQL database... | + | |
- | postgresql 14:58:48.87 INFO ==> pg_hba.conf file not detected. Generating it... | + | |
- | postgresql 14:58:48.87 INFO ==> Generating local authentication configuration | + | |
- | postgresql 14:58:53.51 INFO ==> Starting PostgreSQL in background... | + | |
- | postgresql 14:58:53.64 INFO ==> Changing password of postgres | + | |
- | postgresql 14:58:53.66 INFO ==> Configuring replication parameters | + | |
- | postgresql 14:58:53.69 INFO ==> Configuring fsync | + | |
- | postgresql 14:58:53.70 INFO ==> Loading custom scripts... | + | |
- | postgresql 14:58:53.71 INFO ==> Enabling remote connections | + | |
- | postgresql 14:58:53.73 INFO ==> Stopping PostgreSQL... | + | |
- | postgresql 14:58:54.74 INFO ==> ** PostgreSQL setup finished! ** | + | |
- | postgresql 14:58:54.78 INFO ==> ** Starting PostgreSQL ** | + | root@kubemaster:~# kubectl config get-contexts |
- | 2020-12-12 14:58:54.819 GMT [1] LOG: listening on IPv4 address "0.0.0.0", port 5432 | + | CURRENT |
- | 2020-12-12 14: | + | |
- | 2020-12-12 14: | + | * |
- | 2020-12-12 14:58:54.843 GMT [106] LOG: database system was shut down at 2020-12-12 14:58:53 GMT | + | |
- | 2020-12-12 14:58:54.850 GMT [1] LOG: database system is ready to accept connections | + | root@kubemaster:~# kubectl get pods -n kube-system |
- | ^C | + | NAME READY |
+ | calico-kube-controllers-6766647d54-v4hrm | ||
+ | calico-node-5mrjl | ||
+ | calico-node-688lw | ||
+ | calico-node-j25xd | ||
+ | coredns-6d4b75cb6d-dw4ph | ||
+ | coredns-6d4b75cb6d-ms2jm | ||
+ | etcd-kubemaster.ittraining.loc 1/1 | ||
+ | kube-apiserver-kubemaster.ittraining.loc | ||
+ | kube-controller-manager-kubemaster.ittraining.loc | ||
+ | kube-proxy-bwctz 1/1 | ||
+ | kube-proxy-j89vg 1/1 | ||
+ | kube-proxy-jx76x | ||
+ | kube-scheduler-kubemaster.ittraining.loc | ||
+ | metrics-server-7cb867d5dc-g55k5 | ||
</ | </ | ||
- | <WRAP center round important 40%> | + | ====1.5 - Certificats TLS==== |
- | **Important** : Notez l' | + | |
- | </ | + | |
- | + | ||
- | ===La Commande exec=== | + | |
- | La commande **exec** peut être utilisée pour exécuter une commande à l'intérieur d'un conteneur | + | Par défaut la communication entre kubectl et l'API Kubernetes est cryptée. Les certificats se trouvent |
< | < | ||
- | root@debian10:~# kubectl exec postgresql-6c99978556-vcfmm -- cat /opt/bitnami/postgresql/conf/postgresql.conf | more | + | root@kubemaster:~# ls -l /var/lib/kubelet/pki/ |
- | root@debian10: | + | total 12 |
- | postgresql 14:58:48.79 | + | -rw------- 1 root root 2851 juil. 12 13:23 kubelet-client-2022-07-12-13-23-12.pem |
- | postgresql 14:58:48.79 Welcome to the Bitnami postgresql container | + | lrwxrwxrwx |
- | postgresql 14:58:48.79 Subscribe to project updates by watching https:// | + | -rw-r--r-- 1 root root 2367 juil. 12 13:23 kubelet.crt |
- | postgresql 14:58:48.79 Submit issues and feature requests at https:// | + | -rw------- |
- | postgresql 14:58:48.79 | + | |
- | postgresql 14:58:48.81 INFO ==> ** Starting PostgreSQL setup ** | + | |
- | postgresql 14:58:48.83 INFO ==> Validating settings in POSTGRESQL_* env vars.. | + | |
- | postgresql 14:58:48.84 INFO ==> Loading custom pre-init scripts... | + | |
- | postgresql 14:58:48.85 INFO ==> Initializing PostgreSQL database... | + | |
- | postgresql 14:58:48.87 INFO ==> pg_hba.conf file not detected. Generating it... | + | |
- | postgresql 14:58:48.87 INFO ==> Generating local authentication configuration | + | |
- | postgresql 14:58:53.51 INFO ==> Starting PostgreSQL in background... | + | |
- | postgresql 14:58:53.64 INFO ==> Changing password of postgres | + | |
- | postgresql 14:58:53.66 INFO ==> Configuring replication parameters | + | |
- | postgresql 14:58:53.69 INFO ==> Configuring fsync | + | |
- | postgresql 14:58:53.70 INFO ==> Loading custom scripts... | + | |
- | postgresql 14:58:53.71 INFO ==> Enabling remote connections | + | |
- | postgresql 14:58:53.73 INFO ==> Stopping PostgreSQL... | + | |
- | postgresql 14:58:54.74 INFO ==> ** PostgreSQL setup finished! ** | + | |
- | + | ||
- | postgresql 14:58:54.78 INFO ==> ** Starting PostgreSQL ** | + | |
- | 2020-12-12 14: | + | |
- | 2020-12-12 14:58:54.820 GMT [1] LOG: listening on IPv6 address "::", | + | |
- | 2020-12-12 14: | + | |
- | 2020-12-12 14: | + | |
- | 2020-12-12 14:58:54.850 GMT [1] LOG: database system is ready to accept connections | + | |
- | ^C | + | |
- | root@debian10:~# kubectl exec postgresql-6c99978556-vcfmm -- cat /opt/bitnami/postgresql/conf/postgresql.conf | more | + | |
- | # ----------------------------- | + | |
- | # PostgreSQL configuration file | + | |
- | # ----------------------------- | + | |
- | # | + | |
- | # This file consists of lines of the form: | + | |
- | # | + | |
- | # name = value | + | |
- | # | + | |
- | # (The " | + | |
- | # "#" | + | |
- | # 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. | + | |
- | # server for the changes to take effect, run " | + | |
- | # " | + | |
- | # 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., | + | |
- | # " | + | |
- | # with the " | + | |
- | # | + | |
- | # Memory units: | + | |
- | # MB = megabytes | + | |
- | # GB = gigabytes | + | |
- | # TB = terabytes | + | |
- | # | + | |
- | + | ||
- | + | ||
- | #------------------------------------------------------------------------------ | + | |
- | # FILE LOCATIONS | + | |
- | # | + | |
- | + | ||
- | # The default values of these variables are driven from the -D command-line | + | |
- | # option or PGDATA environment variable, represented here as ConfigDir. | + | |
- | + | ||
- | # | + | |
- | # (change requires restart) | + | |
- | --More-- | + | |
</ | </ | ||
- | La commande | + | <WRAP center round important> |
+ | **Important** : Par défaut les certificats de kubelet expirent au bout d'un an. | ||
+ | </ | ||
- | < | + | =====LAB |
- | root@debian10: | + | |
- | I have no name!@postgresql-6c99978556-vcfmm:/ | + | |
- | bin bitnami | + | |
- | I have no name!@postgresql-6c99978556-vcfmm:/ | + | |
- | exit | + | |
- | root@debian10: | + | |
- | </ | + | |
- | ====1.7 - Gérer les Plugins de kubectl==== | + | ==== 2.1 - Présentation |
- | Les plugins de kubectl étendent ses fonctionnalités. Le gestionnaire des plugins | + | Un **Admission Controller** est un morceau de code qui intercepte les requêtes à destination de l'API de Kubernetes. L' |
- | + | ||
- | ===La Commande krew=== | + | |
- | + | ||
- | Afin d' | + | |
- | + | ||
- | < | + | |
- | root@debian10: | + | |
- | </ | + | |
- | + | ||
- | Installez ensuite krew avec la commande suivante | + | |
< | < | ||
- | ( | + | --admission-control=Initializers, |
- | set -x; cd " | + | |
- | curl -fsSLO " | + | |
- | tar zxvf krew.tar.gz && | + | |
- | KREW=./ | + | |
- | " | + | |
- | ) | + | |
</ | </ | ||
- | < | + | Les Admission Controllers les plus importants en termes de sécurité sont : |
- | root@debian10:~# ( | + | |
- | > set -x; cd " | + | |
- | > curl -fsSLO " | + | |
- | > tar zxvf krew.tar.gz && | + | |
- | > | + | |
- | > " | + | |
- | > ) | + | |
- | </ | + | |
- | A la fin de l'installation, vous verrez | + | * **DenyEscalatingExec**, |
+ | * interdit | ||
+ | * **NodeRestriction**, | ||
+ | * limite les objets d'un nœud et d'un pod que kubectl est capable de modifier, | ||
+ | * **PodSecurityPolicy**, | ||
+ | * agit lors de la création ou de la modification d'un pod pour décider si celui-ci est admis au cluster en fonction du Contexte de Sécurité et les policies applicables, | ||
+ | * **ValidatingAdmissionWebhooks**, | ||
+ | * permet d' | ||
- | < | + | ====2.2 - Kubernetes Security Context==== |
- | ... | + | |
- | Installing plugin: krew | + | |
- | Installed plugin: krew | + | |
- | \ | + | |
- | | Use this plugin: | + | |
- | | + | |
- | | Documentation: | + | |
- | | + | |
- | | Caveats: | + | |
- | | \ | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | / | + | |
- | / | + | |
- | </ | + | |
- | Ensuite ajoutez **$HOME/.krew/bin** à votre PATH : | + | La configuration du Contexte de Sécurité se fait du pod ou du conteneur. Voici quelques exemples. |
- | < | + | ===ReadOnlyRootFilesystem=== |
- | root@debian10: | + | |
- | </ | + | |
- | Afin de ne pas avoir besoin de redéfinir | + | Créez |
< | < | ||
- | root@debian10:~# echo ' | + | root@kubemaster:~# vi readonly.yaml |
- | root@debian10:~# tail .bashrc | + | root@kubemaster:~# cat readonly.yaml |
- | # eval " | + | apiVersion: v1 |
- | # alias ls='ls $LS_OPTIONS' | + | kind: Pod |
- | # alias ll='ls $LS_OPTIONS -l' | + | metadata: |
- | # alias l='ls $LS_OPTIONS | + | name: flask-ro |
- | # | + | |
- | # Some more alias to avoid making mistakes: | + | spec: |
- | # alias rm='rm -i' | + | |
- | # alias cp=' | + | - image: mateobur/ |
- | # alias mv=' | + | name: flask-ro |
- | export PATH=" | + | |
+ | readOnlyRootFilesystem: true | ||
</ | </ | ||
- | Mettez à jour la liste des plugins | + | Exécutez kubectl |
< | < | ||
- | root@debian10:~# kubectl | + | root@kubemaster:~# kubectl |
- | Updated the local copy of plugin index. | + | pod/ |
</ | </ | ||
- | Pour visualiser la liste des plugins, utiisez la commande | + | Vérifiez que le pod est en état de **READY** : |
< | < | ||
- | root@debian10:~# kubectl | + | root@kubemaster:~# kubectl |
- | NAME | + | NAME READY |
- | access-matrix | + | flask-ro |
- | advise-psp | + | postgres-deployment-5b8bd66778-j99zz |
- | allctx | + | redis-deployment-67d4c466c4-9wzfn 1/1 |
- | apparmor-manager | + | result-app-deployment-b8f9dc967-nzbgd 1/1 |
- | auth-proxy | + | result-app-deployment-b8f9dc967-r84k6 1/1 |
- | bd-xray | + | result-app-deployment-b8f9dc967-zbsk2 1/1 |
- | bulk-action | + | voting-app-deployment-669dccccfb-jpn6h |
- | ca-cert | + | voting-app-deployment-669dccccfb-ktd7d 1/1 |
- | capture | + | voting-app-deployment-669dccccfb-x868p |
- | cert-manager | + | worker-app-deployment-559f7749b6-jh86r |
- | change-ns | + | |
- | cilium | + | |
- | cluster-group Exec commands across a group of contexts. | + | |
- | config-cleanup | + | |
- | config-registry | + | |
- | creyaml | + | |
- | cssh SSH into Kubernetes nodes no | + | |
- | ctx | + | |
- | custom-cols | + | |
- | datadog | + | |
- | debug | + | |
- | debug-shell | + | |
- | deprecations | + | |
- | df-pv Show disk usage (like unix df) for persistent v... no | + | |
- | doctor | + | |
- | duck List custom resources with ducktype support | + | |
- | edit-status | + | |
- | eksporter | + | |
- | emit-event | + | |
- | evict-pod | + | |
- | example | + | |
- | exec-as Like kubectl exec, but offers a `user` flag to ... no | + | |
- | exec-cronjob | + | |
- | fields | + | |
- | flame | + | |
- | fleet Shows config and resources of a fleet of clusters | + | |
- | 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 | + | |
- | hns | + | |
- | iexec | + | |
- | images | + | |
- | ingress-nginx | + | |
- | ipick A kubectl wrapper for interactive resource sele... | + | |
- | konfig | + | |
- | krew Package manager for kubectl plugins. | + | |
- | kubesec-scan Scan Kubernetes resources with kubesec.io. | + | |
- | kudo Declaratively build, install, and run operators... | + | |
- | kuttl | + | |
- | kyverno | + | |
- | match-name Match names of pods and other API objects | + | |
- | minio | + | |
- | modify-secret | + | |
- | mtail Tail logs from multiple pods matching label sel... | + | |
- | neat Remove clutter from Kubernetes manifests to mak... | + | |
- | net-forward | + | |
- | node-admin | + | |
- | node-restart | + | |
- | node-shell Spawn a root shell on a node via kubectl | + | |
- | np-viewer | + | |
- | ns Switch between Kubernetes namespaces | + | |
- | oidc-login Log in to the OpenID Connect provider | + | |
- | open-svc Open the Kubernetes URL(s) for the specified se... no | + | |
- | operator | + | |
- | oulogin | + | |
- | outdated | + | |
- | passman | + | |
- | pod-dive | + | |
- | pod-logs | + | |
- | pod-shell | + | |
- | podevents | + | |
- | popeye | + | |
- | preflight | + | |
- | profefe | + | |
- | prompt | + | |
- | prune-unused | + | |
- | psp-util Manage Pod Security Policy(PSP) and the related... | + | |
- | rabbitmq | + | |
- | rbac-lookup | + | |
- | rbac-view A tool to visualize your RBAC permissions. | + | |
- | reap Delete unused Kubernetes resources. | + | |
- | resource-capacity | + | |
- | resource-snapshot | + | |
- | restart | + | |
- | rm-standalone-pods Remove all pods without owner references | + | |
- | rolesum | + | |
- | roll Rolling restart of all persistent pods in a nam... | + | |
- | schemahero | + | |
- | score | + | |
- | service-tree | + | |
- | shovel | + | |
- | sick-pods | + | |
- | snap Delete half of the pods in a namespace or cluster | + | |
- | sniff Start a remote packet capture on pods using tcp... | + | |
- | sort-manifests | + | |
- | split-yaml Split YAML output into one file per resource. | + | |
- | spy pod debugging tool for kubernetes clusters with... | + | |
- | sql Query the cluster via pseudo-SQL no | + | |
- | ssh-jump A kubectl plugin to SSH into Kubernetes nodes u... no | + | |
- | sshd Run SSH server in a Pod no | + | |
- | ssm-secret | + | |
- | starboard | + | |
- | status | + | |
- | sudo Run Kubernetes commands impersonated as group s... no | + | |
- | support-bundle | + | |
- | tail Stream logs from multiple pods and containers u... no | + | |
- | tap | + | |
- | tmux-exec An exec multiplexer using Tmux no | + | |
- | topology | + | |
- | trace | + | |
- | tree Show a tree of object hierarchies through owner... | + | |
- | unused-volumes | + | |
- | view-allocations | + | |
- | view-cert View certificate information stored in secrets | + | |
- | view-secret | + | |
- | view-serviceaccount-kubeconfig | + | |
- | view-utilization | + | |
- | view-webhook | + | |
- | virt Control KubeVirt virtual machines using virtctl | + | |
- | warp Sync and execute local files in Pod no | + | |
- | who-can | + | |
- | whoami | + | |
</ | </ | ||
- | Installez les plugins **ctx**, **ns**, **view-allocations** et **pod-logs** | + | Connectez-vous au conteneur |
< | < | ||
- | root@debian10:~# kubectl | + | root@kubemaster:~# kubectl |
- | Updated the local copy of plugin index. | + | root@flask-ro:/# |
- | 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. Lister les contextes dans le cluster | + | Notez que le système est en lecture seule : |
< | < | ||
- | root@debian10:~# kubectl ctx | + | root@flask-ro:/# mount | grep "/ " |
- | kind-kind | + | overlay on / type overlay (ro, |
- | </code> | + | |
- | <WRAP center round tip 40%> | + | root@flask-ro:/# |
- | Un contexte est un élément qui regroupe les paramètres d'accès sous un nom. Les paramètres d'accès sont au nombre de trois, à savoir le cluster, le namespace et l' | + | touch: cannot touch 'test': Read-only file system |
- | </ | + | |
- | Le plugin **ns** permet de basculer entre les **namespaces** facilement. Lister les namespaces dans le cluster : | + | root@flask-ro:/# exit |
- | + | exit | |
- | < | + | command terminated with exit code 1 |
- | root@debian10:~# kubectl ns | + | |
- | default | + | |
- | kube-node-lease | + | |
- | kube-public | + | |
- | kube-system | + | |
- | local-path-storage | + | |
</ | </ | ||
- | <WRAP center round tip 40%> | + | ===drop=== |
- | Les Namespaces : | + | |
- | * peuvent être considérées comme des clusters virtuels, | + | |
- | * permettent l' | + | |
- | * permettent le regroupement d' | + | |
- | * sont utilisés avec des applications, | + | |
- | </ | + | |
- | Le plugin | + | Créez le fichier |
< | < | ||
- | root@debian10:~# kubectl view-allocations | + | root@kubemaster:~# vi drop.yaml |
- | | + | root@kubemaster: |
- | cpu 1.1 | + | apiVersion: v1 |
- | | + | kind: Pod |
- | | + | metadata: |
- | | + | |
- | │ ├─ kindnet-vrqzw | + | |
- | │ ├─ kube-apiserver-kind-control-plane | + | spec: |
- | | + | |
- | | + | - image: mateobur/ |
- | | + | name: flask-cap |
- | | + | |
- | | + | |
- | | + | |
- | | + | - NET_RAW |
- | | + | - CHOWN |
- | | + | |
- | | + | |
- | | + | |
- | ├─ kind-control-plane | + | |
- | | + | |
- | │ ├─ coredns-f9fd979d6-jwd68 | + | |
- | │ └─ kindnet-vrqzw | + | |
- | ├─ kind-worker2 | + | |
- | │ └─ kindnet-t8t9q 50.0Mi | + | |
- | | + | |
- | | + | |
- | pods 0.0 0% 0.0 0% 330.0 330.0 | + | |
- | ├─ kind-control-plane | + | |
- | ├─ kind-worker2 | + | |
- | └─ kind-worker3 | + | |
</ | </ | ||
- | Le plugin **pod-logs** vous fourni avec une liste de pods en cours d' | + | Exécutez kubectl |
< | < | ||
- | root@debian10:~# kubectl | + | root@kubemaster:~# kubectl |
- | 1) | + | pod/flask-cap created |
- | 2) | + | |
- | 3) | + | |
- | 4) | + | |
- | 5) | + | |
- | 6) | + | |
- | 7) | + | |
- | 8) | + | |
- | 9) | + | |
- | 10) kube-proxy-5zpkb | + | |
- | 11) kube-proxy-8pp5m | + | |
- | 12) kube-proxy-ltx6c | + | |
- | 13) kube-scheduler-kind-control-plane | + | |
- | 14) metrics-server-594b87569-28r4s | + | |
- | 15) local-path-provisioner-78776bfc44-5rzmk | + | |
- | Select a Pod: | + | |
</ | </ | ||
- | Choisissez | + | Vérifiez que le pod est en état de **READY** : |
< | < | ||
- | Select a Pod: 1 | + | root@kubemaster:~# kubectl get pods |
- | postgresql 14: | + | NAME |
- | postgresql 14:58:48.79 Welcome to the Bitnami postgresql container | + | flask-cap |
- | postgresql 14:58:48.79 Subscribe to project updates by watching https://github.com/ | + | flask-ro |
- | postgresql 14:58:48.79 Submit issues and feature requests at https:// | + | postgres-deployment-5b8bd66778-j99zz |
- | postgresql 14:58:48.79 | + | redis-deployment-67d4c466c4-9wzfn |
- | postgresql 14:58:48.81 INFO ==> ** Starting PostgreSQL setup ** | + | result-app-deployment-b8f9dc967-nzbgd |
- | postgresql 14:58:48.83 INFO ==> Validating settings in POSTGRESQL_* env vars.. | + | result-app-deployment-b8f9dc967-r84k6 |
- | postgresql 14:58:48.84 INFO ==> Loading custom pre-init scripts... | + | result-app-deployment-b8f9dc967-zbsk2 |
- | postgresql 14:58:48.85 INFO ==> Initializing PostgreSQL database... | + | voting-app-deployment-669dccccfb-jpn6h |
- | postgresql 14:58:48.87 INFO ==> pg_hba.conf file not detected. Generating it... | + | voting-app-deployment-669dccccfb-ktd7d |
- | postgresql 14:58:48.87 INFO ==> Generating local authentication configuration | + | voting-app-deployment-669dccccfb-x868p |
- | postgresql 14:58:53.51 INFO ==> Starting PostgreSQL in background... | + | worker-app-deployment-559f7749b6-jh86r |
- | postgresql 14:58:53.64 INFO ==> Changing password of postgres | + | |
- | postgresql 14:58:53.66 INFO ==> Configuring replication parameters | + | |
- | postgresql 14:58:53.69 INFO ==> Configuring fsync | + | |
- | postgresql 14:58:53.70 INFO ==> Loading custom scripts... | + | |
- | postgresql 14:58:53.71 INFO ==> Enabling remote connections | + | |
- | postgresql 14:58:53.73 INFO ==> Stopping PostgreSQL... | + | |
- | postgresql 14:58:54.74 INFO ==> ** PostgreSQL setup finished! ** | + | |
- | + | ||
- | postgresql 14:58:54.78 INFO ==> ** Starting PostgreSQL ** | + | |
- | 2020-12-12 14: | + | |
- | 2020-12-12 14: | + | |
- | 2020-12-12 14: | + | |
- | 2020-12-12 14: | + | |
- | 2020-12-12 14: | + | |
</ | </ | ||
- | Pour lister les plugins installés, utilisez la commande **list** | + | Connectez-vous au conteneur |
< | < | ||
- | root@debian10:~# kubectl | + | root@kubemaster:~# kubectl |
- | PLUGIN | + | root@flask-cap:/# |
- | ctx | + | |
- | krew v0.4.0 | + | |
- | ns v0.9.1 | + | |
- | pod-logs v1.0.1 | + | |
- | view-allocations | + | |
</ | </ | ||
- | Pour mettre à jour les plugins installés, utilisez | + | Notez la mise en place des restrictions |
< | < | ||
- | root@debian10:~# kubectl krew upgrade | + | root@flask-cap:/# ping 8.8.8.8 |
- | Updated the local copy of plugin index. | + | ping: Lacking privilege for raw socket. |
- | Upgrading plugin: ctx | + | root@flask-cap:/# chown daemon /tmp |
- | Skipping plugin ctx, it is already on the newest version | + | chown: changing ownership of '/ |
- | 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@flask-cap:/# exit |
- | + | exit | |
- | < | + | command terminated with exit code 1 |
- | root@debian10:~# kubectl krew remove pod-logs | + | |
- | Uninstalled plugin pod-logs | + | |
- | root@debian10:~# kubectl krew list | + | |
- | PLUGIN | + | |
- | ctx v0.9.1 | + | |
- | krew v0.4.0 | + | |
- | ns v0.9.1 | + | |
- | view-allocations | + | |
</ | </ | ||
- | ====1.8 - Gérer des patchs==== | + | ====2.3 - Kubernetes Network Policies==== |
- | ===La Commande kustomize=== | + | Créez le fichier |
- | + | ||
- | Commencez par installer l' | + | |
< | < | ||
- | root@debian10:~# apt install tree | + | root@kubemaster:~# vi guestbook-all-in-one.yaml |
- | </ | + | root@kubemaster:~# cat |
- | + | apiVersion: v1 | |
- | Créez ensuite le répertoire **kustomize** contenant le répertoire **base** et placez-vous dans ce dernier : | + | kind: Service |
- | + | ||
- | < | + | |
- | root@debian10: | + | |
- | root@debian10: | + | |
- | root@debian10: | + | |
- | </ | + | |
- | + | ||
- | Créez le manifest **deployment.yaml** : | + | |
- | + | ||
- | < | + | |
- | root@debian10:~/ | + | |
- | root@debian10: | + | |
- | apiVersion: | + | |
- | kind: Deployment | + | |
metadata: | metadata: | ||
- | name: nginx | + | name: redis-master |
labels: | labels: | ||
- | app: nginx | + | app: redis |
+ | tier: backend | ||
+ | role: master | ||
spec: | spec: | ||
+ | ports: | ||
+ | # the port that this service should serve on | ||
+ | - port: 6379 | ||
+ | targetPort: 6379 | ||
+ | selector: | ||
+ | app: redis | ||
+ | tier: backend | ||
+ | role: master | ||
+ | --- | ||
+ | apiVersion: v1 | ||
+ | kind: ReplicationController | ||
+ | metadata: | ||
+ | name: redis-master | ||
+ | # these labels can be applied automatically | ||
+ | # from the labels in the pod template if not set | ||
+ | labels: | ||
+ | app: redis | ||
+ | role: master | ||
+ | tier: backend | ||
+ | spec: | ||
+ | # this replicas value is default | ||
+ | # modify it according to your case | ||
replicas: 1 | replicas: 1 | ||
- | selector: | + | |
- | | + | # from the labels in the pod template if not set |
- | app: nginx | + | # selector: |
+ | # | ||
+ | # role: master | ||
+ | # tier: backend | ||
template: | template: | ||
metadata: | metadata: | ||
labels: | labels: | ||
- | app: nginx | + | app: redis |
+ | role: master | ||
+ | tier: backend | ||
spec: | spec: | ||
- | affinity: | ||
- | podAntiAffinity: | ||
- | requiredDuringSchedulingIgnoredDuringExecution: | ||
- | - labelSelector: | ||
- | matchExpressions: | ||
- | - key: app | ||
- | operator: In | ||
- | values: | ||
- | - nginx | ||
- | topologyKey: | ||
containers: | containers: | ||
- | - image: | + | - name: master |
- | | + | |
- | name: nginx | + | |
- | </ | + | |
- | + | cpu: 100m | |
- | <WRAP center round important 40%> | + | |
- | **Important** - le contenu de ce fichier crée un **deployment** de 1 **replica** du pod **nginx** à partir de l' | + | ports: |
- | </ | + | - containerPort: 6379 |
- | + | --- | |
- | Créez ensuite le manifest **service.yaml** | + | |
- | + | ||
- | < | + | |
- | root@debian10:~/ | + | |
- | root@debian10: | + | |
apiVersion: v1 | apiVersion: v1 | ||
kind: Service | kind: Service | ||
metadata: | metadata: | ||
- | name: nginx | + | name: redis-slave |
labels: | labels: | ||
- | app: nginx | + | app: redis |
+ | tier: backend | ||
+ | role: slave | ||
spec: | spec: | ||
- | type: ClusterIP | ||
ports: | ports: | ||
- | | + | # the port that this service should serve on |
- | protocol: TCP | + | |
- | targetPort: 80 | + | |
selector: | selector: | ||
- | app: nginx | + | app: redis |
- | </ | + | tier: backend |
- | + | role: slave | |
- | <WRAP center round important 40%> | + | --- |
- | **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. | + | |
- | </ | + | |
- | + | ||
- | <WRAP center round tip 40%> | + | |
- | Le Service ClusterIP permet de regrouper les PODs offrant le même service afin de faciliter la communication. | + | |
- | </ | + | |
- | + | ||
- | Dernièrement, | + | |
- | + | ||
- | < | + | |
- | root@debian10: | + | |
- | root@debian10: | + | |
- | 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@debian10: | + | |
- | root@debian10: | + | |
- | . | + | |
- | └── 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@debian10: | + | |
apiVersion: v1 | apiVersion: v1 | ||
- | kind: Service | + | kind: ReplicationController |
metadata: | metadata: | ||
+ | name: redis-slave | ||
+ | # these labels can be applied automatically | ||
+ | # from the labels in the pod template if not set | ||
labels: | labels: | ||
- | app: nginx | + | app: redis |
- | name: nginx | + | role: slave |
+ | tier: backend | ||
spec: | spec: | ||
- | | + | |
- | | + | |
- | | + | |
- | targetPort: 80 | + | |
- | selector: | + | # from the labels in the pod template if not set |
- | app: nginx | + | |
- | | + | |
- | --- | + | |
- | apiVersion: apps/v1 | + | |
- | kind: Deployment | + | |
- | metadata: | + | |
- | | + | |
- | | + | |
- | | + | |
- | spec: | + | |
- | | + | |
- | selector: | + | |
- | matchLabels: | + | |
- | app: nginx | + | |
template: | template: | ||
metadata: | metadata: | ||
labels: | labels: | ||
- | app: nginx | + | app: redis |
+ | role: slave | ||
+ | tier: backend | ||
spec: | spec: | ||
- | affinity: | ||
- | podAntiAffinity: | ||
- | requiredDuringSchedulingIgnoredDuringExecution: | ||
- | - labelSelector: | ||
- | matchExpressions: | ||
- | - key: app | ||
- | operator: In | ||
- | values: | ||
- | - nginx | ||
- | topologyKey: | ||
containers: | containers: | ||
- | - image: nginx: | + | - name: slave |
- | | + | image: |
- | name: nginx | + | |
- | </ | + | |
- | + | cpu: 100m | |
- | <WRAP center round important 40%> | + | |
- | **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' | + | env: |
- | </WRAP> | + | - name: GET_HOSTS_FROM |
- | + | value: dns | |
- | Imaginons maintenant que vous souhaitez déployer deux environnements **différents** de la même application, | + | # If your cluster config does not include a dns service, then to |
- | + | # instead access an environment variable to find the master | |
- | Créez les répertoires **kustomize/overlays/ | + | # service's host, comment out the 'value: dns' line above, and |
- | + | # uncomment the line below. | |
- | < | + | # value: env |
- | root@debian10:~/ | + | ports: |
- | root@debian10:~/ | + | - containerPort: 6379 |
- | </ | + | --- |
- | + | ||
- | Consultez l' | + | |
- | + | ||
- | < | + | |
- | root@debian10: | + | |
- | . | + | |
- | ├── base | + | |
- | │ ├── deployment.yaml | + | |
- | │ ├── kustomization.yaml | + | |
- | │ └── | + | |
- | └── overlays | + | |
- | ├── development | + | |
- | └── production | + | |
- | + | ||
- | 4 directories, 3 files | + | |
- | </ | + | |
- | + | ||
- | Créez le fichier **overlays/ | + | |
- | + | ||
- | < | + | |
- | root@debian10: | + | |
- | root@debian10: | + | |
- | apiVersion: kustomize.config.k8s.io/ | + | |
- | kind: Kustomization | + | |
- | + | ||
- | bases: | + | |
- | - ../ | + | |
- | + | ||
- | nameSuffix: -development # < | + | |
- | + | ||
- | commonLabels: | + | |
- | environment: | + | |
- | + | ||
- | namespace: nginx-dev # < | + | |
- | </ | + | |
- | + | ||
- | Appliquez ces modifications : | + | |
- | + | ||
- | < | + | |
- | root@debian10: | + | |
apiVersion: v1 | apiVersion: v1 | ||
kind: Service | kind: Service | ||
metadata: | metadata: | ||
+ | name: frontend | ||
labels: | labels: | ||
- | app: nginx | + | app: guestbook |
- | | + | |
- | name: nginx-development # < | + | |
- | namespace: nginx-dev # < | + | |
spec: | spec: | ||
+ | # if your cluster supports it, uncomment the following to automatically create | ||
+ | # an external load-balanced IP for the frontend service. | ||
+ | # type: LoadBalancer | ||
ports: | ports: | ||
+ | # the port that this service should serve on | ||
- port: 80 | - port: 80 | ||
- | protocol: TCP | ||
- | targetPort: 80 | ||
selector: | selector: | ||
- | app: nginx | + | app: guestbook |
- | | + | |
- | type: ClusterIP | + | |
--- | --- | ||
- | apiVersion: | + | apiVersion: v1 |
- | kind: Deployment | + | kind: ReplicationController |
metadata: | metadata: | ||
+ | name: frontend | ||
+ | # these labels can be applied automatically | ||
+ | # from the labels in the pod template if not set | ||
labels: | labels: | ||
- | app: nginx | + | app: guestbook |
- | | + | |
- | name: nginx-development | + | |
- | namespace: nginx-dev | + | |
spec: | spec: | ||
- | replicas: | + | |
- | selector: | + | # modify it according to your case |
- | | + | |
- | app: nginx | + | |
- | | + | # from the labels in the pod template if not set |
+ | # selector: | ||
+ | # | ||
+ | # | ||
template: | template: | ||
metadata: | metadata: | ||
labels: | labels: | ||
- | app: nginx | + | app: guestbook |
- | | + | |
spec: | spec: | ||
- | affinity: | ||
- | podAntiAffinity: | ||
- | requiredDuringSchedulingIgnoredDuringExecution: | ||
- | - labelSelector: | ||
- | matchExpressions: | ||
- | - key: app | ||
- | operator: In | ||
- | values: | ||
- | - nginx | ||
- | topologyKey: | ||
containers: | containers: | ||
- | - image: | + | - name: php-redis |
- | | + | |
- | | + | resources: |
+ | requests: | ||
+ | cpu: 100m | ||
+ | memory: 100Mi | ||
+ | env: | ||
+ | | ||
+ | value: dns | ||
+ | # If your cluster config does not include a dns service, then to | ||
+ | # instead access environment variables to find service host | ||
+ | # info, comment out the 'value: dns' line above, and uncomment the | ||
+ | # line below. | ||
+ | # value: env | ||
+ | | ||
+ | | ||
</ | </ | ||
- | Maintenant créez le fichier | + | Installez l' |
< | < | ||
- | root@debian10:~/kustomize# vi overlays/ | + | root@kubemaster:~# kubectl create -f guestbook-all-in-one.yaml |
- | root@debian10: | + | </code> |
- | apiVersion: kustomize.config.k8s.io/ | + | |
- | kind: Kustomization | + | |
- | bases: | + | Attendez que tous les pods soient dans un état de **READY** : |
- | - ../../base # < | + | |
- | nameSuffix: -production | + | < |
+ | root@kubemaster:~# kubectl get pods -o wide | ||
+ | NAME | ||
+ | flask-cap | ||
+ | flask-ro | ||
+ | frontend-dhd4w | ||
+ | frontend-dmbbf | ||
+ | frontend-rqr6p | ||
+ | redis-master-zrrr4 | ||
+ | redis-slave-jsrt6 1/1 | ||
+ | redis-slave-rrnx9 1/1 | ||
+ | ... | ||
+ | </code> | ||
- | commonLabels: | + | Cette application crée des pods de type //backend// et // |
- | environment: | + | |
- | namespace: nginx-prod | + | < |
+ | root@kubemaster:~# kubectl describe pod redis-master-zrrr4 | grep tier | ||
+ | tier=backend | ||
- | images: | + | root@kubemaster:~# kubectl describe pod frontend-dhd4w | grep tier |
- | - name: nginx | + | |
- | | + | |
</ | </ | ||
- | Appliquez ces modifications | + | Créez le fichier **guestbook-network-policy.yaml** qui empêchera la communication d'un pod backend vers un pod frontend |
< | < | ||
- | root@debian10:~/kustomize# kubectl kustomize overlays/ | + | root@kubemaster:~# vi guestbook-network-policy.yaml |
- | apiVersion: v1 | + | root@kubemaster: |
- | kind: Service | + | apiVersion: |
+ | kind: NetworkPolicy | ||
metadata: | metadata: | ||
- | | + | name: deny-backend-egress |
- | app: nginx | + | namespace: |
- | environment: | + | |
- | | + | |
- | namespace: | + | |
spec: | spec: | ||
- | | + | |
- | - 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: | matchLabels: | ||
- | | + | |
- | environment: | + | |
- | | + | |
- | | + | |
- | | + | - to: |
- | app: nginx | + | |
- | environment: | + | matchLabels: |
- | | + | tier: backend |
- | affinity: | + | |
- | podAntiAffinity: | + | |
- | requiredDuringSchedulingIgnoredDuringExecution: | + | |
- | | + | |
- | | + | |
- | | + | |
- | operator: In | + | |
- | values: | + | |
- | - nginx | + | |
- | topologyKey: | + | |
- | containers: | + | |
- | - image: nginx: | + | |
- | | + | |
- | name: nginx | + | |
</ | </ | ||
- | Créez maintenant le namespace **nginx-prod** | + | Exécutez kubectl |
< | < | ||
- | root@debian10:~/kustomize# kubectl create | + | root@kubemaster:~# kubectl create -f guestbook-network-policy.yaml |
- | namespace/nginx-prod created | + | networkpolicy.networking.k8s.io/deny-backend-egress |
</ | </ | ||
- | Installez l' | + | Connectez-vous au pod **redis-master** : |
< | < | ||
- | root@debian10:~/kustomize# kubectl | + | root@kubemaster:~# kubectl |
- | service/ | + | [ root@redis-master-zrrr4:/ |
- | deployment.apps/ | + | |
</ | </ | ||
- | Constatez le résultat | + | Essayez |
< | < | ||
- | root@debian10:~/kustomize# kubectl get pods -n nginx-prod | + | [ root@redis-master-zrrr4:/data ]$ ping -c 4 192.168.150.15 |
- | NAME | + | PING 192.168.150.15 (192.168.150.15) 56(84) bytes of data. |
- | nginx-production-f456f9c8f-8hgss | + | 64 bytes from 192.168.150.15: |
- | root@debian10:~/ | + | 64 bytes from 192.168.150.15: icmp_seq=2 ttl=62 time=0.291 ms |
- | NAME | + | 64 bytes from 192.168.150.15: |
- | nginx-production | + | 64 bytes from 192.168.150.15: icmp_seq=4 ttl=62 time=0.379 ms |
- | root@debian10:~/ | + | |
- | NAME | + | --- 192.168.150.15 ping statistics |
- | nginx-production | + | 4 packets transmitted, |
+ | rtt min/ | ||
</ | </ | ||
- | Supprimez le deployment et le service nginx-production | + | Essayez maintenant de contacter un pod d'un **tier** frontend |
< | < | ||
- | root@debian10: | + | [ root@redis-master-zrrr4:/data ]$ ping -c 4 192.168.150.16 |
- | deployment.apps " | + | PING 192.168.150.16 (192.168.150.16) 56(84) bytes of data. |
- | root@debian10:~/kustomize# kubectl get deployments | + | |
- | No resources found in nginx-prod namespace. | + | --- 192.168.150.16 ping statistics |
- | root@debian10: | + | 4 packets transmitted, |
- | NAME | + | |
- | nginx-production | + | |
- | root@debian10: | + | |
- | No resources found in nginx-prod namespace. | + | |
- | root@debian10: | + | |
- | service " | + | |
- | root@debian10: | + | |
- | No resources found in nginx-prod namespace. | + | |
</ | </ | ||
- | Installez l' | + | Déconnectez-vous du pod **redis-master** et connectez-vous à un pod **frontend** : |
< | < | ||
- | root@debian10:~/kustomize# kubectl create ns nginx-dev | + | [ root@redis-master-zrrr4:/data ]$ exit |
- | namespace/ | + | exit |
- | root@debian10:~/kustomize# kubectl | + | command terminated with exit code 1 |
- | service/ | + | |
- | deployment.apps/ | + | root@kubemaster:~# kubectl |
+ | root@frontend-dhd4w:/ | ||
</ | </ | ||
- | Constatez | + | Installez |
< | < | ||
- | root@debian10:~/kustomize# kubectl get pods -n nginx-dev | + | root@frontend-dhd4w:/var/www/html# apt update |
- | NAME | + | root@frontend-dhd4w:/var/ |
- | nginx-development-579c5cfcb6-w8dmq | + | |
- | root@debian10: | + | |
- | NAME READY | + | |
- | nginx-development | + | |
- | root@debian10:~/kustomize# kubectl get services | + | |
- | NAME TYPE CLUSTER-IP | + | |
- | nginx-development | + | |
</ | </ | ||
- | ====1.9 - Alias utiles==== | + | Essayez |
- | + | ||
- | Pour faciliter le travail avec la commande kubectl, il est recommendé | + | |
< | < | ||
- | root@debian10:~/kustomize# vi ~/.bash_aliases | + | root@frontend-dhd4w:/var/www/html# ping -c 4 192.168.150.17 |
- | root@debian10: | + | PING 192.168.150.17 (192.168.150.17): |
- | alias k=' | + | 64 bytes from 192.168.150.17: |
- | alias kg=' | + | 64 bytes from 192.168.150.17: |
- | alias kd=' | + | 64 bytes from 192.168.150.17: |
- | alias kga=' | + | 64 bytes from 192.168.150.17: |
- | alias kp=' | + | --- 192.168.150.17 ping statistics --- |
- | alias kap=' | + | 4 packets transmitted, |
- | alias ka=' | + | round-trip min/ |
- | alias kei=' | + | |
- | alias ke=' | + | |
- | alias ktn='watch kubectl top nodes' | + | |
- | alias ktp='watch kubectl top pods' | + | |
- | alias kpf=' | + | |
- | alias kl=' | + | |
- | alias kz=' | + | |
</ | </ | ||
- | Activez les alias avec la commande | + | Essayez maintenant de contacter un pod d' |
< | < | ||
- | root@debian10:~/kustomize# source ~/.bash_aliases | + | root@frontend-dhd4w:/var/ |
+ | PING 192.168.239.27 (192.168.239.27): | ||
+ | 64 bytes from 192.168.239.27: | ||
+ | 64 bytes from 192.168.239.27: | ||
+ | 64 bytes from 192.168.239.27: | ||
+ | 64 bytes from 192.168.239.27: | ||
+ | --- 192.168.239.27 ping statistics --- | ||
+ | 4 packets transmitted, | ||
+ | round-trip min/ | ||
</ | </ | ||
- | ===L' | + | Sortez du pod frontend : |
< | < | ||
- | root@debian10: | + | root@frontend-dhd4w:/var/www/html# exit |
- | NAME | + | exit |
- | kind-control-plane | + | root@kubemaster:~# |
- | kind-worker2 | + | |
- | kind-worker3 | + | |
- | root@debian10:~/kustomize# kg deployments | + | |
- | NAME | + | |
- | postgresql | + | |
- | root@debian10: | + | |
- | NAME | + | |
- | kubernetes | + | |
- | root@debian10:~/kustomize# kg pods | + | |
- | NAME READY | + | |
- | postgresql-6c99978556-kqkp4 | + | |
</ | </ | ||
- | ===L' | + | ====2.4 - Kubernetes Resource Allocation Management==== |
- | < | + | Les ressources qui peuvent être limitées au niveau d' |
- | root@debian10: | + | |
- | Name: | + | |
- | Namespace: | + | |
- | Priority: | + | |
- | Node: | + | |
- | Start Time: Sun, 13 Dec 2020 13:37:14 +0100 | + | |
- | Labels: | + | |
- | pod-template-hash=6c99978556 | + | |
- | Annotations: | + | |
- | Status: | + | |
- | IP: | + | |
- | IPs: | + | |
- | IP: | + | |
- | Controlled By: ReplicaSet/ | + | |
- | Containers: | + | |
- | postgresql: | + | |
- | Container ID: | + | |
- | Image: | + | |
- | Image ID: | + | |
- | Port: < | + | |
- | Host Port: < | + | |
- | State: | + | |
- | Started: | + | |
- | Ready: | + | |
- | Restart Count: | + | |
- | Environment: | + | |
- | POSTGRESQL_PASSWORD: | + | |
- | Mounts: | + | |
- | / | + | |
- | Conditions: | + | |
- | Type Status | + | |
- | Initialized | + | |
- | Ready True | + | |
- | ContainersReady | + | |
- | PodScheduled | + | |
- | Volumes: | + | |
- | default-token-z5ptn: | + | |
- | Type: Secret (a volume populated by a Secret) | + | |
- | SecretName: | + | |
- | Optional: | + | |
- | QoS Class: | + | |
- | Node-Selectors: | + | |
- | Tolerations: | + | |
- | --More-- | + | |
- | </ | + | |
- | ===L' | + | * CPU |
+ | * Mémoire | ||
+ | * Stockage local | ||
+ | |||
+ | Créez le fichier **flask-resources.yaml** : | ||
< | < | ||
- | root@debian10:~/kustomize# kga | + | root@kubemaster:~# vi flask-resources.yaml |
- | NAME READY | + | root@kubemaster: |
- | pod/ | + | apiVersion: v1 |
+ | kind: Pod | ||
+ | metadata: | ||
+ | name: flask-resources | ||
+ | namespace: default | ||
+ | spec: | ||
+ | containers: | ||
+ | | ||
+ | name: flask-resources | ||
+ | resources: | ||
+ | requests: | ||
+ | memory: 512Mi | ||
+ | limits: | ||
+ | memory: 700Mi | ||
+ | </code> | ||
- | NAME | + | Dans ce fichier on peut constater deux allocations de ressources : |
- | service/ | + | |
- | NAME | + | |
- | deployment.apps/ | + | * la quantité de mémoire qui doit être libre au moment du scheduling du pod, |
+ | * **limits**, | ||
+ | * la limite de mémoire pour le pod concerné. | ||
- | NAME DESIRED | + | Exécutez kubectl : |
- | replicaset.apps/ | + | |
- | </ | + | |
- | + | ||
- | ===L' | + | |
< | < | ||
- | root@debian10:~/kustomize# kp | + | root@kubemaster:~# kubectl create |
- | NAME READY | + | pod/flask-resources created |
- | postgresql-6c99978556-kqkp4 1/1 | + | |
</ | </ | ||
- | ===L' | + | Attendez que le statut du pod soit **READY** : |
< | < | ||
- | root@debian10:~/kustomize# kap | + | root@kubemaster:~# kubectl get pods |
- | NAMESPACE | + | NAME |
- | default | + | flask-cap |
- | kube-system | + | flask-resources |
- | kube-system | + | flask-ro 1/1 |
- | kube-system | + | ... |
- | kube-system | + | |
- | kube-system | + | |
- | kube-system | + | |
- | kube-system | + | |
- | kube-system | + | |
- | kube-system | + | |
- | kube-system | + | |
- | kube-system | + | |
- | kube-system | + | |
- | local-path-storage | + | |
- | nginx-dev | + | |
</ | </ | ||
- | ===L' | + | Connectez-vous au pod : |
< | < | ||
- | root@debian10:~/kustomize# kei postgresql-6c99978556-kqkp4 -- bash | + | root@kubemaster:~# kubectl exec -it flask-resources |
- | I have no name!@postgresql-6c99978556-kqkp4:/$ exit | + | root@flask-resources:/# |
- | exit | + | |
</ | </ | ||
- | ===L' | + | Installez le paquet **stress** : |
< | < | ||
- | root@debian10:~/kustomize# ke postgresql-6c99978556-kqkp4 -- ls -alh | + | root@flask-resources:/# echo "deb http://archive.debian.org/debian/ jessie main contrib non-free" > / |
- | total 88K | + | root@flask-resources:/# echo "deb http://archive.debian.org/ |
- | drwxr-xr-x | + | root@flask-resources:/# cat /etc/ |
- | drwxr-xr-x | + | deb http://archive.debian.org/debian/ jessie main contrib non-free |
- | drwxr-xr-x 1 root root 4.0K Aug 12 04:15 bin | + | deb http://archive.debian.org/debian-security jessie/ |
- | drwxr-xr-x | + | root@flask-resources:/# apt update |
- | drwxr-xr-x 2 root root 4.0K Jul 10 21:04 boot | + | root@flask-resources:/# apt install stress |
- | drwxr-xr-x | + | |
- | drwxrwxr-x | + | |
- | drwxr-xr-x | + | |
- | drwxr-xr-x | + | |
- | drwxr-xr-x | + | |
- | drwxr-xr-x | + | |
- | drwxr-xr-x | + | |
- | drwxr-xr-x | + | |
- | drwxr-xr-x | + | |
- | drwxrwxr-x 1 root root 4.0K Aug 12 04:15 opt | + | |
- | dr-xr-xr-x 177 root root 0 Dec 13 12:37 proc | + | |
- | drwx------ | + | |
- | drwxr-xr-x | + | |
- | drwxr-xr-x 1 root root 4.0K Aug 12 04:15 sbin | + | |
- | drwxr-xr-x | + | |
- | dr-xr-xr-x | + | |
- | drwxrwxrwt | + | |
- | drwxrwxr-x 1 root root 4.0K Aug 12 04:15 usr | + | |
- | drwxr-xr-x 1 root root 4.0K Jul 21 19:27 var | + | |
</ | </ | ||
- | ===L' | + | Testez la limite mise en place : |
< | < | ||
- | root@debian10:~/kustomize# kpf postgresql-6c99978556-kqkp4 8080 | + | root@flask-resources:/# stress |
- | Forwarding from 127.0.0.1:8080 -> 8080 | + | stress: info: [41] dispatching hogs: 1 cpu, 1 io, 2 vm, 0 hdd |
- | Forwarding from [::1]:8080 -> 8080 | + | stress: FAIL: [41] (416) <-- worker 45 got signal 9 |
- | ^Croot@debian10:~/ | + | stress: WARN: [41] (418) now reaping child worker processes |
+ | stress: FAIL: [41] (452) failed run completed in 1s | ||
</ | </ | ||
- | ===L' | + | Sortez du pod flask-resources : |
< | < | ||
- | root@debian10:~/kustomize# k get deploy | + | root@flask-resources:/# exit |
- | NAME | + | exit |
- | postgresql | + | root@kubemaster:~# |
- | root@debian10:~/kustomize# kl deploy/ | + | |
- | postgresql 12:37:40.90 INFO ==> Enabling remote connections | + | |
- | postgresql 12:37:40.92 INFO ==> Stopping PostgreSQL... | + | |
- | postgresql 12:37:41.93 INFO ==> ** PostgreSQL setup finished! ** | + | |
- | + | ||
- | postgresql 12:37:41.95 INFO ==> ** Starting PostgreSQL ** | + | |
- | 2020-12-13 12: | + | |
- | 2020-12-13 12: | + | |
- | 2020-12-13 12: | + | |
- | 2020-12-13 12: | + | |
- | 2020-12-13 12: | + | |
</ | </ | ||
---- | ---- | ||
- | < | + | Copyright © 2024 Hugh Norris |
- | <DIV ALIGN=" | + | |
- | Copyright © 2020 Hugh Norris | + | |
- | </ | + | |
- | </ | + | |
- | + |