Reason Codebase
This codebase demonstrates a Flux-based infrastructure for deploying and managing applications across multiple Kubernetes clusters. The core principles are to use Git as a single source of truth and to leverage Kustomize for overlaying cluster-specific configurations.
The repository is structured into three main directories:
- apps: Contains Helm releases with custom configurations for each cluster.
- infrastructure: Defines shared infrastructure components like ingress-nginx and cert-manager.
- clusters: Contains Flux configuration for each cluster, defining deployments and dependencies.
Infrastructure:
- The infrastructure/controllers/ directory holds namespaces and Helm release definitions for Kubernetes controllers. These controllers are responsible for managing shared infrastructure components.
- The infrastructure/configs/ directory holds Kubernetes custom resources such as cert issuers and network policies. These resources are managed by the controllers and provide essential functionality for the cluster.
Apps:
- The apps/base/ directory defines the base Helm releases with common values for both clusters.
- The apps/production/ directory contains production-specific values that override the base values.
- The apps/staging/ directory contains staging-specific values that override the base values.
Clusters:
- Each cluster is represented by a dedicated directory within the clusters/ directory.
- These directories contain Kustomize definitions that define how the infrastructure and apps are deployed for that specific cluster.
Flux Management:
- Flux uses GitRepository and HelmRepository resources to track the source of truth for application and infrastructure definitions.
- HelmRelease resources are used to define the deployment of Helm charts, including their versions and values.
- Kustomization resources are used to overlay configurations based on the specific cluster.
Example:
- infrastructure/controllers/ingress-nginx.yaml: This file defines a HelmRepository and HelmRelease for the ingress-nginx controller. The release uses the
"*"
version for automatic updates. - clusters/production/infrastructure.yaml: This file defines two Kustomization resources for deploying infrastructure controllers and configurations in the production cluster. The
dependsOn
field ensures that the controllers are deployed before the configurations. - apps/base/podinfo/release.yaml: This file defines a HelmRelease for the podinfo application. The release specifies the chart source, interval for updates, and default values.
- clusters/staging/apps.yaml: This file defines a Kustomization resource that deploys the staging overlay for the apps. The
path: ./apps/staging
indicates the source of the overlay, anddependsOn
ensures that the infrastructure configurations are deployed before the applications.
Verification:
- The scripts/validate.sh script provides a way to validate the configuration files for Kubernetes compliance and syntax.
Summary:
This repository provides a comprehensive example of how to use Flux and Kustomize to manage infrastructure and application deployments across multiple Kubernetes clusters. By using Git as the source of truth and defining dependencies between resources, this approach ensures a consistent and automated deployment process.
Top-Level Directory Explanations
apps/ - This directory contains the application definitions and configurations. It includes base, production, staging directories.
apps/base/ - This directory contains the base application configurations. It includes podinfo directory.
apps/production/ - This directory contains the production application configurations.
apps/staging/ - This directory contains the staging application configurations.
clusters/ - This directory contains the Kubernetes cluster configurations. It includes production and staging directories.
clusters/production/ - This directory contains the production Kubernetes cluster configurations. It includes flux-system directory.
clusters/staging/ - This directory contains the staging Kubernetes cluster configurations. It includes flux-system directory.
infrastructure/ - This directory contains the infrastructure configurations and scripts.
infrastructure/configs/ - This directory contains the configuration files for the infrastructure.
infrastructure/controllers/ - This directory contains the Kubernetes controllers for managing the infrastructure.
scripts/ - This directory contains the scripts used for automating tasks.