This documentation section provides a detailed guide on how to monitor the production workloads deployed using the fluxcd/flux2-kustomize-helm-example
. The monitoring process involves using Flux’s built-in capabilities along with CLI commands to ensure visibility and real-time updates regarding the state of the deployed applications.
Prerequisites
Before initializing monitoring, ensure that Flux has been successfully bootstrapped in the production environment as specified in the repository. The following command initializes Flux with the production context:
flux bootstrap github \
--context=production \
--owner=${GITHUB_USER} \
--repository=${GITHUB_REPO} \
--branch=main \
--personal \
--path=clusters/production
Monitoring the Kustomizations in Production
To monitor the Kustomizations in the production environment, the following command can be executed. This will provide a continuous watch on the Kustomization resources:
$ flux get kustomizations --watch
This command ensures that you are informed about the status of Kustomizations consistently. Any updates or failures can be observed in real time, allowing for immediate action if required.
Monitoring Helm Releases
To observe the Helm releases being installed in the staging environment, you can utilize:
$ watch flux get helmreleases --all-namespaces
This command effectively watches and lists all Helm releases across all namespaces. By using --all-namespaces
, it provides a holistic view of the releases, ensuring any changes, failures, or upgrades can be noted.
Validating Kubernetes Manifests Before Changes
An important aspect of maintaining a stable production environment is validating Kubernetes manifests before applying any changes. The following shell script demonstrates how to validate kustomization overlays using kubeconform
:
echo "INFO - Validating kustomize overlays"
find . -type f -name $kustomize_config -print0 | while IFS= read -r -d $'\0' file;
do
echo "INFO - Validating kustomization ${file/%$kustomize_config}"
kustomize build "${file/%$kustomize_config}" "${kustomize_flags[@]}" | \
kubeconform "${kubeconform_flags[@]}" "${kubeconform_config[@]}"
if [[ ${PIPESTATUS[0]} != 0 ]]; then
exit 1
fi
done
This script locates all kustomize configuration files and validates them. If any validation fails, the script exits with a non-zero status, preventing any faulty manifests from being deployed.
Monitoring Workflow through CI
Automated continuous integration (CI) workflows are crucial in the production monitoring process. The repository contains CI workflows that validate Kubernetes manifests and Kustomize overlays with kubeconform
. For example:
# A snippet from CI workflow config
steps:
- name: Validate Manifests
run: |
./scripts/validate.sh
Implementing such CI steps ensures all changes are vetted before they impact the production environment. The e2e workflow can also be configured to deploy to a testing environment, ensuring that any new changes are properly verified before merging to the main.
Conclusion
The monitoring practices implemented in this example are vital for ensuring the proper functioning and stability of production workloads. By leveraging Flux’s capabilities for Kustomization and Helm, along with robust CI workflows for validation, teams can maintain a resilient application deployment strategy. Continual monitoring, validation, and automation are key components of observability and reliability in production environments.