- Introduction
- Prerequisites
- Project Structure
- Deployment Guide
- Monitoring Setup
- Cleanup
- Output
- Best Practices
- Troubleshooting
- Contributing
- License
This repository contains the code and configuration files to deploy a production-grade WordPress application on Kubernetes, along with a monitoring setup using Prometheus and Grafana. The deployment includes MySQL for the database, Nginx as a reverse proxy, and persistent storage for data durability. This setup uses Minikube for local Kubernetes cluster management.
- Minikube (v1.18+)
- Helm (v3+)
- kubectl (v1.18+)
- Docker (for building custom images)
my-wordpress-k8s/
├── Chart.yaml
├── values.yaml
├── Dockerfiles/
│ ├── Dockerfile.wordpress
│ ├── Dockerfile.mysql
│ ├── Dockerfile.nginx
│ ├── nginx.conf
├── templates/
│ ├── mysql-deployment.yaml
│ ├── mysql-service.yaml
│ ├── nginx-deployment.yaml
│ ├── nginx-service.yaml
│ ├── wordpress-deployment.yaml
│ ├── wordpress-service.yaml
│ ├── pvc.yaml
│ ├── secrets.yaml
├── monitoring/
│ ├── dashboards/
│ │ ├── wordpress-dashboard.json
│ │ ├── nginx-dashboard.json
│ ├── grafana/
│ │ ├── values.yaml
│ ├── prometheus/
│ │ ├── values.yaml
│ ├── service-monitor/
│ │ ├── wordpress-service-monitor.yaml
│ │ ├── nginx-service-monitor.yaml
├── docker-compose.yaml
└── README.md
Ensure Minikube is installed and start your Minikube cluster.
minikube start
To interact with the Minikube cluster, ensure you set your Docker environment to use Minikube's Docker daemon.
eval $(minikube docker-env)
Deploy the PVC for WordPress and MySQL to ensure persistent storage.
kubectl apply -f templates/pvc.yaml
Ensure that sensitive information like database passwords are managed using Kubernetes Secrets.
kubectl apply -f templates/secrets.yaml
Deploy the MySQL instance along with its service.
kubectl apply -f templates/mysql-deployment.yaml
kubectl apply -f templates/mysql-service.yaml
Deploy Nginx configured with OpenResty and Lua support. Ensure nginx.conf
is copied into the Docker image.
kubectl apply -f templates/nginx-deployment.yaml
kubectl apply -f templates/nginx-service.yaml
Deploy WordPress with its respective service.
kubectl apply -f templates/wordpress-deployment.yaml
kubectl apply -f templates/wordpress-service.yaml
If using ChartMuseum for Helm chart repository, deploy it using Docker Compose.
docker-compose up -d
Deploy Prometheus using the provided Helm chart.
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm install prometheus prometheus-community/prometheus -f monitoring/prometheus/values.yaml
kubectl apply -f monitoring/prometheus/prometheus.yaml
Deploy Grafana using the provided Helm chart.
helm repo add grafana https://grafana.github.io/helm-charts
helm install grafana grafana/grafana -f monitoring/grafana/values.yaml
kubectl apply -f monitoring/grafana/grafana.yaml
Deploy the Service Monitors for WordPress and Nginx to allow Prometheus to scrape their metrics.
kubectl apply -f monitoring/service-monitor/wordpress-service-monitor.yaml
kubectl apply -f monitoring/service-monitor/nginx-service-monitor.yaml
Import the provided Grafana dashboards for WordPress and Nginx.
- Open Grafana in your browser.
- Go to Dashboards > Import.
- Upload
monitoring/dashboards/wordpress-dashboard.json
andmonitoring/dashboards/nginx-dashboard.json
.
To delete the deployed resources, use the following commands:
helm delete prometheus
helm delete grafana
kubectl delete -f templates/pvc.yaml
kubectl delete -f monitoring/prometheus/prometheus.yaml
kubectl delete -f monitoring/grafana/grafana.yaml
kubectl delete -f monitoring/service-monitor/wordpress-service-monitor.yaml
kubectl delete -f monitoring/service-monitor/nginx-service-monitor.yaml
To stop and delete the Minikube cluster:
minikube stop
minikube delete
- Use Kubernetes Secrets to manage sensitive data.
- Regularly backup PersistentVolume data.
- Monitor resource usage and set resource requests and limits.
- Use Ingress for external access to WordPress.
- Ensure all pods are running with
kubectl get pods
. - Check logs of individual pods with
kubectl logs <pod-name>
. - Verify services and endpoints with
kubectl get svc
. - For Minikube-specific issues, use
minikube logs
.
Contributions are welcome! Please submit a pull request or open an issue to discuss changes.