-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
03a583b
commit ada693c
Showing
14 changed files
with
251 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: hpa-example | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: hpa | ||
template: | ||
metadata: | ||
labels: | ||
app: hpa | ||
spec: | ||
containers: | ||
- name: hello | ||
image: "k8s.gcr.io/hpa-example" | ||
ports: | ||
- name: http | ||
containerPort: 80 | ||
resources: | ||
requests: | ||
cpu: 0.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Verifier l'état du déploiement: | ||
|
||
kubectl get deploy | ||
|
||
ubuntu $ kubectl get deploy | ||
NAME READY UP-TO-DATE AVAILABLE AGE | ||
hpa-example 1/1 1 1 13m | ||
|
||
Le status nombre de pod pour le déploiement est 1. | ||
|
||
Pour afficher l'état de l'objet hpa et enregistrer le résultat: | ||
|
||
echo 'kubectl get hpa' > /tmp/res-step1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/bash | ||
|
||
set -x # to test stderr output in /var/log/killercoda | ||
|
||
# Nothing to run for this scenario | ||
true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash | ||
|
||
# Nothing to run for this scenario | ||
curl -sfL https://get.k3s.io | sh - |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"title": "Autoscaling", | ||
"description": "Mise à l'échelle automatique", | ||
"details": { | ||
"intro": { | ||
"text": "intro.md", | ||
"background": "background.sh", | ||
"foreground": "foreground.sh" | ||
}, | ||
"steps": [ | ||
{ | ||
"title": "Créer un déploiement", | ||
"text": "step1/step1.md", | ||
"verify": "step1/verify.sh" | ||
}, | ||
{ | ||
"title": "Charger le système", | ||
"text": "step2/step2.md" | ||
}, | ||
{ | ||
"title": "Vérifier l'état", | ||
"text": "step3/step3.md", | ||
"verify": "step3/verify.sh" | ||
}, | ||
{ | ||
"title": "Downscale", | ||
"text": "step4/step4.md", | ||
"verify": "step4/verify.sh" | ||
} | ||
], | ||
"assets": { | ||
"host01": [ | ||
{"file": "deployments/*", "target": "/root", "chmod": "+w"}, | ||
{"file": "solution*", "target": "/var/killercoda/solution","chmod":"+w"} | ||
] | ||
} | ||
}, | ||
"backend": { | ||
"imageid": "ubuntu" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Mide à l'echelle automatique | ||
|
||
Dans Kubernetes, un _HorizontalPodAutoscaler_ met automatiquement à jour une ressource de charge de travail (telle qu'un Déploiement ou un StatefulSet), dans le but de faire évoluer automatiquement sa capacité pour répondre à la demande. | ||
|
||
La mise à l'échelle horizontale consiste à adapter le nombre de pod automatiquement en fonction de la demande. | ||
|
||
Si la charge diminue et que le nombre de Pods est supérieur au minimum configuré, le HorizontalPodAutoscaler demande à la ressource de charge de travail (le déploiement, le StatefulSet ou une autre ressource similaire) de s'adapter à la baisse. | ||
|
||
- Les tests vont s’effectuer sur l’image docker k8s.gcr.io/hpa-example. | ||
- Cette image contient un apache+php. La home page de cette apache est un script php qui calcule les racines carrées des nombres de 1 à 1 million. | ||
- L’appel à cette page va provoquer une forte consommation CPU. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
## 0/ Attendre que le noeud soit Ready | ||
|
||
Executer la commande suivante: | ||
``` | ||
kubectl get nodes | ||
```{{exec}} | ||
attendre que la statut soit "Ready". Si besoin relancer la commande en attendant quelque secondes. | ||
## 1/ Créer le déploiement | ||
Lance le service de test sur le cluster | ||
``` | ||
# Création du déploiement | ||
kubectl apply -f deployments/hpa-example.yaml | ||
```{{exec}} | ||
## 2/ Exposer le déploiement | ||
Créer un service en utilisant la méthode impérative. | ||
``` | ||
# Création du service | ||
kubectl expose deployment/hpa-example --port 80 | ||
```{{exec}} | ||
## 3/ Créer le HorizontalPodAutoscaler sur le déploiement | ||
La commande suivante permet de mettre automatiquement le déploiement à l'échelle, en fonction de la charge CPU | ||
``` | ||
# Mise à l'echelle automatique | ||
kubectl autoscale deployment hpa-example --cpu-percent=50 --min=1 --max=2 | ||
```{{exec}} | ||
# Question ? | ||
- Quels est le nombre maximal de pods pour le déploiement _hpa-example_ ? | ||
- Lister les objets de type _hpa_ (horizontalPodAutoscaler) à l'aide d'une commande **kubectl** et placer le résultat dans le fichier /tmp/res-step1 | ||
> vous pouvez utiliser la commande `kubectl .... > /tmp/res-step1` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
grep "hpa-example" /tmp/res-step1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
## 1/ Charger le système | ||
|
||
Vous lancerez ensuite un Pod interactif pour charger le service | ||
|
||
``` | ||
kubectl run -ti load-generator --image=busybox /bin/sh | ||
```{{exec}} | ||
## 2/ Executer la boucle | ||
Une fois dans le shell, lancer la boucle d'appel suivante: | ||
``` | ||
while true; | ||
do wget -q -O- http://hpa-example; | ||
done | ||
```{{exec}} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
|
||
> Laisser la boucle tourner et ouvrir un nouvel onglet (icône **+** à côté de "**Tab1**" en haut à droite de votre zone de terminal) | ||
Basculer dans le nouvel onglet créé nommé "**Tab2**" | ||
|
||
## 1/ Afficher l'état du déploiement | ||
|
||
### Objet hpa | ||
|
||
``` | ||
kubectl get hpa | ||
```{{exec}} | ||
Répéter l'opération à quelques secondes d'intervalle (jusqu'à 1 minute): Comment évolue la charge CPU moyenne ? | ||
### Déploiement | ||
Vérifier le nombre de replicas pour votre déploiement | ||
``` | ||
kubectl get deployment | ||
```{{exec}} | ||
Que constatez-vous ? | ||
## 2/ Analyser les resources du cluster | ||
### Pods | ||
Pour connaître la consommation instantanée des pods, exécuter la commande suivante: | ||
``` | ||
kubectl top pods | ||
```{{exec}} | ||
### Nodes | ||
Pour connaître la consommation instantanée des noeuds entiers, exécuter la commande suivante: | ||
``` | ||
kubectl top nodes | ||
```{{exec}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
kubectl get hpa hpa-example -o jsonpath='{.status.currentMetrics[0].resource.current.averageUtilization}' | grep -v '^0$' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
## 1/ Stopper la charge | ||
|
||
> Revenir dans le premier onglet "**Tab1**" | ||
- Sortir du pod _load-generator_ | ||
|
||
``` | ||
exit | ||
```{{exec interrupt}} | ||
## 2/ Analyser l'état du déploiement | ||
### Objet hpa | ||
Afficher l'état de l'objet hpa | ||
``` | ||
kubectl get hpa | ||
```{{exec}} | ||
Répéter l'opération à quelques secondes d'intervalle (jusqu'à 1 minute): Comment évolue la charge CPU moyenne ? | ||
### Charge instantanée | ||
Examiner l'évolution de la charge des pods et des noeuds | ||
``` | ||
kubectl top pods | ||
```{{exec}} | ||
``` | ||
kubectl top nodes | ||
```{{exec}} | ||
### Déploiement | ||
Vérifier le nombre de replicas pour votre déploiement | ||
``` | ||
kubectl get deployment | ||
```{{exec}} | ||
Que constatez-vous (le résultat peut prendre jusqu'à 10 minutes pour être visible) ? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
kubectl get hpa hpa-example -o jsonpath='{.status.currentMetrics[0].resource.current.averageUtilization}' | grep '^0$' |