Skip to content

Commit 1448692

Browse files
authored
Merge pull request #189541 from JnHs/jh-as-gfnote
multi-tenancy notes and info
2 parents fca87bd + e170e65 commit 1448692

File tree

1 file changed

+131
-39
lines changed

1 file changed

+131
-39
lines changed

articles/azure-arc/kubernetes/tutorial-use-gitops-flux2.md

Lines changed: 131 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ description: "This tutorial shows how to use GitOps with Flux v2 to manage confi
44
keywords: "GitOps, Flux, Kubernetes, K8s, Azure, Arc, AKS, Azure Kubernetes Service, containers, devops"
55
services: azure-arc, aks
66
ms.service: azure-arc
7-
ms.date: 1/24/2022
7+
ms.date: 2/22/2022
88
ms.topic: tutorial
9-
author: csand-msft
10-
ms.author: csand
119
ms.custom: template-tutorial, devx-track-azurecli
1210
---
1311

@@ -17,7 +15,10 @@ GitOps with Flux v2 can be enabled in Azure Kubernetes Service (AKS) managed clu
1715

1816
This tutorial describes how to use GitOps in a Kubernetes cluster. Before you dive in, take a moment to [learn how GitOps with Flux works conceptually](./conceptual-gitops-flux2.md).
1917

20-
General availability of Azure Arc-enabled Kubernetes includes GitOps with Flux v1. The public preview of GitOps with Flux v2, documented here, is available in both Azure Arc-enabled Kubernetes and AKS. Flux v2 is the way forward, and Flux v1 will eventually be deprecated.
18+
General availability of Azure Arc-enabled Kubernetes includes GitOps with Flux v1. The public preview of GitOps with Flux v2, documented here, is available in both AKS and Azure Arc-enabled Kubernetes. Flux v2 is the way forward, and Flux v1 will eventually be deprecated.
19+
20+
>[!IMPORTANT]
21+
>GitOps with Flux v2 is in public preview. In preparation for general availability, features are still being added to the preview. One important feature, multi-tenancy, could be a breaking change for some users. To prepare yourself for the release of multi-tenancy, [please review these details](#multi-tenancy).
2122
2223
## Prerequisites
2324

@@ -40,34 +41,32 @@ To manage GitOps through the Azure CLI or the Azure portal, you need the followi
4041
* Read and write permissions on the `Microsoft.ContainerService/managedClusters` resource type.
4142
* Registration of your subscription with the `AKS-ExtensionManager` feature flag. Use the following command:
4243

43-
```azurecli
44+
```console
4445
az feature register --namespace Microsoft.ContainerService --name AKS-ExtensionManager
4546
```
4647

4748
### Common to both cluster types
4849

4950
* Azure CLI version 2.15 or later. [Install the Azure CLI](/cli/azure/install-azure-cli) or use the following commands to update to the latest version:
5051

51-
```azurecli
52+
```console
5253
az version
5354
az upgrade
5455
```
5556

5657
* Registration of the following Azure service providers. (It's OK to re-register an existing provider.)
5758

58-
```azurecli
59+
```console
5960
az provider register --namespace Microsoft.Kubernetes
6061
az provider register --namespace Microsoft.ContainerService
6162
az provider register --namespace Microsoft.KubernetesConfiguration
6263
```
6364

6465
Registration is an asynchronous process and should finish within 10 minutes. Use the following code to monitor the registration process:
6566

66-
```azurecli
67+
```console
6768
az provider show -n Microsoft.KubernetesConfiguration -o table
68-
```
6969

70-
```output
7170
Namespace RegistrationPolicy RegistrationState
7271
--------------------------------- -------------------- -------------------
7372
Microsoft.KubernetesConfiguration RegistrationRequired Registered
@@ -96,25 +95,23 @@ The GitOps agents require TCP on port 443 (`https://:443`) to function. The agen
9695
9796
Install the latest `k8s-configuration` and `k8s-extension` CLI extension packages:
9897

99-
```azurecli
98+
```console
10099
az extension add -n k8s-configuration
101100
az extension add -n k8s-extension
102101
```
103102

104103
To update these packages, use the following commands:
105104

106-
```azurecli
105+
```console
107106
az extension update -n k8s-configuration
108107
az extension update -n k8s-extension
109108
```
110109

111110
To see the list of az CLI extensions installed and their versions, use the following command:
112111

113-
```azurecli
112+
```console
114113
az extension list -o table
115-
```
116114

117-
```output
118115
Experimental ExtensionType Name Path Preview Version
119116
------------- -------------- ----------------- ----------------------------------------------------- -------- --------
120117
False whl connectedk8s C:\Users\somename\.azure\cliextensions\connectedk8s False 1.2.0
@@ -142,11 +139,9 @@ In the following example:
142139

143140
If the `microsoft.flux` extension isn't already installed in the cluster, it will be installed.
144141

145-
```azurecli
142+
```console
146143
az k8s-configuration flux create -g flux-demo-rg -c flux-demo-arc -n gitops-demo --namespace gitops-demo -t connectedClusters --scope cluster -u https://github.com/fluxcd/flux2-kustomize-helm-example --branch main --kustomization name=infra path=./infrastructure prune=true --kustomization name=apps path=./apps/staging prune=true dependsOn=["infra"]
147-
```
148144

149-
```output
150145
Command group 'k8s-configuration flux' is in preview and under development. Reference and support levels: https://aka.ms/CLI_refstatus
151146
Warning! https url is being used without https auth params, ensure the repository url provided is not a private repo
152147
'Microsoft.Flux' extension not found on the cluster, installing it now. This may take a few minutes...
@@ -160,11 +155,9 @@ Creating the flux configuration 'gitops-demo' in the cluster. This may take a fe
160155

161156
Show the configuration after time to finish reconciliations.
162157

163-
```azurecli
158+
```console
164159
az k8s-configuration flux show -g flux-demo-rg -c flux-demo-arc -n gitops-demo -t connectedClusters
165-
```
166160

167-
```output
168161
Command group 'k8s-configuration flux' is in preview and under development. Reference and support levels: https://aka.ms/CLI_refstatus
169162
{
170163
"complianceState": "Compliant",
@@ -559,7 +552,7 @@ statefulset.apps/redis-master 1/1 95m
559552

560553
You can delete the Flux configuration by using the following command. This action deletes both the `fluxConfigurations` resource in Azure and the Flux configuration objects in the cluster. Because the Flux configuration was originally created with the `prune=true` parameter for the kustomization, all of the objects created in the cluster based on manifests in the Git repository will be removed when the Flux configuration is removed.
561554

562-
```azurecli
555+
```console
563556
az k8s-configuration flux delete -g flux-demo-rg -c flux-demo-arc -n gitops-demo -t connectedClusters --yes
564557
```
565558

@@ -573,7 +566,7 @@ If the Flux extension was created automatically when the Flux configuration was
573566

574567
For an Azure Arc-enabled Kubernetes cluster, use this command:
575568

576-
```azurecli
569+
```console
577570
az k8s-extension delete -g flux-demo-rg -c flux-demo-arc -n flux -t connectedClusters --yes
578571
```
579572

@@ -592,7 +585,7 @@ The `source`, `helm`, `kustomize`, and `notification` Flux controllers are insta
592585

593586
Here's an example for including the [Flux image-reflector and image-automation controllers](https://fluxcd.io/docs/components/image/). If the Flux extension was created automatically when a Flux configuration was first created, the extension name will be `flux`.
594587

595-
```azurecli
588+
```console
596589
az k8s-extension create -g <cluster_resource_group> -c <cluster_name> -t <connectedClusters or managedClusters> --name flux --extension-type microsoft.flux --config image-automation-controller.enabled=true image-reflector-controller.enabled=true
597590
```
598591

@@ -602,11 +595,9 @@ For a description of all parameters that Flux supports, see the [official Flux d
602595

603596
You can see the full list of parameters that the `k8s-configuration flux` CLI command supports by using the `-h` parameter:
604597

605-
```azurecli
598+
```console
606599
az k8s-configuration flux -h
607-
```
608600

609-
```output
610601
Group
611602
az k8s-configuration flux : Commands to manage Flux v2 Kubernetes configurations.
612603
This command group is in preview and under development. Reference and support levels:
@@ -627,11 +618,9 @@ Commands:
627618

628619
Here are the parameters for the `k8s-configuration flux create` CLI command:
629620

630-
```azurecli
621+
```console
631622
az k8s-configuration flux create -h
632-
```
633623

634-
```output
635624
This command is from the following extension: k8s-configuration
636625

637626
Command
@@ -841,7 +830,7 @@ kubectl create secret generic -n flux-config my-custom-secret --from-file=identi
841830

842831
For both cases, when you create the Flux configuration, use `--local-auth-ref my-custom-secret` in place of the other authentication parameters:
843832

844-
```azurecli
833+
```console
845834
az k8s-configuration flux create -g <cluster_resource_group> -c <cluster_name> -n <config_name> -t connectedClusters --scope cluster --namespace flux-config -u <git-repo-url> --kustomization name=kustomization1 --local-auth-ref my-custom-secret
846835
```
847836
Learn more about using a local Kubernetes secret with these authentication methods:
@@ -851,7 +840,7 @@ Learn more about using a local Kubernetes secret with these authentication metho
851840
* [Bucket static authentication](https://fluxcd.io/docs/components/source/buckets/#static-authentication)
852841

853842
>[!NOTE]
854-
>If you need Flux to access the source through your proxy, you'll need to update the Azure Arc agents with the proxy settings. For more information, see [Connect using an outbound proxy server](./quickstart-connect-cluster.md?tabs=azure-cli#connect-using-an-outbound-proxy-server).
843+
>If you need Flux to access the source through your proxy, you'll need to update the Azure Arc agents with the proxy settings. For more information, see [Connect using an outbound proxy server](./quickstart-connect-cluster.md?tabs=azure-cli-connect-using-an-outbound-proxy-server).
855844
856845
### Git implementation
857846

@@ -883,11 +872,9 @@ By using `az k8s-configuration flux create`, you can create one or more kustomiz
883872

884873
You can also use `az k8s-configuration flux kustomization` to create, update, list, show, and delete kustomizations in a Flux configuration:
885874

886-
```azurecli
875+
```console
887876
az k8s-configuration flux kustomization -h
888-
```
889877

890-
```output
891878
Group
892879
az k8s-configuration flux kustomization : Commands to manage Kustomizations associated with Flux
893880
v2 Kubernetes configurations.
@@ -904,11 +891,9 @@ Commands:
904891

905892
Here are the kustomization creation options:
906893

907-
```azurecli
894+
```console
908895
az k8s-configuration flux kustomization create -h
909-
```
910896

911-
```output
912897
This command is from the following extension: k8s-configuration
913898

914899
Command
@@ -1010,13 +995,120 @@ spec:
1010995

1011996
By using this annotation, the HelmRelease that is deployed will be patched with the reference to the configured source. Note that only GitRepository source is supported for this currently.
1012997

998+
## Multi-tenancy
999+
1000+
Flux v2 supports [multi-tenancy](https://github.com/fluxcd/flux2-multi-tenancy). This capability will be integrated into Azure GitOps with Flux v2 prior to general availability.
1001+
1002+
>[!NOTE]
1003+
>This will be a breaking change if you have any cross-namespace sourceRef for HelmRelease, Kustomization, ImagePolicy, or other objects. To prepare for the release of this multi-tenancy feature, take one of these actions:
1004+
>
1005+
>* (Recommended) Assure that all sourceRef are to objects within the same namespace as the GitOps configuration.
1006+
>* If you need time to migrate, you can opt-out of multi-tenancy.
1007+
1008+
### Update manifests for multi-tenancy
1009+
1010+
Let’s say we deploy a `fluxConfiguration` to one of our Kubernetes clusters in the **cluster-config** namespace with cluster scope. We configure the source to sync the https://github.com/fluxcd/flux2-kustomize-helm-example repo. This is the same sample Git repo used in the tutorial earlier in this doc. After Flux syncs the repo, it will deploy the resources described in the manifests (yamls). Two of the manifests describe HelmRelease and HelmRepository objects.
1011+
1012+
```yaml
1013+
apiVersion: helm.toolkit.fluxcd.io/v2beta1
1014+
kind: HelmRelease
1015+
metadata:
1016+
name: nginx
1017+
namespace: nginx
1018+
spec:
1019+
releaseName: nginx-ingress-controller
1020+
chart:
1021+
spec:
1022+
chart: nginx-ingress-controller
1023+
sourceRef:
1024+
kind: HelmRepository
1025+
name: bitnami
1026+
namespace: flux-system
1027+
version: "5.6.14"
1028+
interval: 1h0m0s
1029+
install:
1030+
remediation:
1031+
retries: 3
1032+
# Default values
1033+
# https://github.com/bitnami/charts/blob/master/bitnami/nginx-ingress-controller/values.yaml
1034+
values:
1035+
service:
1036+
type: NodePort
1037+
```
1038+
1039+
```yaml
1040+
apiVersion: source.toolkit.fluxcd.io/v1beta1
1041+
kind: HelmRepository
1042+
metadata:
1043+
name: bitnami
1044+
namespace: flux-system
1045+
spec:
1046+
interval: 30m
1047+
url: https://charts.bitnami.com/bitnami
1048+
```
1049+
1050+
By default, the Flux extension will deploy the `fluxConfigurations` by impersonating the **flux-applier** service account that is deployed only in the **cluster-config** namespace. Using the above manifests, when multi-tenancy is enabled the HelmRelease would be blocked. This is because the HelmRelease is in the **nginx** namespace and is referencing a HelmRepository in the **flux-system** namespace. Also, the Flux helm-controller cannot apply the HelmRelease, because there is no **flux-applier** service account in the **nginx** namespace.
1051+
1052+
To work with multi-tenancy, the correct approach is to deploy all Flux objects into the same namespace as the `fluxConfigurations`. This avoids the cross-namespace reference issue, and allows the Flux controllers to get the permissions to apply the objects. Thus, for a GitOps configuration created in the **cluster-config** namespace, the above manifests would change to these:
1053+
1054+
```yaml
1055+
apiVersion: helm.toolkit.fluxcd.io/v2beta1
1056+
kind: HelmRelease
1057+
metadata:
1058+
name: nginx
1059+
namespace: cluster-config
1060+
spec:
1061+
releaseName: nginx-ingress-controller
1062+
targetNamespace: nginx
1063+
chart:
1064+
spec:
1065+
chart: nginx-ingress-controller
1066+
sourceRef:
1067+
kind: HelmRepository
1068+
name: bitnami
1069+
namespace: cluster-config
1070+
version: "5.6.14"
1071+
interval: 1h0m0s
1072+
install:
1073+
remediation:
1074+
retries: 3
1075+
# Default values
1076+
# https://github.com/bitnami/charts/blob/master/bitnami/nginx-ingress-controller/values.yaml
1077+
values:
1078+
service:
1079+
type: NodePort
1080+
```
1081+
1082+
```yaml
1083+
apiVersion: source.toolkit.fluxcd.io/v1beta1
1084+
kind: HelmRepository
1085+
metadata:
1086+
name: bitnami
1087+
namespace: cluster-config
1088+
spec:
1089+
interval: 30m
1090+
url: https://charts.bitnami.com/bitnami
1091+
```
1092+
1093+
### Opt out of multi-tenancy
1094+
1095+
Multi-tenancy will be enabled by default to assure security by default in your clusters. However, if you need to disable multi-tenancy, you can opt out by creating or updating the `microsoft.flux` extension in your clusters with "--configuration-settings multiTenancy.enforce=false".
1096+
1097+
```console
1098+
az k8s-extension create --extension-type microsoft.flux --configuration-settings multiTenancy.enforce=false -c CLUSTER_NAME -g RESOURCE_GROUP -n flux -t <managedClusters or connectedClusters>
1099+
1100+
or
1101+
1102+
az k8s-extension update --configuration-settings multiTenancy.enforce=false -c CLUSTER_NAME -g RESOURCE_GROUP -n flux -t <managedClusters or connectedClusters>
1103+
```
1104+
10131105
## Migrate from Flux v1
10141106

10151107
If you've been using Flux v1 in Azure Arc-enabled Kubernetes or AKS clusters and want to migrate to using Flux v2 in the same clusters, you first need to delete the Flux v1 `sourceControlConfigurations` from the clusters. The `microsoft.flux` cluster extension won't be installed if there are `sourceControlConfigurations` resources installed in the cluster.
10161108

10171109
Use these az CLI commands to find and then delete existing `sourceControlConfigurations` in a cluster:
10181110

1019-
```azurecli
1111+
```console
10201112
az k8s-configuration list --cluster-name <Arc or AKS cluster name> --cluster-type <connectedClusters OR managedClusters> --resource-group <resource group name>
10211113
az k8s-configuration delete --name <configuration name> --cluster-name <Arc or AKS cluster name> --cluster-type <connectedClusters OR managedClusters> --resource-group <resource group name>
10221114
```

0 commit comments

Comments
 (0)