feat: Add comprehensive WordPress example with multi-container deployment and documentation

This commit is contained in:
mik-tf
2025-11-09 00:59:37 -05:00
parent 59a662ac1e
commit a356271d8b
5 changed files with 1017 additions and 6 deletions

View File

@@ -0,0 +1,213 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: wordpress-config
data:
# WordPress configuration
wp-config.php: |
<?php
define('DB_NAME', 'wordpress');
define('DB_USER', 'wordpress');
define('DB_PASSWORD', 'mycelium-secure-password-2025');
define('DB_HOST', 'localhost');
define('DB_CHARSET', 'utf8mb4');
define('DB_COLLATE', '');
# Auth keys for security
define('AUTH_KEY', 'put your unique phrase here');
define('SECURE_AUTH_KEY', 'put your unique phrase here');
define('LOGGED_IN_KEY', 'put your unique phrase here');
define('NONCE_KEY', 'put your unique phrase here');
define('AUTH_SALT', 'put your unique phrase here');
define('SECURE_AUTH_SALT', 'put your unique phrase here');
define('LOGGED_IN_SALT', 'put your unique phrase here');
define('NONCE_SALT', 'put your unique phrase here');
# WordPress configuration
$table_prefix = 'wp_';
define('WP_DEBUG', false);
# Memory limits
ini_set('memory_limit', '256M');
@ini_set('upload_max_filesize', '64M');
@ini_set('post_max_size', '64M');
@ini_set('max_execution_time', 300);
# WordPress path
if (!defined('ABSPATH')) {
define('ABSPATH', __DIR__ . '/');
}
require_once ABSPATH . 'wp-settings.php';
# Apache configuration for WordPress
wordpress.conf: |
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
# Directory configuration
<Directory /var/www/html>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
# WordPress specific configuration
<Directory /var/www/html/wp-admin>
Require all granted
</Directory>
<Directory /var/www/html/wp-includes>
Require all granted
</Directory>
<Directory /var/www/html/wp-content/plugins>
Require all granted
</Directory>
<Directory /var/www/html/wp-content/themes>
Require all granted
</Directory>
# Security headers
Header always set X-Content-Type-Options nosniff
Header always set X-Frame-Options DENY
Header always set X-XSS-Protection "1; mode=block"
# Error and access logs
ErrorLog ${APACHE_LOG_DIR}/wordpress_error.log
CustomLog ${APACHE_LOG_DIR}/wordpress_access.log combined
</VirtualHost>
# Initialization script for WordPress setup
init-wordpress.sh: |
#!/bin/bash
set -e
echo "🚀 Starting WordPress initialization..."
# Wait for MariaDB to be ready
echo "⏳ Waiting for MariaDB database..."
for i in {1..30}; do
if mysqladmin ping -h localhost -u wordpress -p"mycelium-secure-password-2025" --silent; then
echo "✅ MariaDB is ready!"
break
fi
echo "⏳ Waiting for database... (attempt $i/30)"
sleep 2
done
# Create WordPress database if it doesn't exist
echo "📊 Setting up WordPress database..."
mysql -u wordpress -p"mycelium-secure-password-2025" -e "CREATE DATABASE IF NOT EXISTS wordpress CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;" 2>/dev/null || true
# Set WordPress permissions
echo "🔒 Setting file permissions..."
chown -R www-data:www-data /var/www/html
chmod -R 755 /var/www/html
chmod -R 777 /var/www/html/wp-content 2>/dev/null || true
# Create wp-config.php if it doesn't exist
if [ ! -f /var/www/html/wp-config.php ]; then
echo "📝 Creating WordPress configuration..."
cp /var/www/html/wp-config-sample.php /var/www/html/wp-config.php || true
# Update wp-config.php with database settings
sed -i "s/database_name_here/wordpress/g" /var/www/html/wp-config.php
sed -i "s/username_here/wordpress/g" /var/www/html/wp-config.php
sed -i "s/password_here/mycelium-secure-password-2025/g" /var/www/html/wp-config.php
sed -i "s/localhost/localhost/g" /var/www/html/wp-config.php
fi
# Check if WordPress is already installed
if mysql -u wordpress -p"mycelium-secure-password-2025" -e "USE wordpress; SHOW TABLES;" 2>/dev/null | grep -q "wp_options"; then
echo "✅ WordPress is already installed and configured!"
else
echo "✅ WordPress database setup complete!"
echo "🌐 WordPress will be available at: http://localhost:80"
echo "📝 Next steps: Complete WordPress setup through the web interface"
fi
echo "🎉 WordPress initialization complete!"
---
apiVersion: v1
kind: ConfigMap
metadata:
name: wordpress-mariadb-config
data:
# MariaDB configuration
my.cnf: |
[mysqld]
# Basic settings
bind-address = 0.0.0.0
port = 3306
user = mysql
# Character set and collation
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
# Memory settings (for small deployments)
innodb_buffer_pool_size = 64M
innodb_log_file_size = 16M
innodb_flush_log_at_trx_commit = 1
innodb_flush_method = O_DIRECT
# WordPress optimization
max_connections = 50
max_allowed_packet = 64M
query_cache_size = 16M
query_cache_type = 1
# Security
skip-name-resolve
local-infile = 0
# Logging
log-error = /var/log/mysql/error.log
slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow.log
long_query_time = 2
[client]
default-character-set = utf8mb4
[mysql]
default-character-set = utf8mb4
# MariaDB initialization script
init-mariadb.sh: |
#!/bin/bash
set -e
echo "🗄️ Starting MariaDB initialization..."
# Wait for MariaDB to start
echo "⏳ Waiting for MariaDB to start..."
for i in {1..30}; do
if mysqladmin ping -h localhost --silent; then
echo "✅ MariaDB is ready!"
break
fi
echo "⏳ Waiting for MariaDB... (attempt $i/30)"
sleep 2
done
# Create WordPress database and user
echo "📊 Creating WordPress database and user..."
mysql -u root << EOF
CREATE DATABASE IF NOT EXISTS wordpress CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER IF NOT EXISTS 'wordpress'@'localhost' IDENTIFIED BY 'mycelium-secure-password-2025';
CREATE USER IF NOT EXISTS 'wordpress'@'%' IDENTIFIED BY 'mycelium-secure-password-2025';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpress'@'localhost';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpress'@'%';
FLUSH PRIVILEGES;
EOF
# Test database connection
echo "🧪 Testing database connection..."
mysql -u wordpress -p"mycelium-secure-password-2025" -e "SELECT 'Database connection successful' as status;" || echo "⚠️ Database connection test failed, but database should be accessible."
echo "✅ MariaDB initialization complete!"

View File

@@ -0,0 +1,237 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: wordpress-database-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
storageClassName: standard
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: wordpress-content-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
storageClassName: standard
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: wordpress
labels:
app: wordpress
spec:
replicas: 1
selector:
matchLabels:
app: wordpress
template:
metadata:
labels:
app: wordpress
spec:
# Prefer worker nodes only (not master nodes) - following nginx-nodeport pattern
affinity:
nodeAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
preference:
matchExpressions:
- key: node-role.kubernetes.io/control-plane
operator: DoesNotExist
- weight: 50
preference:
matchExpressions:
- key: node-role.kubernetes.io/master
operator: DoesNotExist
containers:
# WordPress container (PHP + Apache)
- name: wordpress
image: wordpress:6.4-php8.2-apache
ports:
- containerPort: 80
name: wordpress
env:
- name: WORDPRESS_DB_HOST
value: "localhost"
- name: WORDPRESS_DB_NAME
value: "wordpress"
- name: WORDPRESS_DB_USER
value: "wordpress"
- name: WORDPRESS_DB_PASSWORD
value: "mycelium-secure-password-2025"
- name: WORDPRESS_CONFIG_EXTRA
value: |
define('DISALLOW_FILE_EDIT', true);
define('FORCE_SSL_ADMIN', false);
define('WP_MEMORY_LIMIT', '256M');
define('WP_MAX_MEMORY_LIMIT', '256M');
@ini_set('upload_max_filesize', '64M');
@ini_set('post_max_size', '64M');
@ini_set('max_execution_time', 300);
volumeMounts:
- name: wordpress-content
mountPath: /var/www/html
- name: wordpress-config
mountPath: /var/www/html/wp-config.php
subPath: wp-config.php
- name: wordpress-config
mountPath: /etc/apache2/conf-available/wordpress.conf
subPath: wordpress.conf
- name: init-wordpress
mountPath: /init-wordpress.sh
subPath: init-wordpress.sh
resources:
requests:
memory: "128Mi"
cpu: "200m"
limits:
memory: "512Mi"
cpu: "500m"
livenessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 60
periodSeconds: 30
readinessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 30
periodSeconds: 10
# MariaDB container (database)
- name: mariadb
image: mariadb:10.11
ports:
- containerPort: 3306
name: mariadb
env:
- name: MARIADB_ROOT_PASSWORD
value: "mycelium-root-password-2025"
- name: MARIADB_DATABASE
value: "wordpress"
- name: MARIADB_USER
value: "wordpress"
- name: MARIADB_PASSWORD
value: "mycelium-secure-password-2025"
- name: MARIADB_CHARACTER_SET
value: "utf8mb4"
- name: MARIADB_COLLATION
value: "utf8mb4_unicode_ci"
volumeMounts:
- name: mariadb-database
mountPath: /var/lib/mysql
- name: mariadb-config
mountPath: /etc/mysql/conf.d/my.cnf
subPath: my.cnf
resources:
requests:
memory: "64Mi"
cpu: "100m"
limits:
memory: "256Mi"
cpu: "300m"
livenessProbe:
exec:
command:
- mysqladmin
- ping
- -h
- localhost
- -u
- root
- -p"mycelium-root-password-2025"
initialDelaySeconds: 60
periodSeconds: 30
readinessProbe:
exec:
command:
- mysqladmin
- ping
- -h
- localhost
- -u
- root
- -p"mycelium-root-password-2025"
initialDelaySeconds: 30
periodSeconds: 10
initContainers:
# Init container to initialize MariaDB
- name: init-mariadb
image: mariadb:10.11
command: ["/bin/sh", "-c"]
args:
- |
echo "🔧 Starting MariaDB initialization..."
chmod +x /init-mariadb.sh
/init-mariadb.sh
echo "✅ MariaDB initialization complete"
volumeMounts:
- name: mariadb-config
mountPath: /etc/mysql/conf.d/my.cnf
subPath: my.cnf
- name: mariadb-init
mountPath: /init-mariadb.sh
subPath: init-mariadb.sh
# Init container to initialize WordPress
- name: init-wordpress
image: wordpress:6.4-php8.2-apache
command: ["/bin/sh", "-c"]
args:
- |
echo "🔧 Starting WordPress initialization..."
sleep 30
chmod +x /init-wordpress.sh
/init-wordpress.sh
echo "✅ WordPress initialization complete"
volumeMounts:
- name: wordpress-content
mountPath: /var/www/html
- name: wordpress-config
mountPath: /var/www/html/wp-config.php
subPath: wp-config.php
- name: init-wordpress
mountPath: /init-wordpress.sh
subPath: init-wordpress.sh
volumes:
- name: wordpress-config
configMap:
name: wordpress-config
- name: mariadb-config
configMap:
name: wordpress-mariadb-config
- name: mariadb-init
configMap:
name: wordpress-mariadb-config
items:
- key: init-mariadb.sh
path: init-mariadb.sh
mode: 0755
- name: init-wordpress
configMap:
name: wordpress-config
items:
- key: init-wordpress.sh
path: init-wordpress.sh
mode: 0755
- name: mariadb-database
persistentVolumeClaim:
claimName: wordpress-database-pvc
- name: wordpress-content
persistentVolumeClaim:
claimName: wordpress-content-pvc

View File

@@ -0,0 +1,20 @@
apiVersion: v1
kind: Service
metadata:
name: wordpress-service
labels:
app: wordpress
spec:
selector:
app: wordpress
ports:
- name: wordpress
port: 80
targetPort: 80
protocol: TCP
type: LoadBalancer
# Enable dual-stack (IPv4 + IPv6) for Mycelium Cloud
ipFamilies:
- IPv4
- IPv6
ipFamilyPolicy: RequireDualStack

View File

@@ -0,0 +1,540 @@
# 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
- **wordpress-configmap.yaml** - WordPress configuration, Apache config, and initialization scripts
## 🚀 Quick Start (3 minutes)
```bash
# 1. Deploy WordPress stack (ConfigMaps, PVCs, Deployment, Service)
kubectl apply -f wordpress-configmap.yaml
kubectl apply -f wordpress-deployment.yaml
kubectl apply -f wordpress-service.yaml
# 2. Wait for pods to be ready
kubectl wait --for=condition=ready pod -l app=wordpress --timeout=300s
# 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, init containers)
- ✅ WordPress deployment and configuration
- ✅ MariaDB database deployment with persistent storage
- ✅ ConfigMap usage for application configuration
- ✅ LoadBalancer services on Mycelium Cloud
- ✅ PersistentVolume claims for data persistence
- ✅ Init container patterns for database initialization
- ✅ Production WordPress management
- ✅ Resource limits and container orchestration
- ✅ Health checks for both web and database services
## 🏗️ Architecture
This example uses a **multi-container pod pattern** with **persistent storage** and **init containers**:
**Network Flow:**
```
kubectl port-forward → LoadBalancer Service → Pod (wordpress + mariadb)
```
**Multi-Container Architecture:**
- **wordpress**: WordPress 6.4 with PHP 8.2 and Apache (port 80)
- **mariadb**: MariaDB 10.11 database server (port 3306)
- **init-mariadb**: Init container for database setup
- **init-wordpress**: Init container for WordPress configuration
- **PersistentVolumes**: Database and WordPress content storage
## 🔧 Files Explanation
### wordpress-deployment.yaml
```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: wordpress
spec:
replicas: 1
selector:
matchLabels:
app: wordpress
template:
metadata:
labels:
app: wordpress
spec:
# Worker node preference (like nginx-nodeport)
affinity:
nodeAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
preference:
matchExpressions:
- key: node-role.kubernetes.io/master
operator: DoesNotExist
containers:
- name: wordpress
image: wordpress:6.4-php8.2-apache
ports:
- containerPort: 80
env:
- name: WORDPRESS_DB_HOST
value: "localhost"
# ... WordPress environment variables
- name: mariadb
image: mariadb:10.11
ports:
- containerPort: 3306
env:
- name: MARIADB_ROOT_PASSWORD
value: "mycelium-root-password-2025"
# ... MariaDB environment variables
initContainers:
- name: init-mariadb
# Database initialization
- name: init-wordpress
# WordPress setup
```
**What it does:**
- Creates multi-container pod with WordPress + MariaDB
- ConfigMap mounts for configuration and initialization scripts
- PersistentVolume claims for database and content storage
- Init containers for database and WordPress setup
- Resource limits for both containers
- Worker node preference for production deployments
### wordpress-service.yaml
```yaml
apiVersion: v1
kind: Service
metadata:
name: wordpress-service
spec:
selector:
app: wordpress
ports:
- name: wordpress
port: 80
targetPort: 80
type: LoadBalancer
ipFamilies:
- IPv4
- IPv6
ipFamilyPolicy: RequireDualStack
```
**What it does:**
- Creates LoadBalancer service for Mycelium Cloud
- Exposes WordPress port 80
- Dual-stack (IPv4 + IPv6) support
- Routes traffic to multi-container pod
### wordpress-configmap.yaml
```yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: wordpress-config
data:
wp-config.php: |
<?php
define('DB_NAME', 'wordpress');
define('DB_USER', 'wordpress');
define('DB_PASSWORD', 'mycelium-secure-password-2025');
# ... WordPress configuration
wordpress.conf: |
<VirtualHost *:80>
# ... Apache configuration
init-wordpress.sh: |
#!/bin/bash
# WordPress initialization script
```
**What it does:**
- WordPress configuration (wp-config.php)
- Apache virtual host configuration
- Database initialization scripts
- WordPress setup automation
## 🌐 Access Methods
### Method 1: Port-Forward (Recommended for Mycelium Cloud)
**Option 1: Simple (Recommended)**
```bash
# Keep terminal open, forward WordPress port
kubectl port-forward service/wordpress-service 8080:80
# Access WordPress setup
curl http://localhost:8080
```
**Option 2: Background**
```bash
# Start in background
nohup kubectl port-forward service/wordpress-service 8080:80 > wordpress-access.log 2>&1 &
# Access WordPress
curl http://localhost:8080
```
### Method 2: Direct Pod Access (Inside Cluster)
**WordPress CLI Access:**
```bash
# Execute WordPress commands
kubectl exec -it $(kubectl get pod -l app=wordpress -o jsonpath='{.items[0].metadata.name}') -c wordpress -- wp --allow-root --info
# Access WordPress shell
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 root -p"mycelium-root-password-2025"
# WordPress database access
kubectl exec -it $(kubectl get pod -l app=wordpress -o jsonpath='{.items[0].metadata.name}') -c mariadb -- mysql -u wordpress -p"mycelium-secure-password-2025" wordpress
```
### Method 3: LoadBalancer IP Access (If Available)
```bash
# Get LoadBalancer IP (may be internal on Mycelium Cloud)
kubectl get svc wordpress-service
# Access WordPress (if external IP available)
curl http://<external-ip>:80
```
## 📊 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
### WordPress CLI Management
```bash
# Install WordPress CLI in pod
kubectl exec -it $(kubectl get pod -l app=wordpress -o jsonpath='{.items[0].metadata.name}') -c wordpress -- \
curl -O https://raw.githubusercontent.com/wp-cli/wp-cli/master/phar/wp-cli.phar && \
chmod +x wp-cli.phar
# Basic WordPress operations
kubectl exec -it $(kubectl get pod -l app=wordpress -o jsonpath='{.items[0].metadata.name}') -c wordpress -- \
./wp-cli.phar --allow-root --info
# List plugins
kubectl exec -it $(kubectl get pod -l app=wordpress -o jsonpath='{.items[0].metadata.name}') -c wordpress -- \
./wp-cli.phar --allow-root plugin list
# Install theme
kubectl exec -it $(kubectl get pod -l app=wordpress -o jsonpath='{.items[0].metadata.name}') -c wordpress -- \
./wp-cli.phar --allow-root theme install twentytwentyfour
```
### 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"mycelium-secure-password-2025" 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"mycelium-secure-password-2025" wordpress -e "SELECT * FROM wp_users;"
# Database backup
kubectl exec -it $(kubectl get pod -l app=wordpress -o jsonpath='{.items[0].metadata.name}') -c mariadb -- \
mysqldump -u wordpress -p"mycelium-secure-password-2025" wordpress > wordpress-backup.sql
```
## 🔍 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 PersistentVolumeClaims
kubectl get pvc wordpress-database-pvc wordpress-content-pvc
# Check ConfigMaps
kubectl get configmap wordpress-config wordpress-mariadb-config
```
### 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
kubectl logs -l app=wordpress -c wordpress
kubectl logs -l app=wordpress -c mariadb --previous
```
#### Database Connection Issues
```bash
# Check MariaDB connectivity from WordPress container
kubectl exec -it $(kubectl get pod -l app=wordpress -o jsonpath='{.items[0].metadata.name}') -c wordpress -- \
mysqladmin ping -h localhost -u wordpress -p"mycelium-secure-password-2025"
# Test database access
kubectl exec -it $(kubectl get pod -l app=wordpress -o jsonpath='{.items[0].metadata.name}') -c mariadb -- \
mysql -u root -p"mycelium-root-password-2025" -e "SHOW DATABASES;"
```
#### WordPress Installation 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
# Check WordPress directory permissions
kubectl exec -it $(kubectl get pod -l app=wordpress -o jsonpath='{.items[0].metadata.name}') -c wordpress -- \
ls -la /var/www/html/
# Test WordPress initialization
kubectl exec -it $(kubectl get pod -l app=wordpress -o jsonpath='{.items[0].metadata.name}') -c wordpress -- \
/init-wordpress.sh
```
#### Persistent Volume Issues
```bash
# Check PVC status
kubectl describe pvc wordpress-database-pvc
kubectl describe pvc wordpress-content-pvc
# Check volume mount in containers
kubectl exec -it $(kubectl get pod -l app=wordpress -o jsonpath='{.items[0].metadata.name}') -c mariadb -- \
ls -la /var/lib/mysql/
kubectl exec -it $(kubectl get pod -l app=wordpress -o jsonpath='{.items[0].metadata.name}') -c wordpress -- \
ls -la /var/www/html/
```
#### Port Conflicts
```bash
# Check if port 8080 is in use
lsof -i :8080
# Check port 80 conflicts
kubectl exec -it $(kubectl get pod -l app=wordpress -o jsonpath='{.items[0].metadata.name}') -c wordpress -- \
netstat -tlnp | grep :80
```
## 🛠️ Common Operations
### Scaling (Note: WordPress scaling is complex)
```bash
# Note: WordPress is typically single-instance due to file-based sessions
# For horizontal scaling, you'd need shared storage and session management
kubectl scale deployment wordpress --replicas=1
# Check distribution
kubectl get pods -o wide
```
### Updates
```bash
# Update WordPress image
kubectl set image deployment/wordpress wordpress=wordpress:6.5-php8.2-apache
# Update MariaDB image
kubectl set image deployment/wordpress mariadb=mariadb:11.0
# Restart deployment
kubectl rollout restart deployment/wordpress
# Check rollout status
kubectl rollout status deployment/wordpress
```
### Data Management
```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"mycelium-secure-password-2025" wordpress
# Common database operations inside pod:
# SHOW TABLES;
# DESCRIBE wp_posts;
# SELECT * FROM wp_options;
# FLUSH PRIVILEGES;
```
### Monitoring
```bash
# View logs from both containers
kubectl logs -f deployment/wordpress
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 root -p"mycelium-root-password-2025" status
```
## 🧹 Cleanup
When you're done testing:
```bash
# Delete the application and service
kubectl delete -f wordpress-deployment.yaml -f wordpress-service.yaml -f wordpress-configmap.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
kubectl get pvc wordpress-database-pvc wordpress-content-pvc 2>/dev/null || echo "PVCs deleted"
kubectl get configmap wordpress-config wordpress-mariadb-config 2>/dev/null || echo "ConfigMaps deleted"
```
## 🎯 What This Demonstrates
This example shows:
- **Advanced Kubernetes patterns** - multi-container pods, init containers, persistent volumes
- **Production WordPress deployment** - proper configuration, security, performance
- **Database integration** - MariaDB setup, persistent storage, initialization
- **Mycelium Cloud networking** - LoadBalancer services, port-forwarding, dual-stack
- **Container orchestration** - resource management, health monitoring, init containers
- **Development workflows** - testing, debugging, configuration management
- **Production patterns** - worker node preferences, scaling considerations
## 🔗 Next Steps
Once you understand this example, try:
1. **WordPress Clustering** - Multiple WordPress instances with shared database
2. **Advanced Scaling** - Load balancing, shared storage, 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
## 💡 Pro Tips
1. **Multi-Container Access**: Use `-c container-name` to access specific containers
2. **Init Containers**: Check init container logs for setup issues
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. **Network Testing**: Use `kubectl exec` for internal cluster testing
7. **Background Services**: Use `&` to run multiple port-forwards
8. **Persistent Storage**: Verify PVC mounting for data persistence
## 🔧 WordPress-Specific Tips
### Plugin Management
```bash
# List installed plugins
kubectl exec -it $(kubectl get pod -l app=wordpress -o jsonpath='{.items[0].metadata.name}') -c wordpress -- \
./wp-cli.phar --allow-root plugin list
# Install popular plugins
kubectl exec -it $(kubectl get pod -l app=wordpress -o jsonpath='{.items[0].metadata.name}') -c wordpress -- \
./wp-cli.phar --allow-root plugin install seo yoast-seo contact-form-7
```
### Theme Management
```bash
# List installed themes
kubectl exec -it $(kubectl get pod -l app=wordpress -o jsonpath='{.items[0].metadata.name}') -c wordpress -- \
./wp-cli.phar --allow-root theme list
# Install and activate theme
kubectl exec -it $(kubectl get pod -l app=wordpress -o jsonpath='{.items[0].metadata.name}') -c wordpress -- \
./wp-cli.phar --allow-root theme install twentytwentyfour --activate
```
### Content Management
```bash
# Create sample post
kubectl exec -it $(kubectl get pod -l app=wordpress -o jsonpath='{.items[0].metadata.name}') -c wordpress -- \
./wp-cli.phar --allow-root post create --post_type=post --post_title="Welcome to Mycelium Cloud WordPress" --post_content="This is a sample post deployed on Mycelium Cloud!" --post_status=publish
```
### Database Maintenance
```bash
# Optimize database tables
kubectl exec -it $(kubectl get pod -l app=wordpress -o jsonpath='{.items[0].metadata.name}') -c mariadb -- \
mysql -u wordpress -p"mycelium-secure-password-2025" wordpress -e "OPTIMIZE TABLE wp_posts, wp_options;"
# Check database size
kubectl exec -it $(kubectl get pod -l app=wordpress -o jsonpath='{.items[0].metadata.name}') -c mariadb -- \
mysql -u wordpress -p"mycelium-secure-password-2025" wordpress -e "SELECT table_schema AS 'Database', ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS 'Size (MB)' FROM information_schema.tables WHERE table_schema = 'wordpress' GROUP BY table_schema;"
```
## 🎉 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
-`kubectl get pvc` shows both PVCs as "Bound"
-`curl http://localhost:8080` returns WordPress installation page
- ✅ Database initialization completes without errors
- ✅ WordPress setup wizard can be accessed and completed
- ✅ No errors in `kubectl get events`
**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. Verify PersistentVolumeClaim status: `kubectl get pvc`
7. Test WordPress functionality via browser at http://localhost:8080
For more help, visit our [documentation](../../README.md) or contact support.