This project demonstrates the deployment of a WordPress application with a MySQL database on a Kubernetes cluster using kubeadm
. It covers the setup of namespaces, deployments, services, and ConfigMaps to ensure a smooth and secure deployment.
- Launched 3 EC2 instances using
t2.medium
type. - OS: Ubuntu 22.04 LTS
- Set up the Kubernetes cluster using
kubeadm
. - Followed steps to install Kubernetes v1.30.2 and configure the control plane and worker nodes.
- β Successful deployment of WordPress and MySQL on a Kubernetes cluster.
- β Proper configuration of namespaces, deployments, services, and ConfigMaps.
- β Secure and seamless communication between WordPress and MySQL using Kubernetes services.
- β WordPress accessible via the public IP or domain on port 30080 using NodePort.
- β Hands-on experience in managing containerized applications and using kubeadm for cluster setup.
- β
Done! WordPress is now successfully deployed on your Kubernetes cluster! π
To deploy a WordPress application connected to a MySQL database using Kubernetes, ensuring secure communication and scalability.
kubectl create ns mywebsite
Create a mysql.yaml
file:
apiVersion: apps/v1
kind: Deployment
metadata:
name: mysql
namespace: mywebsite
spec:
replicas: 1
selector:
matchLabels:
app: mysql
template:
metadata:
labels:
app: mysql
spec:
containers:
- name: db
image: mysql
env:
- name: MYSQL_ROOT_PASSWORD
value: "redhat"
- name: MYSQL_DATABASE
value: "bigdata"
kubectl expose deployment -n mywebsite mysql --port 3306 --target-port 3306 --name=mysql-svc
Create a wordpress.yaml
file:
apiVersion: apps/v1
kind: Deployment
metadata:
name: wordpress
namespace: mywebsite
spec:
replicas: 1
selector:
matchLabels:
app: wordpress
template:
metadata:
labels:
app: wordpress
spec:
containers:
- name: wp
image: wordpress
env:
- name: WORDPRESS_DB_HOST
value: "10.96.164.193"
- name: WORDPRESS_DB_USER
value: "root"
- name: WORDPRESS_DB_PASSWORD
value: "redhat"
- name: WORDPRESS_DB_NAME
value: "bigdata"
Create wp-svc.yaml
:
apiVersion: v1
kind: Service
metadata:
name: wp-svc
namespace: mywebsite
spec:
selector:
app: wordpress
type: NodePort
ports:
- protocol: TCP
port: 80
targetPort: 80
nodePort: 30080
http://<EC2_PUBLIC_IP>:30080
kubectl create configmap app-db --from-literal=MYSQL_ROOT_PASSWORD=redhat --from-literal=MYSQL_DATABASE=bigdata -n mywebsite
kubectl create configmap app-wp -n mywebsite \
--from-literal=WORDPRESS_DB_HOST=10.110.46.197 \
--from-literal=WORDPRESS_DB_USER=root \
--from-literal=WORDPRESS_DB_PASSWORD=redhat \
--from-literal=WORDPRESS_DB_NAME=bigdata
Modify the environment section of your deployment file to reference the ConfigMap:
envFrom:
- configMapRef:
name: app-db
- configMapRef:
name: app-wp
- Check if all pods are running:
kubectl get pods -n mywebsite
- Verify services:
kubectl get svc -n mywebsite
- Access WordPress via browser:
http://<EC2_PUBLIC_IP>:30080
- β Successfully deployed a WordPress application with a MySQL backend on a Kubernetes cluster.
- β Used ConfigMaps to manage configuration, ensuring application portability and better management.
- Stay updated on LinkedIn for more DevOps projects and insights.
- Follow along as I explore Cloud Infrastructure, Ansible Automation, and DevOps practices.
- Let's collaborate and build scalable solutions together!