Skip to content

digvijay-y/wordpress-k8s

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

WordPress on Kubernetes with Monitoring

A production-ready WordPress deployment on Kubernetes with custom Docker images, Prometheus monitoring, and Grafana visualization. Features OpenResty (Nginx with Lua) as a reverse proxy, persistent storage for scaling, and comprehensive metrics collection.

Features

  • Custom Docker Images: WordPress, MySQL, and OpenResty built from Dockerfiles
  • OpenResty with Lua: Nginx compiled with Lua support for advanced routing
  • ReadWriteMany Volumes: Persistent storage supporting horizontal scaling
  • Prometheus Monitoring: Real-time metrics collection and alerting
  • Grafana Dashboards: Visualization of nginx requests, error rates, and pod CPU
  • Helm Charts: Easy deployment and management

Prerequisites

  • Kubernetes cluster (minikube, kind, or cloud provider)
  • kubectl configured to access your cluster
  • Helm 3.x installed

Architecture

Internet → Nginx (OpenResty + Lua) → WordPress (PHP-FPM) → MySQL
              ↓
         Nginx Exporter → Prometheus → Grafana
              ↓
         Pod Metrics

Components:

  • OpenResty (Nginx): Reverse proxy with Lua scripting and Prometheus exporter
  • WordPress: PHP-FPM application server with persistent storage
  • MySQL: Database with persistent volume
  • Prometheus: Metrics collection and alerting engine
  • Grafana: Metrics visualization with pre-configured dashboards

Quick Start

1. Deploy WordPress Stack

# From the project root
helm install my-release ./charts/wordpress

This creates:

  • WordPress deployment with custom Docker image
  • MySQL database with PersistentVolumeClaim (ReadWriteMany)
  • OpenResty (Nginx) with Lua support and metrics exporter
  • Persistent volumes for WordPress content and database

Verify deployment:

kubectl get pods
kubectl get pvc
kubectl get svc

2. Deploy Monitoring Stack

# Add Prometheus community Helm repository
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update

# Install Prometheus and Grafana
helm install monitoring prometheus-community/kube-prometheus-stack

Wait for all pods to be ready:

kubectl get pods -w

3. Access Services

WordPress Site

# Get the URL (for minikube)
minikube service nginx --url

# Or for cloud deployments
kubectl get svc nginx

Visit the URL in your browser to complete WordPress installation.

Grafana Dashboard

# Port forward Grafana
kubectl port-forward svc/monitoring-grafana 3000:80
kubectl get secret monitoring-grafana -o jsonpath="{.data.admin-password}" | base64 --decode

Grafana Dashboard

Prometheus UI

kubectl port-forward svc/monitoring-kube-prometheus-prometheus 9090:9090

Prometheus Alerts

Verify Data Sources

Grafana comes pre-configured with Prometheus and Alertmanager data sources. To verify:

  • Navigate to Configuration → Data Sources in Grafana
  • Both Prometheus and Alertmanager should show as connected

Grafana Data Sources

Monitoring & Metrics

This project implements comprehensive monitoring as per production requirements:

Monitored Metrics

1. Pod CPU Utilization

  • Tracks CPU usage across all pods
  • Alert threshold: >80% CPU usage
  • Visualized in Grafana dashboards

2. Nginx Request Metrics

  • Total Request Count: All HTTP requests through nginx
  • Total 5xx Requests: Server error tracking
  • Error Rate: Percentage of failed requests
  • Alert threshold: >5% error rate

3. Additional Metrics

  • Pod memory usage
  • Nginx connection count
  • MySQL connection status
  • Container restart count

Grafana Dashboard

Custom Dashboards

Navigate to Grafana → Dashboards to view:

  • Total Nginx Requests: HTTP request volume over time
  • 5xx Error Rate: Application error monitoring
  • Pod CPU Usage: Resource utilization tracking

Alerts

Prometheus alerting rules are configured for:

  • HighPodCPU: Triggers when pod CPU usage exceeds 80%
  • High5xxErrorRate: Triggers when 5xx error rate exceeds 5%

Check alerts in Prometheus UI → Alerts tab.

Service Monitor

For complete metrics documentation including WordPress, Apache, and Nginx metrics, see METRICS.md.

Troubleshooting

Check pod status

kubectl get pods
kubectl describe pod <pod-name>
kubectl logs <pod-name>

Verify services

kubectl get svc
kubectl get servicemonitor

Check metrics endpoint

kubectl port-forward svc/<release-name>-nginx-metrics 9113:9113
curl http://localhost:9113/metrics

MySQL connection issues

# Get MySQL password
kubectl get secret <release-name>-mysql -o jsonpath="{.data.mysql-root-password}" | base64 --decode

# Connect to MySQL pod
kubectl exec -it <mysql-pod-name> -- mysql -u root -p

Cleanup

# Delete WordPress stack
helm delete my-release

# Delete monitoring stack  
helm delete monitoring

# Delete persistent volumes (optional)
kubectl delete pvc --all

Custom Docker Images

This project uses custom-built Docker images located in charts/wordpress/docker/:

OpenResty (Nginx)

  • Built from source with Lua support
  • Compiled with configure options:
    ./configure --prefix=/opt/openresty \
                --with-pcre-jit \
                --with-ipv6 \
                --without-http_redis2_module \
                --with-http_iconv_module \
                --with-http_postgres_module \
                --with-http_stub_status_module \
                -j8
  • Includes nginx-prometheus-exporter for metrics
  • Proxy pass configuration from nginx to WordPress

WordPress

  • Custom PHP-FPM setup
  • Optimized for Kubernetes deployment
  • ReadWriteMany volume support for scaling

MySQL

  • Production-ready configuration
  • Persistent storage with proper permissions

Scaling

The deployment supports horizontal scaling thanks to ReadWriteMany persistent volumes:

# Scale WordPress pods
kubectl scale deployment my-release-wordpress --replicas=3

# Verify scaling
kubectl get pods -l app=wordpress

Configuration

Edit values.yaml to customize:

  • Docker image tags (nginx, wordpress, mysql)
  • Replica count (default: 2)
  • Storage size and class
  • Persistent volume sizes (WordPress: 5Gi, MySQL: 5Gi)

Resources

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors