211 lines
4.7 KiB
YAML
211 lines
4.7 KiB
YAML
apiVersion: v1
|
|
kind: Secret
|
|
metadata:
|
|
name: credencials-bd
|
|
type: Opaque
|
|
data:
|
|
password: c3VwZXJzZWNyZXQ= # "supersecret" en base64
|
|
---
|
|
apiVersion: v1
|
|
kind: PersistentVolumeClaim
|
|
metadata:
|
|
name: wordpress-pvc
|
|
spec:
|
|
accessModes:
|
|
- ReadWriteOnce
|
|
resources:
|
|
requests:
|
|
storage: 2Gi
|
|
---
|
|
apiVersion: v1
|
|
kind: ConfigMap
|
|
metadata:
|
|
name: mariadb-configmap
|
|
data:
|
|
primary.cnf: |
|
|
[mariadb]
|
|
log-bin
|
|
log-basename=my-mariadb
|
|
|
|
replica.cnf: |
|
|
[mariadb]
|
|
log-basename=my-mariadb
|
|
|
|
primary.sql: |
|
|
CREATE USER 'repluser'@'%' IDENTIFIED BY 'replsecret';
|
|
GRANT REPLICATION REPLICA ON *.* TO 'repluser'@'%';
|
|
CREATE DATABASE IF NOT EXISTS wordpress;
|
|
|
|
secondary.sql: |
|
|
CHANGE MASTER TO
|
|
MASTER_HOST='mariadb-sts-0.servei-mariadb.default.svc.cluster.local',
|
|
MASTER_USER='repluser',
|
|
MASTER_PASSWORD='replsecret',
|
|
MASTER_CONNECT_RETRY=10;
|
|
START SLAVE;
|
|
---
|
|
apiVersion: v1
|
|
kind: Service
|
|
metadata:
|
|
name: servei-mariadb
|
|
spec:
|
|
selector:
|
|
app: mariadb
|
|
ports:
|
|
- protocol: TCP
|
|
port: 3306
|
|
targetPort: 3306
|
|
clusterIP: None
|
|
---
|
|
apiVersion: apps/v1
|
|
kind: StatefulSet
|
|
metadata:
|
|
name: mariadb-sts
|
|
spec:
|
|
serviceName: "servei-mariadb"
|
|
replicas: 3
|
|
selector:
|
|
matchLabels:
|
|
app: mariadb
|
|
template:
|
|
metadata:
|
|
labels:
|
|
app: mariadb
|
|
spec:
|
|
initContainers:
|
|
- name: init-mariadb
|
|
image: mariadb:lts-ubi
|
|
command:
|
|
- bash
|
|
- "-c"
|
|
- |
|
|
set -ex
|
|
echo 'Starting init-mariadb'
|
|
ls /mnt/config-map
|
|
[[ `hostname` =~ -([0-9]+)$ ]] || exit 1
|
|
ordinal=${BASH_REMATCH[1]}
|
|
if [[ $ordinal -eq 0 ]]; then
|
|
cp /mnt/config-map/primary.cnf /etc/mysql/conf.d/server-id.cnf
|
|
cp /mnt/config-map/primary.sql /docker-entrypoint-initdb.d
|
|
else
|
|
cp /mnt/config-map/replica.cnf /etc/mysql/conf.d/server-id.cnf
|
|
cp /mnt/config-map/secondary.sql /docker-entrypoint-initdb.d
|
|
fi
|
|
echo server-id=$((3000 + ordinal)) >> /etc/mysql/conf.d/server-id.cnf
|
|
ls /etc/mysql/conf.d/
|
|
cat /etc/mysql/conf.d/server-id.cnf
|
|
volumeMounts:
|
|
- name: mariadb-config-map
|
|
mountPath: /mnt/config-map
|
|
- name: mariadb-config
|
|
mountPath: /etc/mysql/conf.d/
|
|
- name: initdb
|
|
mountPath: /docker-entrypoint-initdb.d
|
|
containers:
|
|
- name: mariadb
|
|
image: mariadb:lts-ubi
|
|
ports:
|
|
- containerPort: 3306
|
|
name: mariadb-port
|
|
env:
|
|
- name: MARIADB_ROOT_PASSWORD
|
|
valueFrom:
|
|
secretKeyRef:
|
|
name: credencials-bd
|
|
key: password
|
|
- name: MYSQL_INITDB_SKIP_TZINFO
|
|
value: "1"
|
|
volumeMounts:
|
|
- name: datadir
|
|
mountPath: /var/lib/mysql
|
|
- name: mariadb-config
|
|
mountPath: /etc/mysql/conf.d/
|
|
- name: initdb
|
|
mountPath: /docker-entrypoint-initdb.d
|
|
volumes:
|
|
- name: mariadb-config-map
|
|
configMap:
|
|
name: mariadb-configmap
|
|
- name: mariadb-config
|
|
emptyDir: {}
|
|
- name: initdb
|
|
emptyDir: {}
|
|
volumeClaimTemplates:
|
|
- metadata:
|
|
name: datadir
|
|
spec:
|
|
accessModes:
|
|
- ReadWriteOnce
|
|
resources:
|
|
requests:
|
|
storage: 2Gi
|
|
---
|
|
apiVersion: apps/v1
|
|
kind: Deployment
|
|
metadata:
|
|
name: wordpress-deployment
|
|
spec:
|
|
replicas: 1
|
|
selector:
|
|
matchLabels:
|
|
app: wordpress
|
|
template:
|
|
metadata:
|
|
labels:
|
|
app: wordpress
|
|
spec:
|
|
containers:
|
|
- name: wordpress
|
|
image: wordpress:latest
|
|
env:
|
|
- name: WORDPRESS_DB_HOST
|
|
value: "mariadb-sts-0.servei-mariadb.default.svc.cluster.local" # Apunta al pod primari de MariaDB
|
|
- name: WORDPRESS_DB_PASSWORD
|
|
valueFrom:
|
|
secretKeyRef:
|
|
name: credencials-bd
|
|
key: password
|
|
- name: WORDPRESS_DB_USER
|
|
value: "root"
|
|
- name: WORDPRESS_DB_NAME
|
|
value: "wordpress"
|
|
ports:
|
|
- containerPort: 80
|
|
volumeMounts:
|
|
- name: dades-web
|
|
mountPath: /var/www/html
|
|
volumes:
|
|
- name: dades-web
|
|
persistentVolumeClaim:
|
|
claimName: wordpress-pvc
|
|
---
|
|
apiVersion: v1
|
|
kind: Service
|
|
metadata:
|
|
name: servei-wordpress
|
|
spec:
|
|
type: NodePort
|
|
selector:
|
|
app: wordpress
|
|
ports:
|
|
- protocol: TCP
|
|
port: 80
|
|
targetPort: 80
|
|
nodePort: 30010
|
|
---
|
|
apiVersion: networking.k8s.io/v1
|
|
kind: Ingress
|
|
metadata:
|
|
name: wordpress-ingress
|
|
spec:
|
|
rules:
|
|
- host: elmeublog.local
|
|
http:
|
|
paths:
|
|
- path: /
|
|
pathType: Prefix
|
|
backend:
|
|
service:
|
|
name: servei-wordpress
|
|
port:
|
|
number: 80 |