Skip to content

Lab6 Volumes Solutions

Producteur

Créer un pvc web et un pv web qui pointe sur un volume web de type nfs pour créer un fichier index.html

Création du pv nfs

Terminal window
vi nfs-pv.yml
apiVersion: v1
kind: PersistentVolume
metadata:
name: nfs-pv
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteMany
nfs:
path: /home/shares/user12
server: 192.168.1.5

Création du pvc nfs

Terminal window
vi nfs-pvc.yml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: nfs-pvc
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 1Gi

Créer un daemonSet nommé web basé sur l’image alpine

Terminal window
vi ds-nfs.yml
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: web-ds
spec:
selector:
matchLabels:
app: web-ds
template:
metadata:
labels:
app: web-ds
spec:
containers:
- name: daemon
image: alpine:3.12
command: ["/bin/sh"]
args: ["-c","while true; do echo `hostname` `date` >> /mnt/index.html ; sleep 60 ;done"]
volumeMounts:
- name: data
mountPath: /mnt
volumes:
- name: data
persistentVolumeClaim:
claimName: nfs-pvc

Consommateur

Créer un déploiement nommé web basé sur l’image httpd

Terminal window
vi deploy-nfs.yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-deploy
spec:
replicas: 4
selector:
matchLabels:
app: web-deploy
template:
metadata:
labels:
app: web-deploy
spec:
containers:
- name: nginx
image: nginx:1.17-alpine
ports:
- containerPort: 80
volumeMounts:
- name: data
mountPath: /usr/share/nginx/html
volumes:
- name: data
persistentVolumeClaim:
claimName: nfs-pvc
readOnly: true

Service NodePort

Créer un service nommé web de type NodePort qui rassemble les pods du DaemonSet web

Terminal window
vi service-nfs.yml
apiVersion: v1
kind: Service
metadata:
name: web-svc
spec:
selector:
app: web-deploy
type: NodePort
ports:
- port: 80
targetPort: 80
nodePort: 30001

Appliquer les spécifications

Terminal window
kubectl apply -f .

Test

Depuis le poste de travail, exécuter la commande “curl node1:30001”

Terminal window
curl host111:30001