-
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
ada693c
commit 7a94fbc
Showing
20 changed files
with
328 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,4 @@ | ||
Retrouver le mot de passe: | ||
|
||
kubectl get secret mysql -o jsonpath='{.data.password}' | base64 -d | ||
|
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,8 @@ | ||
Le déploiement possède une image avec un tag non valide | ||
image: nginx:<changeme> #mettre: nginx:1.9.14 | ||
|
||
Il est possible d'utiliser un outil tel que vim pour remplacer nginx:<changeme> en nginx:1.9.14 | ||
|
||
Pour appliquer le changement d'un fichier yaml, utiliser kubectl apply -f frontend.yaml | ||
|
||
echo 'kubectl apply -f frontend.yaml' > res-step2 |
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,12 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: mysql | ||
labels: | ||
app: mysql | ||
spec: | ||
type: ClusterIP | ||
ports: | ||
- port: 3306 | ||
selector: | ||
app: mysql |
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,10 @@ | ||
kind: PersistentVolumeClaim | ||
apiVersion: v1 | ||
metadata: | ||
name: mysql-volumeclaim | ||
spec: | ||
accessModes: | ||
- ReadWriteOnce | ||
resources: | ||
requests: | ||
storage: 1Gi |
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,42 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: mysql | ||
labels: | ||
app: mysql | ||
spec: | ||
strategy: | ||
type: Recreate | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: mysql | ||
template: | ||
metadata: | ||
labels: | ||
app: mysql | ||
spec: | ||
containers: | ||
- image: mysql:5.6 | ||
name: mysql | ||
env: | ||
- name: MYSQL_ROOT_PASSWORD | ||
valueFrom: | ||
secretKeyRef: | ||
name: mysql | ||
key: password | ||
ports: | ||
- containerPort: 3306 | ||
name: mysql | ||
volumeMounts: | ||
- name: mysql-persistent-storage | ||
mountPath: /var/lib/mysql | ||
resources: | ||
requests: | ||
memory: 400Mi | ||
limits: | ||
cpu: 0.1 | ||
volumes: | ||
- name: mysql-persistent-storage | ||
persistentVolumeClaim: | ||
claimName: mysql-volumeclaim |
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,15 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
labels: | ||
app: wordpress | ||
name: wordpress | ||
spec: | ||
type: NodePort | ||
ports: | ||
- port: 80 | ||
targetPort: 80 | ||
nodePort: 30000 | ||
protocol: TCP | ||
selector: | ||
app: wordpress |
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,10 @@ | ||
kind: PersistentVolumeClaim | ||
apiVersion: v1 | ||
metadata: | ||
name: wordpress-volumeclaim | ||
spec: | ||
accessModes: | ||
- ReadWriteOnce | ||
resources: | ||
requests: | ||
storage: 1Gi |
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 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: wordpress | ||
labels: | ||
app: wordpress | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: wordpress | ||
template: | ||
metadata: | ||
labels: | ||
app: wordpress | ||
spec: | ||
containers: | ||
- image: wordpress | ||
name: wordpress | ||
env: | ||
- name: WORDPRESS_DB_HOST | ||
value: mysql:3306 | ||
- name: WORDPRESS_DB_PASSWORD | ||
valueFrom: | ||
secretKeyRef: | ||
name: mysql | ||
key: password | ||
ports: | ||
- containerPort: 80 | ||
name: wordpress | ||
volumeMounts: | ||
- name: wordpress-persistent-storage | ||
mountPath: /var/www/html | ||
resources: | ||
limits: | ||
cpu: 0.1 | ||
memory: "50Mi" | ||
volumes: | ||
- name: wordpress-persistent-storage | ||
persistentVolumeClaim: | ||
claimName: wordpress-volumeclaim |
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,5 @@ | ||
#!/bin/bash | ||
|
||
echo "Welcome to the Sfeir School Volume scenario" | ||
echo " Enjoy :-)" | ||
|
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,40 @@ | ||
{ | ||
"title": "Volume", | ||
"description": "Gérer les données dans Kubernetes", | ||
"details": { | ||
"intro": { | ||
"text": "intro.md", | ||
"background": "background.sh", | ||
"foreground": "foreground.sh" | ||
}, | ||
"steps": [ | ||
{ | ||
"title": "Créer un secret pour la base de données", | ||
"text": "step1/step1.md", | ||
"verify": "step1/verify.sh" | ||
}, | ||
{ | ||
"title": "Déployer un Wordpress complet", | ||
"text": "step2/step2.md", | ||
"verify": "step2/verify.sh" | ||
}, | ||
{ | ||
"title": "Détruire et relancer des pods", | ||
"text": "step3/step3.md" | ||
}, | ||
{ | ||
"title": "Nettoyage", | ||
"text": "step4/step4.md", | ||
"verify": "step4/verify.sh" | ||
} | ||
], | ||
"assets": { | ||
"host01": [ | ||
{"file": "volume/*", "target": "/root", "chmod": "+w"} | ||
] | ||
} | ||
}, | ||
"backend": { | ||
"imageid": "kubernetes-kubeadm-1node" | ||
} | ||
} |
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,5 @@ | ||
# Volumes | ||
|
||
Les fichiers sur disque dans un conteneur sont éphémères, ce qui présente des problèmes pour des applications non-triviales lorsqu'elles s'exécutent dans des conteneurs. Premièrement, lorsqu'un conteneur plante, kubelet va le redémarrer mais les fichiers seront perdus - le conteneur démarre avec un état propre. Deuxièmement, lorsque plusieurs conteneurs s'exécutent ensemble dans un `Pod`, il est souvent nécessaire de partager des fichiers entre ces conteneurs. L'abstraction Kubernetes `Volume` résout ces deux problèmes. | ||
|
||
Le but de ce TP est de déployer une stack Wordpress complète avec une base de données MySQL. |
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,36 @@ | ||
## 1/ Créer un secret pour votre base de données | ||
|
||
Executer la commande suivante: | ||
``` | ||
kubectl create secret generic mysql --from-literal=password=$(openssl rand -hex 12) | ||
```{{exec}} | ||
### Question ? | ||
- Quelle est le mot de passe généré ? | ||
Indices pour le retrouver: | ||
1. Afficher le secret en format YAML | ||
``` | ||
kubectl get secret mysql -o yaml | ||
```{{exec}} | ||
2. Dans ce yamml, repérer le chemin de l'élément qui contient le mot de passe, et l'extraire avec le paramètre _jsonpath_ de kubectl | ||
``` | ||
kubectl get secret mysql -o jsonpath='{.mon.chemin.ici}' | ||
``` | ||
3. Attention, la valeur est encodée en base64, il faut donc la décoder: | ||
``` | ||
echo 'mon_MoT_de_PaSsE_enCOde==' | base64 -d | ||
``` | ||
- Ecrire la valeur de ce mot de passe dans le fichier /tmp/res-step1 | ||
> vous pouvez utiliser la commande `echo '..mot_de_passe_trouvé..' > /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 $(kubectl get secret mysql -o jsonpath='{.data.password}' | base64 -d) /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,61 @@ | ||
## 1/ Créer les volumes | ||
Appliquer ces 2 commandes | ||
|
||
``` | ||
kubectl apply -f volume/mysql-volumeclaim.yaml | ||
kubectl apply -f volume/wordpress-volumeclaim.yaml | ||
```{{exec}} | ||
## 2/ Créer ma base de données MySQL | ||
Les descripteurs permettant de déployer une base de données sont founis dans le TP. Les examiner et les appliquer: | ||
``` | ||
cat volume/mysql.yaml | ||
```{{exec}} | ||
``` | ||
kubectl apply -f volume/mysql.yaml | ||
```{{exec}} | ||
``` | ||
cat volume/mysql-service.yaml | ||
```{{exec}} | ||
``` | ||
kubectl apply -f volume/mysql-service.yaml | ||
```{{exec}} | ||
## 3/ Créer l'instance Wordpress et l'exposer | ||
Les descripteurs sont founis dans le TP. Les examiner et les appliquer: | ||
``` | ||
cat volume/wordpress.yaml | ||
```{{exec}} | ||
``` | ||
kubectl apply -f volume/wordpress.yaml | ||
```{{exec}} | ||
``` | ||
cat volume/wordpress-service.yaml | ||
```{{exec}} | ||
``` | ||
kubectl apply -f volume/wordpress-service.yaml | ||
```{{exec}} | ||
## 4/ Accédez à votre wordpress | ||
``` | ||
curl http://$(kubectl get service wordpress -o jsonpath="{.status.loadBalancer.ingress[0].ip}") | ||
```{{exec}} | ||
### Challenge | ||
Accédez à l'application depuis votre navigateur | ||
- Trouver l'IP | ||
- Se connecter en http | ||
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,12 @@ | ||
## 1/ Détruire des pods mysql et wordpress | ||
|
||
``` | ||
kubectl delete pods -l="app=mysql" | ||
```{{exec}} | ||
``` | ||
kubectl delete pods -l="app=wordpress" | ||
```{{exec}} | ||
### Question ? | ||
Que se passe-t-il ? (un peu de patience quand même ;) ) |
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,12 @@ | ||
## 1/ Nettoyer l'environnement | ||
|
||
Effacer tous les objets crées. | ||
|
||
``` | ||
kubectl delete service wordpress | ||
kubectl delete deployment wordpress | ||
kubectl delete pvc wordpress | ||
kubectl delete service mysql | ||
kubectl delete deployment mysql | ||
kubectl delete pvc mysql | ||
```{{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 |