How To Launch WordPress In Kubernetes Multi-Node Cluster

Gupta Aditya
4 min readApr 24, 2021

--

Hey, guys hope you all are doing good in today's article we are going to set our own WordPress server on our own Kubernetes multi-node cluster. If you have not yet read how to launch our own Kubernetes multi-node cluster then do read it link given below we have used ansible the automation to once you create the script then just you need to give the command and not have to repeat the same lengthy process.

Let's get started with the process of setting up the WordPress for that we need a Mysql server so that data of WordPress can be stored and while setting up the Mysql we have to give our database root password entering root password directly into the file is not a good option as the file is maintained by many people there can be a huge security issue in that case so to overcome it is suggested to write password in a resource called secret which can be managed by admin. So in total, we have to create three yml files one for making secret, one for launching WordPress, and one for launching MySQL server. You can find all these files in the GitHub repo attached at the end of the article.

Let's start making and understanding our first file which will launch create secret for us which we can use while configuring MySQL server.

File for makind secrets
apiVersion: v1
kind: Secret
metadata:
name: "name you want to give to your secret"
type: Opaque
data:
"key": "value encode in base 64"
Eg:-
apiVersion: v1
kind: Secret
metadata:
name: secret-demo
type: Opaque
data:
password: UmVkaGF0

Save the above file with any name but the file extension should be yml. After saving the file using the below command to make secrets

kubectl create -f filenameEg:-kubectl create -f secret.yml

After creating a secret successfully we will now configure our MySQL server using the below file.

Note below file is just for an explanation for the original file head to GitHub link provided at the end

#making service for mysql
apiVersion: v1
kind: Service
metadata:
name: [service name]
labels:
[key]: [value]
spec:
ports:
— port: 3306
selector:
[key]: [value]
clusterIP: None
# here we have set cluster ip to none to make headles service so that cluster ip service get adress of mysql pod and only internal pod can connect to it
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: [PVC name]
labels:
key: value
spec:
accessModes:
— ReadWriteOnce
resources:
requests:
storage: [size]
— -
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
name: [deployment name]
labels:
key: value
spec:
selector:
matchLabels:
key: value
strategy:
type: Recreate
template:
metadata:
labels:
key: value
spec:
containers:
— image: mysql:5.6
name: [pod name]
env:
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: [secret name]
key: [secret key]
ports:
- containerPort: 3306
name: mysql
volumeMounts:
- name: [volume name]
mountPath: /var/lib/mysql
volumes:
- name: [volume name]
persistentVolumeClaim:
claimName: [pvc name]

After creating and saving the file using the below command to launch the MySQL system.

kubectl create -f filename

Now we are all set to launch our frontend application WordPress using the yml code which is quite similar to the above code to make things easier I am not adding code here you can find the code in the GitHub repo link attached at the end. After creating the file the above command to run to launch the WordPress server.

After launching the WordPress use the below command to get port

kubectl get service

From the above command, you will get output with the service name and port number get the port number for service which is attached with WordPress.

After going to that port number you could able to see your WordPress screen as below.

It's done we have successfully launched WordPress on our multi-node Kubernetes cluster.

Here is one create command to all readers who have put effort to read it till here creating file again and again can be a boring job to overcome this we could make one kustomization file that contains all the files and will also generate secret for us automatically. All other information like how to run kustomization file and why to make you could find it in git hub repo attached below

Github link:-https://github.com/guptaadi123/wordpress-on-k8s_multi-node.git

Guys, here we come to the end of this blog I hope you all like it and found it informative. If have any query feel free to reach me :)

Guys follow me for such amazing blogs and if have any review then please let me know I will keep those points in my mind next time while writing blogs. If want to read more such blog to know more about me here is my website link https://avg-g.technology.Guys Please do not hesitate to keep 👏👏👏👏👏 for it (An Open Secret: You can clap up to 50 times for a post, and the best part is, it wouldn’t cost you anything), also feel free to share it across. This really means a lot to me.

--

--