Autoscaling like a Pro-Deploy WordPress on GKE (Google Kubernetes Engine)

Reuel Lobo
2 min readFeb 12, 2024

--

Let me directly start on How to get this done, Rather than explaining the benefits of WordPress on GKE, you may be a business owner and looking for ultimate autoscaling for your WordPress website, Reach out to me on reuel53@gmail.com, if you need to make this a reality for your precious WordPress Website.

Create GKE Cluster.

Below are the YAML Files

# wordpress-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: wordpress
spec:
replicas: 1
selector:
matchLabels:
app: wordpress
template:
metadata:
labels:
app: wordpress
spec:
containers:
- name: wordpress
image: wordpress:latest
ports:
- containerPort: 80
env:
- name: WORDPRESS_DB_HOST
value: wordpress-mysql
- name: WORDPRESS_DB_USER
value: your_mysql_username
- name: WORDPRESS_DB_PASSWORD
value: your_mysql_password
- name: WORDPRESS_DB_NAME
value: wordpress
---
# mysql-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: wordpress-mysql
spec:
replicas: 1
selector:
matchLabels:
app: wordpress-mysql
template:
metadata:
labels:
app: wordpress-mysql
spec:
containers:
- name: mysql
image: mysql:5.7
env:
- name: MYSQL_ROOT_PASSWORD
value: your_mysql_root_password
- name: MYSQL_DATABASE
value: wordpress
- name: MYSQL_USER
value: your_mysql_username
- name: MYSQL_PASSWORD
value: your_mysql_password
ports:
- containerPort: 3306
---
# wordpress-service.yaml
apiVersion: v1
kind: Service
metadata:
name: wordpress
spec:
selector:
app: wordpress
ports:
- protocol: TCP
port: 80
targetPort: 80
type: LoadBalancer
---
# mysql-service.yaml
apiVersion: v1
kind: Service
metadata:
name: wordpress-mysql
spec:
selector:
app: wordpress-mysql
ports:
- protocol: TCP
port: 3306
targetPort: 3306

Save each of these configurations in separate files (wordpress-deployment.yaml, mysql-deployment.yaml, wordpress-service.yaml, mysql-service.yaml).

Apply these configurations to your Kubernetes cluster using the kubectl apply command:

kubectl apply -f wordpress-deployment.yaml
kubectl apply -f mysql-deployment.yaml
kubectl apply -f wordpress-service.yaml
kubectl apply -f mysql-service.yaml

This will deploy WordPress with MySQL on your Kubernetes cluster. Adjust the environment variables and configuration values as per your requirements. Additionally, consider using PersistentVolumeClaims (PVCs) for persistent storage if needed.

That's it, Now you have deployed WordPress on GKE and now you can migrate your site.

Feel free to reach out to me if the above is your requirement.

Email: reuel53@gmail.com

--

--