This documentation provides a comprehensive step-by-step guide for deploying the FluxCD Kustomize Helm example to a production environment.

Prerequisites

Ensure you have the necessary configurations set up prior to initiating the deployment. This includes forking the repository, exporting environment variables for GitHub access, and checking the state of your cluster.

export GITHUB_TOKEN=<your_token>
export GITHUB_USER=<your_username>
export GITHUB_REPO=<your_repo>

Verify the prerequisites for your production cluster:

flux check --pre

Bootstrapping the Production Environment

To bootstrap Flux in your production cluster, execute the following command. Make sure to set the context and specify the path relevant to your production cluster.

flux bootstrap github \
--context=production \
--owner=${GITHUB_USER} \
--repository=${GITHUB_REPO} \
--branch=main \
--personal \
--path=clusters/production

The above bootstrap command initializes Flux within the specified cluster and commits the necessary manifests in the clusters/production/flux-system directory.

Setting Up the Production Clone

In scenarios where you want to create a production clone for testing or development, bootstrap a new cluster named production-clone using the definitions from your production setup.

flux bootstrap github \
--context=production-clone \
--owner=${GITHUB_USER} \
--repository=${GITHUB_REPO} \
--branch=main \
--personal \
--path=clusters/production-clone

After bootstrapping the clone, pull the latest changes.

git pull origin main

Configuration Files

Create a kustomization.yaml in the clusters/production-clone directory to specify the resources that Flux should manage. Ensure it references your production infrastructure and application manifests.

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- flux-system
- ../production/infrastructure.yaml
- ../production/apps.yaml

Deploying Production Workloads

Push any changes to your manifest files to the main branch in order for Flux to automatically detect and apply them.

git add -A && git commit -m "add production clone" && git push

To instruct Flux to reconcile the kustomization and deploy workloads to the production-clone, use the following command:

flux reconcile kustomization flux-system \
--context=production-clone \
--with-source

Watching Deployment Progress

Monitor the reconciliation status of your kustomizations to ensure they are applied as intended.

flux get kustomizations --watch

You will receive output indicating the status of your kustomizations, such as their readiness and any applied revisions.

NAME             	REVISION     	SUSPENDED	READY	MESSAGE
apps             	main/696182e	False    	True 	Applied revision: main/696182e
flux-system      	main/696182e	False    	True 	Applied revision: main/696182e
infra-configs    	main/696182e	False    	True 	Applied revision: main/696182e
infra-controllers	main/696182e	False    	True 	Applied revision: main/696182e

Testing Production Services

Once the deployment is applied, you can verify the services are running properly. Using a curl command, test one of the deployed services.

curl -H "Host: podinfo.production" http://localhost:8080

You should expect to receive a JSON response containing deployment details, confirming the service is up and functional.

{
"hostname": "podinfo-59489db7b5-lmwpn",
"version": "6.2.3"
}

This confirms that your production deployment is successfully configured and operational.