324 lines
9.9 KiB
Markdown
324 lines
9.9 KiB
Markdown
# Mycelium Cloud - WordPress Example
|
|
|
|
A complete, production-ready example for deploying a WordPress CMS with MariaDB database on Mycelium Cloud Kubernetes cluster. Features multi-container pod architecture, persistent storage, and comprehensive WordPress management patterns.
|
|
|
|
## 📁 What This Contains
|
|
|
|
This directory contains everything you need to deploy a WordPress CMS system:
|
|
|
|
- **wordpress.md** - This comprehensive guide
|
|
- **wordpress-deployment.yaml** - Multi-container pod deployment (WordPress + MariaDB)
|
|
- **wordpress-service.yaml** - LoadBalancer service configuration
|
|
|
|
## 🚀 Quick Start (3 minutes)
|
|
|
|
```bash
|
|
# 1. Deploy WordPress stack (Deployment, Service)
|
|
kubectl apply -f wordpress-deployment.yaml
|
|
kubectl apply -f wordpress-service.yaml
|
|
|
|
# 2. Wait for pods to be ready (should show 2/2 Running)
|
|
kubectl get pods -l app=wordpress
|
|
|
|
# 3. Access WordPress
|
|
kubectl port-forward service/wordpress-service 8080:80 &
|
|
|
|
# 4. Visit WordPress setup
|
|
echo "🌐 Visit: http://localhost:8080"
|
|
```
|
|
|
|
**Expected Result:** WordPress installation page will appear, ready for initial setup and configuration.
|
|
|
|
## 📋 What You'll Learn
|
|
|
|
- ✅ Advanced Kubernetes patterns (multi-container pods)
|
|
- ✅ WordPress deployment and configuration
|
|
- ✅ MariaDB database deployment
|
|
- ✅ LoadBalancer services on Mycelium Cloud
|
|
- ✅ Container orchestration and health checks
|
|
- ✅ WordPress initialization and setup
|
|
- ✅ Database connectivity within pods
|
|
- ✅ Production WordPress management
|
|
|
|
## 🏗️ Architecture
|
|
|
|
This example uses a **multi-container pod pattern** following the successful Mycelium Cloud patterns:
|
|
|
|
**Network Flow:**
|
|
```
|
|
kubectl port-forward → LoadBalancer Service → Pod (wordpress + mariadb)
|
|
```
|
|
|
|
**Multi-Container Architecture:**
|
|
- **wordpress**: WordPress with PHP 8.3 and Apache (port 80)
|
|
- **mariadb**: MariaDB 10.11 database server (port 3306)
|
|
- **Local communication**: Both containers in same pod using 127.0.0.1
|
|
|
|
## 🔧 Files Explanation
|
|
|
|
### wordpress-deployment.yaml
|
|
```yaml
|
|
apiVersion: apps/v1
|
|
kind: Deployment
|
|
metadata:
|
|
name: wordpress
|
|
spec:
|
|
replicas: 1
|
|
template:
|
|
spec:
|
|
# Follow successful Mycelium Cloud patterns
|
|
affinity:
|
|
nodeAffinity:
|
|
preferredDuringSchedulingIgnoredDuringExecution:
|
|
- weight: 100
|
|
preference:
|
|
matchExpressions:
|
|
- key: node-role.kubernetes.io/control-plane
|
|
operator: DoesNotExist
|
|
containers:
|
|
# MariaDB container
|
|
- name: mariadb
|
|
image: mariadb:10.11
|
|
# Database setup and health checks
|
|
# WordPress container
|
|
- name: wordpress
|
|
image: wordpress:latest
|
|
# Web server with database connectivity
|
|
```
|
|
|
|
**What it does:**
|
|
- Creates multi-container pod with WordPress + MariaDB
|
|
- Worker node preference following successful patterns
|
|
- Proper health checks and resource limits
|
|
- Intra-pod database communication using 127.0.0.1
|
|
|
|
### wordpress-service.yaml
|
|
```yaml
|
|
apiVersion: v1
|
|
kind: Service
|
|
metadata:
|
|
name: wordpress-service
|
|
spec:
|
|
type: LoadBalancer
|
|
ipFamilies:
|
|
- IPv4
|
|
- IPv6
|
|
ipFamilyPolicy: RequireDualStack
|
|
selector:
|
|
app: wordpress
|
|
ports:
|
|
- name: wordpress
|
|
port: 80
|
|
targetPort: 80
|
|
```
|
|
|
|
**What it does:**
|
|
- Creates LoadBalancer service for Mycelium Cloud
|
|
- Dual-stack (IPv4 + IPv6) support
|
|
- Routes traffic to multi-container pod
|
|
|
|
## 🌐 Access Methods
|
|
|
|
### Method 1: Port-Forward (Recommended)
|
|
|
|
```bash
|
|
# Simple port-forward
|
|
kubectl port-forward service/wordpress-service 8080:80
|
|
|
|
# Access WordPress setup
|
|
curl http://localhost:8080
|
|
```
|
|
|
|
### Method 2: Direct Pod Access (Inside Cluster)
|
|
|
|
**WordPress CLI Access:**
|
|
```bash
|
|
kubectl exec -it $(kubectl get pod -l app=wordpress -o jsonpath='{.items[0].metadata.name}') -c wordpress -- /bin/bash
|
|
```
|
|
|
|
**Database Access:**
|
|
```bash
|
|
# Access MariaDB
|
|
kubectl exec -it $(kubectl get pod -l app=wordpress -o jsonpath='{.items[0].metadata.name}') -c mariadb -- mysql -u wordpress -p"wp123" wordpress
|
|
```
|
|
|
|
## 📊 WordPress Management
|
|
|
|
### Initial Setup
|
|
1. **Visit WordPress Setup**: http://localhost:8080
|
|
2. **Choose Language**: Select your preferred language
|
|
3. **Site Configuration**:
|
|
- Site Title: "Mycelium Cloud WordPress"
|
|
- Username: "admin" (or your choice)
|
|
- Password: Generate secure password
|
|
- Email: Your email address
|
|
4. **Complete Setup**: WordPress will create database tables and configure
|
|
|
|
### Database Operations
|
|
```bash
|
|
# Access WordPress database
|
|
kubectl exec -it $(kubectl get pod -l app=wordpress -o jsonpath='{.items[0].metadata.name}') -c mariadb -- \
|
|
mysql -u wordpress -p"wp123" wordpress -e "SHOW TABLES;"
|
|
|
|
# Check WordPress users
|
|
kubectl exec -it $(kubectl get pod -l app=wordpress -o jsonpath='{.items[0].metadata.name}') -c mariadb -- \
|
|
mysql -u wordpress -p"wp123" wordpress -e "SELECT * FROM wp_users;"
|
|
```
|
|
|
|
## 🔍 Troubleshooting
|
|
|
|
### Check Deployment Status
|
|
```bash
|
|
# Check pods status (should show 2/2 Ready)
|
|
kubectl get pods -l app=wordpress
|
|
|
|
# Check service details
|
|
kubectl get svc wordpress-service
|
|
|
|
# Check container logs
|
|
kubectl logs -l app=wordpress
|
|
kubectl logs -l app=wordpress -c wordpress
|
|
kubectl logs -l app=wordpress -c mariadb
|
|
```
|
|
|
|
### Common Issues
|
|
|
|
#### Pod Not Starting
|
|
```bash
|
|
# Check pod status and events
|
|
kubectl describe pod -l app=wordpress
|
|
|
|
# Check container logs
|
|
kubectl logs -l app=wordpress -c wordpress --previous
|
|
kubectl logs -l app=wordpress -c mariadb --previous
|
|
```
|
|
|
|
#### Database Connection Issues
|
|
```bash
|
|
# Test database connectivity from WordPress container
|
|
kubectl exec -it $(kubectl get pod -l app=wordpress -o jsonpath='{.items[0].metadata.name}') -c mariadb -- \
|
|
mysql -u wordpress -p"wp123" -e "SELECT 'Connection successful';"
|
|
```
|
|
|
|
#### WordPress Setup Issues
|
|
```bash
|
|
# Check WordPress configuration
|
|
kubectl exec -it $(kubectl get pod -l app=wordpress -o jsonpath='{.items[0].metadata.name}') -c wordpress -- \
|
|
cat /var/www/html/wp-config.php
|
|
```
|
|
|
|
## 🛠️ Common Operations
|
|
|
|
### Updates
|
|
```bash
|
|
# Update WordPress image
|
|
kubectl set image deployment/wordpress wordpress=wordpress:6.5-php8.2-apache
|
|
|
|
# Restart deployment
|
|
kubectl rollout restart deployment/wordpress
|
|
|
|
# Check rollout status
|
|
kubectl rollout status deployment/wordpress
|
|
```
|
|
|
|
### Monitoring
|
|
```bash
|
|
# View logs from both containers
|
|
kubectl logs -f deployment/wordpress -c wordpress
|
|
kubectl logs -f deployment/wordpress -c mariadb
|
|
|
|
# Monitor resource usage
|
|
kubectl top pod -l app=wordpress
|
|
|
|
# Check database status
|
|
kubectl exec -it $(kubectl get pod -l app=wordpress -o jsonpath='{.items[0].metadata.name}') -c mariadb -- \
|
|
mysqladmin -u wordpress -p"wp123" status
|
|
```
|
|
|
|
## 🧹 Cleanup
|
|
|
|
When you're done testing:
|
|
|
|
```bash
|
|
# Delete the application and service
|
|
kubectl delete -f wordpress-deployment.yaml -f wordpress-service.yaml
|
|
|
|
# Wait for cleanup
|
|
kubectl wait --for=delete pod -l app=wordpress --timeout=60s
|
|
|
|
# Kill any port-forwards
|
|
lsof -ti:8080 | xargs kill -9 2>/dev/null || true
|
|
|
|
# Verify cleanup
|
|
kubectl get all -l app=wordpress
|
|
```
|
|
|
|
## 🎯 What This Demonstrates
|
|
|
|
This example shows:
|
|
- **Advanced Kubernetes patterns** - multi-container pods, health monitoring
|
|
- **Production WordPress deployment** - proper configuration, database integration
|
|
- **Database integration** - MariaDB setup, intra-pod communication
|
|
- **Mycelium Cloud networking** - LoadBalancer services, port-forwarding
|
|
- **Container orchestration** - resource management, health checks
|
|
- **Development workflows** - testing, debugging, WordPress setup
|
|
|
|
## 🔗 Next Steps
|
|
|
|
Once you understand this example, try:
|
|
|
|
1. **WordPress Scaling** - Multiple WordPress instances with shared database
|
|
2. **WordPress Clustering** - Load balancing and session management
|
|
3. **WordPress Multisite** - Multiple WordPress sites on one deployment
|
|
4. **Plugin Management** - Automated plugin/theme deployment
|
|
5. **Backup Strategies** - Database and file backups
|
|
6. **Security Hardening** - SSL/TLS, security headers, access controls
|
|
7. **Performance Optimization** - Caching, CDN integration
|
|
8. **Monitoring** - WordPress performance and database monitoring
|
|
|
|
## 📚 More Examples
|
|
|
|
Other available examples:
|
|
- **hello-world/** - Basic web application deployment
|
|
- **nginx-static/** - Static website hosting
|
|
- **python-flask/** - Python API server
|
|
- **redis-cache/** - Data caching services
|
|
- **nginx-nodeport/** - NodePort scaling with workers
|
|
- **nginx-load-balancer/** - LoadBalancer with replicas
|
|
|
|
## 💡 Pro Tips
|
|
|
|
1. **Multi-Container Access**: Use `-c container-name` to access specific containers
|
|
2. **Database Testing**: Always test database connectivity when troubleshooting
|
|
3. **WordPress CLI**: Great for automated WordPress management
|
|
4. **Database Backup**: Always backup before major changes
|
|
5. **Resource Monitoring**: Watch memory usage, especially during WordPress operations
|
|
6. **Health Checks**: Monitor the 2/2 ready status for both containers
|
|
7. **Port Conflicts**: Use different ports (8080, 8090, etc.) if conflicts occur
|
|
8. **WordPress Themes**: Test with different themes to understand WordPress capabilities
|
|
|
|
## 🎉 Success Indicators
|
|
|
|
You'll know everything is working when:
|
|
- ✅ `kubectl get pods` shows "2/2 Running" for wordpress pod
|
|
- ✅ `kubectl get svc` shows wordpress-service with LoadBalancer type
|
|
- ✅ `curl http://localhost:8080` returns WordPress installation page (HTTP 200)
|
|
- ✅ No errors in `kubectl get events`
|
|
- ✅ WordPress setup wizard can be accessed and completed
|
|
- ✅ Database connection works from both containers
|
|
|
|
**Congratulations! You've successfully deployed a production-ready WordPress CMS system on Mycelium Cloud! 🚀**
|
|
|
|
---
|
|
|
|
## 🆘 Support
|
|
|
|
If you encounter issues:
|
|
1. Check the troubleshooting section above
|
|
2. Verify your kubeconfig is set correctly: `kubectl get nodes`
|
|
3. Ensure your cluster is healthy: `kubectl get pods --all-namespaces`
|
|
4. Check WordPress logs: `kubectl logs -l app=wordpress -c wordpress`
|
|
5. Check MariaDB logs: `kubectl logs -l app=wordpress -c mariadb`
|
|
6. Test WordPress functionality via browser at http://localhost:8080
|
|
|
|
For more help, visit our [documentation](../../README.md) or contact support. |