Skip to content

This repository showcases the deployment of a WordPress application with a MySQL database on a Kubernetes cluster using kubeadm, with secure communication and seamless scaling. πŸš€

Notifications You must be signed in to change notification settings

Kartikk-26/WordPress-Deployment-on-K8s

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

βš“οΈ WordPress Deployment on Kubernetes Cluster

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.


πŸ“š Project Overview

1. βœ… Launching EC2 Instances

  • Launched 3 EC2 instances using t2.medium type.
  • OS: Ubuntu 22.04 LTS

2. ⚑ Kubernetes Cluster Setup

  • Set up the Kubernetes cluster using kubeadm.
  • Followed steps to install Kubernetes v1.30.2 and configure the control plane and worker nodes.

🎯 Expected Outcomes

  • βœ… 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! πŸŽ‰ Image2

🎯 Objective

To deploy a WordPress application connected to a MySQL database using Kubernetes, ensuring secure communication and scalability.


βš™οΈ Kubernetes Configuration

1. πŸ—‚οΈ Create Namespace

kubectl create ns mywebsite

2. πŸ›’οΈ MySQL Deployment

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"

3. 🧩 MySQL Service (ClusterIP)

kubectl expose deployment -n mywebsite mysql --port 3306 --target-port 3306 --name=mysql-svc

4. 🌐 WordPress Deployment

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"

5. 🌐 WordPress Service (NodePort)

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

⚑ Access WordPress in Browser

http://<EC2_PUBLIC_IP>:30080

πŸ› οΈ ConfigMap for Environment Variables

1. πŸ“„ Create MySQL ConfigMap

kubectl create configmap app-db --from-literal=MYSQL_ROOT_PASSWORD=redhat --from-literal=MYSQL_DATABASE=bigdata -n mywebsite

2. πŸ“„ Create WordPress ConfigMap

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

πŸš€ Using ConfigMap in Deployment

Modify the environment section of your deployment file to reference the ConfigMap:

envFrom:
  - configMapRef:
      name: app-db
  - configMapRef:
      name: app-wp

πŸ“‘ Verifying Deployment

  1. Check if all pods are running:
kubectl get pods -n mywebsite
  1. Verify services:
kubectl get svc -n mywebsite
  1. Access WordPress via browser:
http://<EC2_PUBLIC_IP>:30080

πŸ“ Conclusion

  • βœ… Successfully deployed a WordPress application with a MySQL backend on a Kubernetes cluster.
  • βœ… Used ConfigMaps to manage configuration, ensuring application portability and better management.

πŸ“’ Let's Connect!

  • 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!

About

This repository showcases the deployment of a WordPress application with a MySQL database on a Kubernetes cluster using kubeadm, with secure communication and seamless scaling. πŸš€

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published