mickael-baron.fr Microservices - K8S
Page
mickaelbaron
70
Type Stockage : exemple hostPath
Options kubectl : apply, get
# Appliquer une configuration Deployment+Service (NodePort = 30001) dans le Namespace mynamespace
$ kubectl apply –f volumes/myhostpath.yaml –n mynamespace
# Lister les Pods créés (Pods disponibles sur deux nœuds)
$ kubectl get pods -n mynamespace -o wide
NAME READY STATUS RESTARTS AGE IP NODE
mydeploymentwithhostpath-776c7487f6-25gn2 1/1 Running 0 81m 10.42.1.123 kubernetes-cluster-2
mydeploymentwithhostpath-776c7487f6-qplmp 1/1 Running 0 81m 10.42.1.124 kubernetes-cluster-2
mydeploymentwithhostpath-776c7487f6-jhbmr 1/1 Running 0 79m 10.42.2.136 kubernetes-cluster-3
# Accéder au contenu web d’un Pod (accessible depuis le service NodePort)
$ curl 167.53.81.116:30001 => Erreur 403
# 🧐
# Il n’y a pas de contenu dans le dossier /usr/share/nginx/html de ce Pod (problème pour tous les Pods)
# Ajouter un fichier index.html dans le dossier /myhostpath du nœud kubernetes-cluster-2
$ ssh
[email protected] "sudo sh -c 'echo "Bonjour depuis le noeud 2" > /myhostpath/index.html'"
# Accéder au contenu web d’un Pod
$ curl 167.53.81.116:30001 => Bonjour depuis le noeud 2
$ curl 167.53.81.116:30001 => Erreur 403
# 🧐
# Seul le nœud kubernetes-cluster-2 fonctionne, nécessite d’impacter tous les nœuds où le Pod est déployé
$ ssh
[email protected] "sudo sh -c 'echo "Bonjour depuis le noeud 3" > /myhostpath/index.html'"
$ curl 167.53.81.116:30001 => Bonjour depuis le noeud 2
$ curl 167.53.81.116:30001 => Bonjour depuis le noeud 3
$ curl 167.53.81.116:30001 => Bonjour depuis le noeud 3