Skip to content

Lab8 Secret Solution

Secret de type Volume

Copier le fichier /etc/nginx/nginx.conf à partir d’un pod web existant

Terminal window
kubectl cp web:/etc/nginx/nginx.conf nginx.conf

Modifier le fichier et créer un Secret nommé nginx-conf

Terminal window
kubectl create secret generic nginx-conf --from-file=nginx.conf

Créer un pod web avec le Secret nginx-conf

Terminal window
vi web.yml
apiVersion: v1
kind: Pod
metadata:
name: web
labels:
app: web
spec:
containers:
- name: www
image: nginx:1.17-alpine
volumeMounts:
- name: config
mountPath: "/etc/nginx/nginx.conf"
subPath: "nginx.conf"
volumes:
- name: config
secret:
secretName: nginx-conf

Vérifier le fichier de conf /etc/nginx/nginx.conf du pod web

Terminal window
kubectl exec -it web -- sh
cat /etc/nginx/nginx.conf

Secret de type variable d’environnement

Créer un Secret nommé mysql-pass qui contient une clé password et une valeur root

Terminal window
kubectl create secret generic mysql-pass --from-literal=password=root

Visualiser le Secret

Terminal window
kubectl get sc/mysql-pass -o yaml

Créer un pod mysql et initialiser le ROOT_PASSWORD de mysql

Terminal window
vi mysql.yml
apiVersion: v1
kind: Pod
metadata:
name: mysql
spec:
containers:
- image: mysql:5.6
name: mysql
env:
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-pass
key: password
Terminal window
kubectl apply -f mysql.yml

Vérifier que le pod mysql est Running

Terminal window
kubectl get pods