|
| 1 | +# Preventing AGIC from removing certain rules |
| 2 | + |
| 3 | +> Note: This feature is **EXPERIMENTAL** with **limited support**. Use with caution. |
| 4 | +
|
| 5 | +By default AGIC assumes full ownership of the App Gateway it is linked to. AGIC version 0.8.0 and later allows |
| 6 | +retaining rules to allow adding VMSS as backend along with AKS cluster. |
| 7 | + |
| 8 | +Please __backup your App Gateway's configuration__ before enabling this setting: |
| 9 | + 1. using [Azure Portal](https://portal.azure.com/) navigate to your `App Gateway` instance |
| 10 | + 2. from `Export template` click `Download` |
| 11 | + |
| 12 | +The zip file you downloaded will have JSON templates, bash, and PowerShell scripts you could use to restore App Gateway |
| 13 | + |
| 14 | +## Example Scenario |
| 15 | +Let's look at an imaginary App Gateway, which manages traffic for 2 web sites: |
| 16 | + - `dev.contoso.com` - hosted on a new AKS, using App Gateway and AGIC |
| 17 | + - `prod.contoso.com` - hosted on an [Azure VMSS](https://azure.microsoft.com/en-us/services/virtual-machine-scale-sets/) |
| 18 | + |
| 19 | +With default settings, AGIC assumes 100% ownership of the App Gateway it is pointed to. AGIC overwrites all of App |
| 20 | +Gateway's configuration. If we were to manually create a listener for `prod.contoso.com` (on App Gateway), without |
| 21 | +defining it in the Kubernetes Ingress, AGIC will delete the `prod.contoso.com` config within seconds. |
| 22 | + |
| 23 | +To install AGIC and also serve `prod.contoso.com` from our VMSS machines, we must constrain AGIC to configuring |
| 24 | +`dev.contoso.com` only. This is facilitated by instantiating the following |
| 25 | +[CRD](https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/): |
| 26 | + |
| 27 | +```bash |
| 28 | +cat <<EOF | kubectl apply -f - |
| 29 | +apiVersion: "appgw.ingress.k8s.io/v1" |
| 30 | +kind: AzureIngressProhibitedTarget |
| 31 | +metadata: |
| 32 | + name: prod-contoso-com |
| 33 | +spec: |
| 34 | + hostname: prod.contoso.com |
| 35 | +EOF |
| 36 | +``` |
| 37 | + |
| 38 | +The command above creates an `AzureIngressProhibitedTarget` object. This makes AGIC (version 0.8.0 and later) aware of the existence of |
| 39 | +App Gateway config for `prod.contoso.com` and explicitly instructs it to avoid changing any configuration |
| 40 | +related to that hostname. |
| 41 | + |
| 42 | + |
| 43 | +## Enable with new AGIC installation |
| 44 | +To limit AGIC (version 0.8.0 and later) to a subset of the App Gateway configuration modify the `helm-config.yaml` template. |
| 45 | +Under the `appgw:` section, add `shared` key and set it to to `true`. |
| 46 | + |
| 47 | +```yaml |
| 48 | +appgw: |
| 49 | + subscriptionId: <subscriptionId> # existing field |
| 50 | + resourceGroup: <resourceGroupName> # existing field |
| 51 | + name: <applicationGatewayName> # existing field |
| 52 | + shared: true # <<<<< Add this field to enable shared App Gateway >>>>> |
| 53 | +``` |
| 54 | +
|
| 55 | +Apply the Helm changes: |
| 56 | + 1. Ensure the `AzureIngressProhibitedTarget` CRD is installed with: |
| 57 | + ```bash |
| 58 | + kubectl apply -f https://raw.githubusercontent.com/Azure/application-gateway-kubernetes-ingress/ae695ef9bd05c8b708cedf6ff545595d0b7022dc/crds/AzureIngressProhibitedTarget.yaml |
| 59 | + ``` |
| 60 | + 2. Update Helm: |
| 61 | + ```bash |
| 62 | + helm upgrade \ |
| 63 | + --recreate-pods \ |
| 64 | + -f helm-config.yaml \ |
| 65 | + ingress-azure application-gateway-kubernetes-ingress/ingress-azure |
| 66 | + ``` |
| 67 | + |
| 68 | +As a result your AKS will have a new instance of `AzureIngressProhibitedTarget` called `prohibit-all-targets`: |
| 69 | +```bash |
| 70 | +kubectl get AzureIngressProhibitedTargets prohibit-all-targets -o yaml |
| 71 | +``` |
| 72 | + |
| 73 | +The object `prohibit-all-targets`, as the name implies, prohibits AGIC from changing config for *any* host and path. |
| 74 | +Helm install with `appgw.shared=true` will deploy AGIC, but will not make any changes to App Gateway. |
| 75 | + |
| 76 | + |
| 77 | +## Broaden permissions |
| 78 | +Since Helm with `appgw.shared=true` and the default `prohibit-all-targets` blocks AGIC from applying any config. |
| 79 | + |
| 80 | +Broaden AGIC permissions with: |
| 81 | +1. Create a new `AzureIngressProhibitedTarget` with your specific setup: |
| 82 | + ```bash |
| 83 | + cat <<EOF | kubectl apply -f - |
| 84 | + apiVersion: "appgw.ingress.k8s.io/v1" |
| 85 | + kind: AzureIngressProhibitedTarget |
| 86 | + metadata: |
| 87 | + name: your-custom-prohibitions |
| 88 | + spec: |
| 89 | + hostname: your.own-hostname.com |
| 90 | + EOF |
| 91 | + ``` |
| 92 | +**NOTE:** To prohibit AGIC from making changes, in addition to *hostname*, a list of URL paths can also be configured as part of your prohibited policy, please refer to the [schema](https://github.com/Azure/application-gateway-kubernetes-ingress/blob/master/crds/AzureIngressProhibitedTarget-v1-CRD-v1.yaml) for details. |
| 93 | + |
| 94 | +2. Only after you have created your own custom prohibition, you can delete the default one, which is too broad: |
| 95 | + |
| 96 | + ```bash |
| 97 | + kubectl delete AzureIngressProhibitedTarget prohibit-all-targets |
| 98 | + ``` |
| 99 | + |
| 100 | +## Enable for an existing AGIC installation |
| 101 | +Let's assume that we already have a working AKS, App Gateway, and configured AGIC in our cluster. We have an Ingress for |
| 102 | +`prod.contosor.com` and are successfully serving traffic for it from AKS. We want to add `staging.contoso.com` to our |
| 103 | +existing App Gateway, but need to host it on a [VM](https://azure.microsoft.com/en-us/services/virtual-machines/). We |
| 104 | +are going to re-use the existing App Gateway and manually configure a listener and backend pools for |
| 105 | +`staging.contoso.com`. But manually tweaking App Gateway config (via |
| 106 | +[portal](https://portal.azure.com), [ARM APIs](https://docs.microsoft.com/en-us/rest/api/resources/) or |
| 107 | +[Terraform](https://www.terraform.io/)) would conflict with AGIC's assumptions of full ownership. Shortly after we apply |
| 108 | +changes, AGIC will overwrite or delete them. |
| 109 | + |
| 110 | +We can prohibit AGIC from making changes to a subset of configuration. |
| 111 | + |
| 112 | +1. Create an `AzureIngressProhibitedTarget` object: |
| 113 | + ```bash |
| 114 | + cat <<EOF | kubectl apply -f - |
| 115 | + apiVersion: "appgw.ingress.k8s.io/v1" |
| 116 | + kind: AzureIngressProhibitedTarget |
| 117 | + metadata: |
| 118 | + name: manually-configured-staging-environment |
| 119 | + spec: |
| 120 | + hostname: staging.contoso.com |
| 121 | + EOF |
| 122 | + ``` |
| 123 | + |
| 124 | +2. View the newly created object: |
| 125 | + ```bash |
| 126 | + kubectl get AzureIngressProhibitedTargets |
| 127 | + ``` |
| 128 | + |
| 129 | +3. Modify App Gateway config via portal - add listeners, routing rules, backends etc. The new object we created |
| 130 | +(`manually-configured-staging-environment`) will prohibit AGIC from overwriting App Gateway configuration related to |
| 131 | +`staging.contoso.com`. |
0 commit comments