GitOps Testing with Flux
Flux, a Kubernetes-native continuous delivery solution, is a leading tool for facilitating the GitOps process. It streamlines application deployment management by continuously syncing the Git repository with the Kubernetes cluster.
With the integration of Flux into Testkube, it ensures automated and streamlined workflows for Kubernetes deployments and testing. When Testkube is added to the GitOps process, automated testing is added to the deployment lifecycle. This approach cuts down on the time and effort needed for manual work and speeds up the testing and deployment process, giving faster feedback and better application delivery.
Flux Integration
Testkube can be integrated into a Flux-managed CI/CD pipeline, with Flux managing continuous application delivery and Testkube ensuring thorough testing at all stages. Here is how to integrate Flux with Testkube for automated GitOps testing.
Prerequisites
- Testkube
- Kubernetes cluser
- Testkube Agent configured on the cluster
- Flux is configured on the cluster
- Install the Flux CLI
1. Configure the GitHub repo on Flux
Run the flux bootstrap github command to deploy and configure the Flux controllers on a Kubernetes cluster and link them to a GitHub repo for synchronization of the cluster's state. Additionally, this command simplifies the process of pushing the Flux manifests to the designated GitHub repo.
Note: Before using Flux, create a GitHub personal access token (PAT) to be used later for authentication.
2. Export PAT
After the PAT is created, export it as an environment variable using the following command:
export GITHB_TOKEN=<gh-token>
3. Configure Flux
Install the Flux CLI and run the following command to sync with the repo:
flux bootstrap github \
--owner=techmaharaj \
--repository=testkube-flux \
--path=cluster \
--personal
4. Set up Git source in Flux
Add a Git source that specifies the repo and branch to be monitored for changes by executing the following command:
flux create source git testkube-tests \
--url=https://github.com/techmaharaj/testkube-flux \
--branch=main \
--interval=30s
5. Create a Kustomization
Create Kustomization that instructs the Flux controller to monitor the Git repo at regular intervals and sync the resources to the Kubernetes cluster:
flux create kustomization testkube-test \
--target-namespace=testkube \
--source=testkube-tests \
--path="cluster" \
--prune=true \
--interval=30s
6. Verify Kustomization status
To verify if the sync was successful, use the following command to monitor Flux's progress and see if it successfully synced the resources.
flux get kustomizations --watch
This command shows the status of the Kustomizations and continuously updates as changes are applied.
| NAME | REVISION | SUSPENDED | READY | MESSAGE |
| ----------------------- | ------------------ | ----------- | ---------- | ------------------------------------- |
| flux-system | main@sha1:a72cbbd4 | False | True | Applied revision: main@sha1:a72cbbd4 |
| testkube-test | main@sha1:a72cbbd4 | False | True | Applied revision: main@sha1:a72cbbd4 |
7. Verify Testkube Test Workflow creation
After confirming that the synchronization is successful with Flux, verify if the Test Workflow has been created in the testkube namespace by using the following command:
kubectl get testworkflows -n testkube
| NAME | AGE |
| ----------------------- | --------- |
| basic-k6-workflow | 3m38s |
GitOps Takeaways
Once fully realized, leveraging GitOps for Kubernetes application testing as outlined above provides a powerful alternative to the more traditional approach where orchestration is tied to your current CI/CD tooling and not closely aligned with the lifecycle of Kubernetes applications.