Flux
GitOps for AKS
This is taken from: https://learn.microsoft.com/en-us/azure/azure-arc/kubernetes/tutorial-use-gitops-flux2?tabs=azure-cli
Install the latest k8s-configuration
and k8s-extension
CLI extension packages:
The following example applies a Flux configuration to a cluster, using the following values and settings:
The resource group that contains the cluster is
flux-demo-rg
.The name of the Azure Arc cluster is
flux-demo-arc
.The cluster type is Azure Arc (
-t connectedClusters
), but this example also works with AKS (-t managedClusters
) and AKS hybrid clusters provisioned from Azure (-t provisionedClusters
).The name of the Flux configuration is
cluster-config
.The namespace for configuration installation is
cluster-config
.The URL for the public Git repository is
https://github.com/Azure/gitops-flux2-kustomize-helm-mt
.The Git repository branch is
main
.The scope of the configuration is
cluster
. This gives the operators permissions to make changes throughout cluster.Two kustomizations are specified with names
infra
andapps
. Each is associated with a path in the repository.The
apps
kustomization depends on theinfra
kustomization. (Theinfra
kustomization must finish before theapps
kustomization runs.)Set
prune=true
on both kustomizations. This setting ensures that the objects that Flux deployed to the cluster will be cleaned up if they're removed from the repository or if the Flux configuration or kustomizations are deleted.
The microsoft.flux
extension will be installed on the cluster (if it hasn't already been installed due to a previous GitOps deployment).
When the flux configuration is first installed, the initial compliance state may be Pending
or Non-compliant
because reconciliation is still ongoing. After a minute or so, query the configuration again to see the final compliance state.
To confirm that the deployment was successful, run the following command:
With a successful deployment the following namespaces are created:
flux-system
: Holds the Flux extension controllers.cluster-config
: Holds the Flux configuration objects.nginx
,podinfo
,redis
: Namespaces for workloads described in manifests in the Git repository.
To confirm the namespaces, run the following command:
Azure CLICopy
The flux-system
namespace contains the Flux extension objects:
Azure Flux controllers:
fluxconfig-agent
,fluxconfig-controller
OSS Flux controllers:
source-controller
,kustomize-controller
,helm-controller
,notification-controller
The Flux agent and controller pods should be in a running state. Confirm this using the following command:
The namespace cluster-config
has the Flux configuration objects.
Confirm other details of the configuration by using the following commands.
Workloads are deployed from manifests in the Git repository.
Create an image pull secret
To connect non-AKS and local clusters to your Azure Container Registry, create an image pull secret. Kubernetes uses image pull secrets to store information needed to authenticate your registry.
Create an image pull secret with the following kubectl
command. Repeat for both the dev
and stage
namespaces.
To avoid having to set an imagePullSecret for every Pod, consider adding the imagePullSecret to the Service account in the dev
and stage
namespaces.
Depending on the CI/CD orchestrator you prefer, you can proceed with instructions either for Azure DevOps or for GitHub.
Connect the GitOps repository
To continuously deploy your app, connect the application repository to your cluster using GitOps. Your arc-cicd-demo-gitops GitOps repository contains the basic resources to get your app up and running on your arc-cicd-cluster cluster.
The initial GitOps repository contains only a manifest that creates the dev and stage namespaces corresponding to the deployment environments.
The GitOps connection that you create will automatically:
Sync the manifests in the manifest directory.
Update the cluster state.
The CI/CD workflow populates the manifest directory with extra manifests to deploy the app.
Create a new GitOps connection to your newly imported arc-cicd-demo-gitops repository in Azure Repos.
Azure CLICopy
Implement CI/CD with GitHub
Fork application and GitOps repositories
Fork an application repository and a GitOps repository. For this tutorial, use the following example repositories:
arc-cicd-demo-src application repository
Contains the example Azure Vote App that you will deploy using GitOps.
arc-cicd-demo-gitops GitOps repository
Works as a base for your cluster resources that house the Azure Vote App.
Connect the GitOps repository
To continuously deploy your app, connect the application repository to your cluster using GitOps. Your arc-cicd-demo-gitops GitOps repository contains the basic resources to get your app up and running on your arc-cicd-cluster cluster.
The initial GitOps repository contains only a manifest that creates the dev and stage namespaces corresponding to the deployment environments.
The GitOps connection that you create will automatically:
Sync the manifests in the manifest directory.
Update the cluster state.
The CI/CD workflow populates the manifest directory with extra manifests to deploy the app.
Create a new GitOps connection to your newly forked arc-cicd-demo-gitops repository in GitHub.
Check the state of the deployment in Azure portal.
If successful, you'll see both
dev
andstage
namespaces created in your cluster.
Last updated