The instructions below assume Application Gateway Ingress Controller (AGIC) will be installed in an environment with no pre-existing components.
We recommend the use of Azure Cloud Shell for all command line operations below. Launch your shell from shell.azure.com or by clicking the link:
Alternatively, launch Cloud Shell from Azure portal using the following icon:
Your Azure Cloud Shell already has all necessary tools. Should you choose to use another environment, please ensure the following command line tools are installed:
az
- Azure CLI: installation instructionskubectl
- Kubernetes command-line tool: installation instructionshelm
- Kubernetes package manager: installation instructions
Follow the steps below to create an Azure Active Directory (AAD) service principal object. Please record the appId
, password
, and objectId
values - these will be used in the following steps.
-
Create AD service principal (Read more about RBAC):
az ad sp create-for-rbac --skip-assignment
note: the
appId
andpassword
values from the JSON output will be used in the following steps -
Use the
appId
from the previous command's output to get theobjectId
of the newl service principal:az ad sp show --id <appId> --query "objectId"
note: the output of this command is
objectId
, which will be used in the ARM template below
Click on the Deploy to Azure icon below to begin the infrastructure deployment using an ARM template. This step will add the following components to your subscription:
- Azure Kubernetes Service
- Application Gateway v2
- Virtual Network with 2 subnets
- Public IP Address
- Managed Identity, which will be used by AAD Pod Identity
Please use the appId
, objectId
, and password
values from the az
commands above and
paste them in the corresponding ARM template fields:
- paste the
appId
vaule in theAks Service Principal App Id
template field - paste the
password
value in theAks Service Principal Client Secret
field - paste the
objectId
value in theAks Service Principal Object Id
field
Note: To deploy an RBAC enabled cluster, set the aksEnabledRBAC
field to true
Navigate to the deployment output and record the parameters:
Azure portal: Home -> *resource group* -> Deployments -> *new deployment* -> Outputs
)
With the instructions in the previous section we created and configured a new AKS cluster and an App Gateway. We are now ready to deploy an sample app and an ingress controller to our new Kubernetes infrastructure.
For the following steps we need setup kubectl command,
which we will use to connect to our new Kubernetes cluster. Cloud Shell has kubectl
already installed. We will use az
CLI to obtain credentials for Kubernetes.
Get credentials for your newly deployed AKS (read more):
bash az aks get-credentials --resource-group <your-new-resource-group> --name <name-of-new-AKS-cluster>
Azure Active Directory Pod Identity provides token-based access to Azure Resource Manager (ARM).
AAD Pod Identity will add the following components to your Kubernetes cluster:
- Kubernetes CRDs:
AzureIdentity
,AzureAssignedIdentity
,AzureIdentityBinding
- Managed Identity Controller (MIC) component
- Node Managed Identity (NMI) component
To install AAD Pod Identity to your cluster:
- *RBAC enabled* AKS cluster
```bash
kubectl create -f https://raw.githubusercontent.com/Azure/aad-pod-identity/master/deploy/infra/deployment-rbac.yaml
```
- *RBAC disabled* AKS cluster
```bash
kubectl create -f https://raw.githubusercontent.com/Azure/aad-pod-identity/master/deploy/infra/deployment.yaml
```
Helm is a package manager for
Kubernetes. We will leverage it to install the application-gateway-kubernetes-ingress
package:
-
Install Helm and run the following to add
application-gateway-kubernetes-ingress
helm package:- RBAC enabled AKS cluster
kubectl create serviceaccount --namespace kube-system tiller-sa kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller-sa helm init --tiller-namespace kube-system --service-account tiller-sa
- RBAC disabled AKS cluster
helm init
-
Add the AGIC Helm repository:
helm repo add application-gateway-kubernetes-ingress https://appgwingress.blob.core.windows.net/ingress-azure-helm-package/ helm repo update
-
Download helm-config.yaml, which will configure AGIC:
wget https://raw.githubusercontent.com/Azure/application-gateway-kubernetes-ingress/master/docs/examples/sample-helm-config.yaml -O helm-config.yaml
-
Edit helm-config.yaml and fill in the values for
appgw
andarmAuth
.nano helm-config.yaml
NOTE: The
<identity-resource-id>
and<identity-client-id>
are the properties of the Azure AD Identity you setup in the previous section. You can retrieve this information by running the following command:az identity show -g <resourcegroup> -n <identity-name>
, where<resourcegroup>
is the resource group in which the top level AKS cluster object, Application Gateway and Managed Identify are deployed. -
Install the Application Gateway ingress controller package:
helm install -f helm-config.yaml application-gateway-kubernetes-ingress/ingress-azure
Now that we have App Gateway, AKS, and AGIC installed we can install a sample app via Azure Cloud Shell:
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
name: aspnetapp
labels:
app: aspnetapp
spec:
containers:
- image: "mcr.microsoft.com/dotnet/core/samples:aspnetapp"
name: aspnetapp-image
ports:
- containerPort: 80
protocol: TCP
---
apiVersion: v1
kind: Service
metadata:
name: aspnetapp
spec:
selector:
app: aspnetapp
ports:
- protocol: TCP
port: 80
targetPort: 80
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: aspnetapp
annotations:
kubernetes.io/ingress.class: azure/application-gateway
spec:
rules:
- http:
paths:
- path: /
backend:
serviceName: aspnetapp
servicePort: 80
EOF
Alternatively you can:
- Download the YAML file above:
curl https://raw.githubusercontent.com/Azure/application-gateway-kubernetes-ingress/master/docs/examples/aspnetapp.yaml -o aspnetapp.yaml
- Apply the YAML file:
kubectl apply -f apsnetapp.yaml
The tutorials document contains more examples on how toexpose an AKS service via HTTP or HTTPS, to the Internet with App Gateway.