Skip to main content
In this guide, we’ll walk through deploying a MySQL database on Kubernetes using Flux’s GitRepository and Kustomization controllers along with Kustomize manifests. By following these steps, you will:
  1. Update the PHP application to connect to MySQL
  2. Define Kubernetes manifests for MySQL
  3. Use Flux GitRepository and Kustomization resources for GitOps deployment

1. Update the PHP Application

On the 7-demo branch, the PHP app has been extended to store high scores in a MySQL database. The connection logic in highscore.php now looks like:
Ensure you’re on the correct branch in your terminal:

2. Inspect the Infrastructure Branch

All MySQL manifests and namespace definitions reside in the infrastructure branch under the database/ directory:
Inside database/, you’ll find:
  • namespace.yaml
  • configmap.yaml
  • secret.yaml
  • deployment.yaml
  • service.yaml
  • PersistentVolume and PersistentVolumeClaim manifests
Storing passwords in plain text is insecure. Use sealed-secrets or another secret management solution for production environments.

3. Create a Flux GitRepository Source

Define a GitRepository resource in your Flux cluster repo (flux-clusters/dev-cluster) to track the infrastructure branch:
Export it with the Flux CLI:

4. Create a Flux Kustomization

Use a Kustomization to apply resources under database/:
Generate via:
Commit and push both manifests:

5. Reconcile and Verify

Force Flux to apply changes immediately:
Check that the database namespace is created:
Inspect Flux sources and kustomizations:
Verify MySQL resources in database namespace:
The MySQL database is now up and running! Next, we’ll pull the PHP application image from an OCI registry and deploy it with Flux.

Flux Resources Overview


Watch Video