Wordpress
Warning
This site is still under development.
Wordpress is a free and open-source content management system (CMS) based on PHP and MySQL. Features include a plugin architecture and a template system. WordPress was used by more than 27.5% of the top 10 million websites as of February 2017. WordPress is reportedly the most popular website management or blogging system in use on the Web, supporting more than 60 million websites.
Pre-requirements
A Kubernetes Serverless cluster
kubectl installed
Setup the database
First, create a MariaDB database using the StatefulSet controller.
kubectl apply -f - <<EOF
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: mariadb
spec:
selector:
matchLabels:
app: mariadb
serviceName: mariadb
replicas: 1
template:
metadata:
labels:
app: mariadb
spec:
containers:
- name: mariadb
image: mariadb:11.0
env:
- name: MARIADB_ROOT_PASSWORD
value: password
- name: MARIADB_DATABASE
value: wordpress
- name: MARIADB_USER
value: wordpress
- name: MARIADB_PASSWORD
value: password
resources:
requests:
memory: 400Mi
cpu: 250m
limits:
memory: 400Mi
cpu: 250m
ports:
- name: mariadb
containerPort: 3306
volumeMounts:
- name: mariadb
mountPath: /var/lib/mysql
volumeClaimTemplates:
- metadata:
name: mariadb
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
EOF
After a few seconds, the database will be ready.
kubectl get statefulset mariadb
NAME READY AGE
mariadb 1/1 13s
Now, create a service to expose the database within the cluster.
kubectl apply -f - <<EOF
apiVersion: v1
kind: Service
metadata:
name: mariadb
spec:
selector:
app: mariadb
ports:
- name: mariadb
port: 3306
EOF
Setup the application
Then, create a Wordpress application using the Deployment controller.
kubectl apply -f - <<EOF
apiVersion: apps/v1
kind: Deployment
metadata:
name: wordpress
spec:
selector:
matchLabels:
app: wordpress
replicas: 1
template:
metadata:
labels:
app: wordpress
spec:
containers:
- name: wordpress
image: wordpress:6.3
env:
- name: WORDPRESS_DB_HOST
value: mariadb
- name: WORDPRESS_DB_USER
value: wordpress
- name: WORDPRESS_DB_PASSWORD
value: password
- name: WORDPRESS_DB_NAME
value: wordpress
resources:
requests:
memory: 400Mi
cpu: 250m
limits:
memory: 400Mi
cpu: 250m
ports:
- name: wordpress
containerPort: 80
volumeMounts:
- name: wordpress
mountPath: /var/www/html
volumes:
- name: wordpress
persistentVolumeClaim:
claimName: wordpress
---
apiVersion: v1
kind: Service
metadata:
name: wordpress
spec:
selector:
app: wordpress
ports:
- name: wordpress
port: 80
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: wordpress
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: wordpress
spec:
rules:
- host: wordpress.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: wordpress
port:
number: 80
EOF
Soon, the application will be ready.
kubectl get deployment wordpress
NAME READY UP-TO-DATE AVAILABLE AGE
wordpress 1/1 1 1 13s
Access the application
To access the application, you need to add an entry to your /etc/hosts
file or to your DNS server.
Get the IP address of the cluster.
cat $KUBECONFIG | grep server
# server: https://<dns-name>
Resolve the DNS name to an IP address.
dig +short <dns-name>
# <ip-address>
Add an entry to your /etc/hosts
file, replacing <ip-address>
with the IP address of the cluster.
Or add an entry to your DNS server.
echo "<ip-address> wordpress.example.com" | sudo tee -a /etc/hosts
Now, you can access the application at http://wordpress.example.com.
Cleanup
kubectl delete deployment wordpress
kubectl delete service wordpress
kubectl delete ingress wordpress
kubectl delete pvc wordpress
kubectl delete statefulset mariadb
kubectl delete service mariadb
kubectl delete pvc mariadb-mariadb-0