|
| 1 | +--- |
| 2 | +title: "Apply Flux v2 configurations at-scale using Azure Policy" |
| 3 | +services: azure-arc, container-service |
| 4 | +ms.date: 8/23/2022 |
| 5 | +ms.topic: how-to |
| 6 | +description: "Apply Flux v2 configurations at-scale using Azure Policy" |
| 7 | +keywords: "Kubernetes, K8s, Arc, AKS, Azure, containers, GitOps, Flux v2, policy" |
| 8 | +--- |
| 9 | + |
| 10 | +# Apply Flux v2 configurations at-scale using Azure Policy |
| 11 | + |
| 12 | +You can use Azure Policy to apply Flux v2 configurations (`Microsoft.KubernetesConfiguration/fluxConfigurations` resource type) at scale on Azure Arc-enabled Kubernetes (`Microsoft.Kubernetes/connectedClusters`) or AKS (`Microsoft.ContainerService/managedClusters`) clusters. |
| 13 | + |
| 14 | +To use Azure Policy, select a built-in policy definition and create a policy assignment. You can search for **flux** to find all of the Flux v2 policy definitions. When creating the policy assignment: |
| 15 | +1. Set the scope for the assignment. |
| 16 | + * The scope will be all resource groups in a subscription or management group or specific resource groups. |
| 17 | +2. Set the parameters for the Flux v2 configuration that will be created. |
| 18 | + |
| 19 | +Once the assignment is created, the Azure Policy engine identifies all Azure Arc-enabled Kubernetes clusters located within the scope and applies the GitOps configuration to each cluster. |
| 20 | + |
| 21 | +To enable separation of concerns, you can create multiple policy assignments, each with a different Flux v2 configuration pointing to a different source. For example, one git repository may be used by cluster admins and other repositories may be used by application teams. |
| 22 | + |
| 23 | +> [!TIP] |
| 24 | +> There are built-in policy definitions for these scenarios: |
| 25 | +> * Flux extension install (required for all scenarios): `Configure installation of Flux extension on Kubernetes cluster` |
| 26 | +> * Flux configuration using public Git repository (generally a test scenario): `Configure Kubernetes clusters with Flux v2 configuration using public Git repository` |
| 27 | +> * Flux configuration using private Git repository with SSH auth: `Configure Kubernetes clusters with Flux v2 configuration using Git repository and SSH secrets` |
| 28 | +> * Flux configuration using private Git repository with HTTPS auth: `Configure Kubernetes clusters with Flux v2 configuration using Git repository and HTTPS secrets` |
| 29 | +> * Flux configuration using private Git repository with HTTPS CA cert auth: `Configure Kubernetes clusters with Flux v2 configuration using Git repository and HTTPS CA Certificate` |
| 30 | +> * Flux configuration using private Git repository with local K8s secret: `Configure Kubernetes clusters with Flux v2 configuration using Git repository and local secrets` |
| 31 | +> * Flux configuration using private Bucket source and KeyVault secrets: `Configure Kubernetes clusters with Flux v2 configuration using Bucket source and secrets in KeyVault` |
| 32 | +> * Flux configuration using private Bucket source and local K8s secret: `Configure Kubernetes clusters with specified Flux v2 Bucket source using local secrets` |
| 33 | +
|
| 34 | +## Prerequisite |
| 35 | + |
| 36 | +Verify you have `Microsoft.Authorization/policyAssignments/write` permissions on the scope (subscription or resource group) where you'll create this policy assignment. |
| 37 | + |
| 38 | +## Create a policy assignment |
| 39 | + |
| 40 | +1. In the Azure portal, navigate to **Policy**. |
| 41 | +1. In the **Authoring** section of the sidebar, select **Definitions**. |
| 42 | +1. In the "Kubernetes" category, choose the "Configure Kubernetes clusters with specified GitOps configuration using no secrets" built-in policy definition. |
| 43 | +1. Select **Assign**. |
| 44 | +1. Set the **Scope** to the management group, subscription, or resource group to which the policy assignment will apply. |
| 45 | + * If you want to exclude any resources from the policy assignment scope, set **Exclusions**. |
| 46 | +1. Give the policy assignment an easily identifiable **Name** and **Description**. |
| 47 | +1. Ensure **Policy enforcement** is set to **Enabled**. |
| 48 | +1. Select **Next**. |
| 49 | +1. Set the parameter values to be used while creating the `fluxConfigurations` resource. |
| 50 | + * For more information about parameters, see the [tutorial on deploying Flux v2 configurations](./tutorial-use-gitops-flux2.md). |
| 51 | +1. Select **Next**. |
| 52 | +1. Enable **Create a remediation task**. |
| 53 | +1. Verify **Create a managed identity** is checked, and that the identity will have **Contributor** permissions. |
| 54 | + * For more information, see the [Create a policy assignment quickstart](../../governance/policy/assign-policy-portal.md) and the [Remediate non-compliant resources with Azure Policy article](../../governance/policy/how-to/remediate-resources.md). |
| 55 | +1. Select **Review + create**. |
| 56 | + |
| 57 | +After creating the policy assignment, the configuration is applied to new Azure Arc-enabled Kubernetes or AKS clusters created within the scope of policy assignment. |
| 58 | + |
| 59 | +For existing clusters, you may need to manually run a remediation task. This task typically takes 10 to 20 minutes for the policy assignment to take effect. |
| 60 | + |
| 61 | +## Verify a policy assignment |
| 62 | + |
| 63 | +1. In the Azure portal, navigate to one of your Azure Arc-enabled Kubernetes or AKS clusters. |
| 64 | +1. In the **Settings** section of the sidebar, select **GitOps**. |
| 65 | + * In the configurations list, you should see the configuration created by the policy assignment. |
| 66 | +1. In the **Kubernetes resources** section of the sidebar, select **Namespaces** and **Workloads**. |
| 67 | + * You should see the namespace and artifacts that were created by the Flux configuration. |
| 68 | + * You should see the objects described by the manifests in the Git repo deployed on the cluster. |
| 69 | + |
| 70 | +## Next steps |
| 71 | + |
| 72 | +[Set up Azure Monitor for Containers with Azure Arc-enabled Kubernetes clusters](../../azure-monitor/containers/container-insights-enable-arc-enabled-clusters.md). |
0 commit comments