Skip to content

WP Complete Example

Franklin García edited this page Sep 17, 2025 · 8 revisions

WordPress + MySQL Complete Example: Development Guide

This guide demonstrates how to create a complete WordPress + MySQL application using Timonel's umbrella chart functionality. The example shows the proper way to build, configure, and deploy a multi-service application with Helm chart generation.

Table of Contents

  1. Overview
  2. Prerequisites
  3. Project Setup
  4. Creating the MySQL Subchart
  5. Creating the WordPress Subchart
  6. Configuring the Umbrella Chart
  7. Verification and Testing
  8. Deployment
  9. Lessons Learned

Overview

This example demonstrates how to create a complete WordPress + MySQL application using Timonel's umbrella chart functionality. The final result includes:

  • A MySQL database subchart with persistent storage
  • A WordPress application subchart with Ingress configuration
  • Proper Helm chart generation with all necessary templates
  • Full compatibility with Helm deployment tools

Prerequisites

Before starting, ensure you have:

  • Node.js (v18 or later)
  • npm or pnpm package manager
  • Helm CLI (v3.x)
  • Kubernetes cluster (optional, for actual deployment)
  • Timonel CLI installed globally
npm install -g timonel

Initial Project Setup

Step 1: Initialize the Umbrella Chart

Create a new umbrella chart in the examples directory:

cd examples
npx timonel umbrella init wordpress-mysql-complete
cd wordpress-mysql-complete

This creates the basic structure with umbrella.ts and umbrella.config.json files.

Creating the MySQL Subchart

Step 2: Add MySQL Subchart

npx timonel umbrella add mysql

Step 3: Configure MySQL

Edit charts/mysql/chart.ts:

import { App } from 'cdk8s';
import { Subchart } from 'timonel';

export function createChart(): Subchart {
  const app = new App();
  
  return new Subchart(app, 'mysql', {
    name: 'mysql',
    appName: 'mysql',
    image: 'mysql:8.0',
    port: 3306,
    serviceType: 'ClusterIP',
    enableIngress: false,
    env: {
      MYSQL_ROOT_PASSWORD: 'rootpassword',
      MYSQL_DATABASE: 'wordpress',
      MYSQL_USER: 'wordpress',
      MYSQL_PASSWORD: 'wordpress'
    },
    persistentVolume: {
      enabled: true,
      size: '10Gi',
      mountPath: '/var/lib/mysql'
    }
  });
}

export default createChart;

Creating the WordPress Subchart

Step 4: Add WordPress Subchart

npx timonel umbrella add wordpress

Step 5: Configure WordPress

Edit charts/wordpress/chart.ts:

import { App } from 'cdk8s';
import { Subchart } from 'timonel';

export function createChart(): Subchart {
  const app = new App();
  
  return new Subchart(app, 'wordpress', {
    name: 'wordpress',
    appName: 'wordpress',
    image: 'wordpress:latest',
    port: 80,
    replicas: 1,
    serviceType: 'LoadBalancer',
    enableIngress: true,
    ingressHost: 'wordpress.local',
    env: {
      WORDPRESS_DB_HOST: 'mysql:3306',
      WORDPRESS_DB_NAME: 'wordpress',
      WORDPRESS_DB_USER: 'wordpress',
      WORDPRESS_DB_PASSWORD: 'wordpress'
    },
    persistentVolume: {
      enabled: true,
      size: '5Gi',
      mountPath: '/var/www/html'
    }
  });
}

export default createChart;

Configuring the Umbrella Chart

Step 6: Update Umbrella Configuration

Edit umbrella.ts to include the critical synthesis calls:

import { App, YamlOutputType } from 'cdk8s';
import { UmbrellaChart } from 'timonel';
import mysql from './charts/mysql/chart';
import wordpress from './charts/wordpress/chart';

export function synth(outDir: string) {
  const app = new App({
    outdir: outDir,
    outputFileExtension: '.yaml',
    yamlOutputType: YamlOutputType.FILE_PER_RESOURCE
  });
  
  const chart = new UmbrellaChart(app, 'wordpress-mysql-complete', {
    name: 'wordpress-mysql-complete',
    version: '0.1.0',
    description: 'wordpress-mysql-complete umbrella chart',
    services: [],
    subcharts: [
      { name: 'mysql', chart: mysql },
      { name: 'wordpress', chart: wordpress }
    ]
  });

  // CRITICAL: Generate Helm chart files
  chart.writeHelmChart(outDir);
  
  // CRITICAL: Generate CDK8s YAML files
  app.synth();
}

// Auto-execute when run directly
if (import.meta.url === new URL(import.meta.url).href) {
  synth(process.argv[2] || 'dist');
}

export default synth;

Step 7: Generate the Charts

npx timonel umbrella synth

Verification and Testing

Step 8: Verify Chart Structure

Check the generated files:

tree dist/

You should see a complete Helm chart structure with:

  • Main umbrella chart files (Chart.yaml, values.yaml)
  • MySQL subchart in charts/mysql/ with templates and values
  • WordPress subchart in charts/wordpress/ with templates and values
  • Proper Ingress template in WordPress subchart

Step 9: Test with Helm Dry Run

helm install wordpress-mysql-test ./dist --dry-run --debug

Step 10: Test Template Rendering

helm template wordpress-mysql ./dist

Deployment

If you have a Kubernetes cluster:

# Helm creates the namespace automatically with --create-namespace
helm install wordpress-mysql ./dist -n wordpress-mysql --create-namespace
kubectl get all -n wordpress-mysql

Lessons Learned

1. Critical Synthesis Calls

The umbrella chart must include both:

  • chart.writeHelmChart(outDir) - generates Helm chart files
  • app.synth() - synthesizes the CDK8s application

Error encountered: Initially forgot these calls, resulting in incomplete chart generation.

2. Ingress Configuration

Timonel automatically generates complete ingress structures with:

  • Basic properties (enableIngress, ingressHost)
  • Advanced configuration (annotations, className, hosts, tls)
  • Proper Helm templating with conditional rendering

Error encountered: Manual defaultValues modifications in subcharts were unnecessary and caused conflicts.

3. Subchart Independence

Each subchart operates independently but integrates seamlessly through the umbrella chart's coordination.

4. Helm Compatibility

Generated templates are fully Helm-compatible and follow Kubernetes best practices for production deployments.

Key Success: The final implementation generates production-ready Helm charts that pass helm install --dry-run and deploy successfully to Kubernetes clusters.

Conclusion

This example demonstrates how to create a production-ready WordPress + MySQL Helm chart using Timonel. The key is following the proper synthesis workflow and using Timonel's built-in configurations.

Result: A complete, deployable Helm chart that follows Kubernetes best practices, generated entirely through Timonel's declarative approach.

Clone this wiki locally