Skip to content

Instantly share code, notes, and snippets.

@AlexisDucastel
Created December 6, 2021 22:24
Show Gist options
  • Save AlexisDucastel/e794bdba1a66a4512ae4a0a1959dd077 to your computer and use it in GitHub Desktop.
Save AlexisDucastel/e794bdba1a66a4512ae4a0a1959dd077 to your computer and use it in GitHub Desktop.
Solution possible pour le projet wordpress de la formation K8S infraBuilder
#====================================================
# ____
# / ___|___ _ __ ___ _ __ ___ ___ _ __
# | | / _ \| '_ ` _ \| '_ ` _ \ / _ \| '_ \
# | |__| (_) | | | | | | | | | | | (_) | | | |
# \____\___/|_| |_| |_|_| |_| |_|\___/|_| |_|
#
#====================================================
apiVersion: v1
kind: Secret
metadata:
name: wp-mysql
type: Opaque
data:
MYSQL_ROOT_PASSWORD: SmVTYXBwZWxsZUdyb290
MYSQL_PASSWORD: d3BQNHNz
---
apiVersion: v1
kind: ConfigMap
metadata:
name: wp-mysql
data:
MYSQL_DATABASE: wordpress
MYSQL_USER: wpuser
---
#===================================
# __ __ ____ ___ _
# | \/ |_ _/ ___| / _ \| |
# | |\/| | | | \___ \| | | | |
# | | | | |_| |___) | |_| | |___
# |_| |_|\__, |____/ \__\_\_____|
# |___/
#===================================
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: my-data
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: mysql
name: mysql
spec:
replicas: 1
selector:
matchLabels:
app: mysql
strategy:
type: Recreate
template:
metadata:
creationTimestamp: null
labels:
app: mysql
spec:
containers:
- envFrom:
- configMapRef:
name: wp-mysql
- secretRef:
name: wp-mysql
image: mysql:5.7
name: mysql
ports:
- name: mysql
containerPort: 3306
volumeMounts:
- name: mysql-data
subPath: data
mountPath: /var/lib/mysql
volumes:
- name: mysql-data
persistentVolumeClaim:
claimName: my-data
---
apiVersion: v1
kind: Service
metadata:
labels:
app: mysql
name: mysql
spec:
ports:
- port: 3306
protocol: TCP
targetPort: 3306
selector:
app: mysql
---
#====================================================
# _
# __ _____ _ __ __| |_ __ _ __ ___ ___ ___
# \ \ /\ / / _ \| '__/ _` | '_ \| '__/ _ \/ __/ __|
# \ V V / (_) | | | (_| | |_) | | | __/\__ \__ \
# \_/\_/ \___/|_| \__,_| .__/|_| \___||___/___/
# |_|
#====================================================
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: wp-data
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: wordpress
name: wordpress
spec:
replicas: 1
selector:
matchLabels:
app: wordpress
strategy:
type: Recreate
template:
metadata:
labels:
app: wordpress
spec:
containers:
- env:
- name: WORDPRESS_DB_HOST
value: mysql
- name: WORDPRESS_DB_NAME
valueFrom:
configMapKeyRef:
name: wp-mysql
key: MYSQL_DATABASE
- name: WORDPRESS_DB_USER
valueFrom:
configMapKeyRef:
name: wp-mysql
key: MYSQL_USER
- name: WORDPRESS_DB_PASSWORD
valueFrom:
secretKeyRef:
name: wp-mysql
key: MYSQL_PASSWORD
image: wordpress:5
name: wordpress
ports:
- name: http
containerPort: 80
volumeMounts:
- name: wordpress-data
mountPath: /var/www/html
volumes:
- name: wordpress-data
persistentVolumeClaim:
claimName: wp-data
---
apiVersion: v1
kind: Service
metadata:
labels:
app: wordpress
name: wordpress
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
app: wordpress
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: wordpress
spec:
rules:
- host: projet12.alp.ibd.sh
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: wordpress
port:
number: 80
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment