This documentation provides a step-by-step guide to deploying Continuous Integration/Continuous Delivery (CI/CD) with the fluxcd/flux2-multi-tenancy
project using Flux. Below are detailed instructions on setting up and verifying the CI/CD pipeline.
Prerequisites
Ensure that Flux and related tools are properly set up. This includes a working Kubernetes cluster and the Flux CLI installed on your local development environment.
CI/CD Setup
If CI/CD is not yet set up in the project, follow these next steps to deploy it:
Install the Flux CLI:
brew install fluxcd/tap/flux
Bootstrap Flux: Export your GitHub username and repository name. The repository should be forked from the multi-tenancy repository you are working with.
export GITHUB_USER=your-username export GITHUB_REPO=your-repo
Verify your cluster:
flux check --pre
Bootstrap Flux to connect to your GitHub repo:
flux bootstrap github \ --context=your-staging-context \ --owner=${GITHUB_USER} \ --repository=${GITHUB_REPO} \ --branch=main \ --personal \ --path=clusters/staging
Create Tenant Resources: You’ll need to create service accounts and role bindings for each tenant. Example for the dev-team:
flux create kustomization dev-team \ --namespace=apps \ --service-account=dev-team \ --source=GitRepository/dev-team \ --path="./" \ --export >> ./tenants/base/dev-team/sync.yaml
Base Kustomization: Create a base Kustomization for the tenant:
cd ./tenants/base/dev-team/ && kustomize create --autodetect --namespace apps
Create Staging Overlays: Set up a patch for staging deployments:
cat << EOF | tee ./tenants/staging/dev-team-patch.yaml apiVersion: kustomize.toolkit.fluxcd.io/v1 kind: Kustomization metadata: name: dev-team namespace: apps spec: path: ./staging EOF
Configure Helm Releases: The base directory in each tenant repository handles the Helm releases. Update the
kustomization.yaml
:apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization namespace: apps resources: - ../base/dev-team patches: - path: dev-team-patch.yaml
Verify Tenant Repository: After setting up your tenant repository, verify the Git sources:
flux -n apps get sources git
Monitor Helm Releases: Wait for the demo app to be installed and verify:
watch flux -n apps get helmreleases
Example output should show the Helm release status:
NAME READY MESSAGE REVISION SUSPENDED
podinfo True Release reconciliation succeeded 5.0.3 False
Conclusion
By following the above steps, you can set up a CI/CD pipeline using Flux for a multi-tenant Kubernetes environment. Ensure you replace placeholder data with your actual configurations.
Remember to review your tenant’s security policies and configurations to enforce proper isolation and security measures. For further configurations, always refer back to the Flux documentation to ensure compliance with best practices.
This documentation is a guide based on the project’s repository structure and command usage as described in various source files. Further tweaks might be needed based on specific use cases and requirements.