Delen via


Een application gateway-ingangscontroller (AGIC) installeren met behulp van een nieuwe toepassingsgateway

In de onderstaande instructies wordt ervan uitgegaan dat AGIC (Application Gateway Ingress Controller) wordt geïnstalleerd in een omgeving zonder bestaande onderdelen.

Vereiste opdrachtregelprogramma's

We raden het gebruik van Azure Cloud Shell aan voor alle onderstaande opdrachtregelbewerkingen. Start de shell vanuit shell.azure.com of klik op de koppeling:

U kunt Cloud Shell ook starten vanuit Azure Portal met behulp van het volgende pictogram:

Portal launch

Uw Azure Cloud Shell beschikt al over alle benodigde hulpprogramma's. Als u ervoor kiest om een andere omgeving te gebruiken, controleert u of de volgende opdrachtregelprogramma's zijn geïnstalleerd:

Een identiteit maken

Volg de onderstaande stappen om een Microsoft Entra-service-principalobject te maken. Noteer de appId, passworden objectId waarden - deze waarden worden gebruikt in de volgende stappen.

  1. Ad-service-principal maken (meer informatie over Azure RBAC):

    az ad sp create-for-rbac --role Contributor --scopes /subscriptions/mySubscriptionID -o json > auth.json
    appId=$(jq -r ".appId" auth.json)
    password=$(jq -r ".password" auth.json)
    

    De appId en password waarden uit de JSON-uitvoer worden gebruikt in de volgende stappen

  2. Gebruik de appId uitvoer van de vorige opdracht om de id nieuwe service-principal op te halen:

    objectId=$(az ad sp show --id $appId --query "id" -o tsv)
    

    De uitvoer van deze opdracht is objectId, die wordt gebruikt in de Onderstaande Azure Resource Manager-sjabloon

  3. Maak het parameterbestand dat later wordt gebruikt in de azure Resource Manager-sjabloonimplementatie.

    cat <<EOF > parameters.json
    {
      "aksServicePrincipalAppId": { "value": "$appId" },
      "aksServicePrincipalClientSecret": { "value": "$password" },
      "aksServicePrincipalObjectId": { "value": "$objectId" },
      "aksEnableRBAC": { "value": false }
    }
    EOF
    

    Als u een Kubernetes RBAC-cluster wilt implementeren, stelt u het aksEnableRBAC veld in op true

Onderdelen implementeren

Met deze stap worden de volgende onderdelen aan uw abonnement toegevoegd:

  1. Download de Azure Resource Manager-sjabloon en pas de sjabloon zo nodig aan.

    wget https://raw.githubusercontent.com/Azure/application-gateway-kubernetes-ingress/master/deploy/azuredeploy.json -O template.json
    
  2. Implementeer de Azure Resource Manager-sjabloon met behulp van de Azure CLI. De implementatie kan maximaal 5 minuten duren.

    resourceGroupName="MyResourceGroup"
    location="westus2"
    deploymentName="ingress-appgw"
    
    # create a resource group
    az group create -n $resourceGroupName -l $location
    
    # modify the template as needed
    az deployment group create \
            -g $resourceGroupName \
            -n $deploymentName \
            --template-file template.json \
            --parameters parameters.json
    
  3. Zodra de implementatie is voltooid, downloadt u de uitvoer van de implementatie naar een bestand met de naam deployment-outputs.json.

    az deployment group show -g $resourceGroupName -n $deploymentName --query "properties.outputs" -o json > deployment-outputs.json
    

Controller voor inkomend verkeer van Application Gateway instellen

Met de instructies in de vorige sectie hebben we een nieuw AKS-cluster en een Application Gateway gemaakt en geconfigureerd. We zijn nu klaar om een voorbeeld-app en een ingangscontroller te implementeren in onze nieuwe Kubernetes-infrastructuur.

Kubernetes-referenties instellen

Voor de volgende stappen moeten we de kubectl-opdracht instellen, die we gaan gebruiken om verbinding te maken met ons nieuwe Kubernetes-cluster. Cloud Shell is kubectl al geïnstalleerd. We gebruiken az CLI om referenties voor Kubernetes te verkrijgen.

Referenties ophalen voor uw zojuist geïmplementeerde AKS (lees meer):

# use the deployment-outputs.json created after deployment to get the cluster name and resource group name
aksClusterName=$(jq -r ".aksClusterName.value" deployment-outputs.json)
resourceGroupName=$(jq -r ".resourceGroupName.value" deployment-outputs.json)

az aks get-credentials --resource-group $resourceGroupName --name $aksClusterName

Microsoft Entra Pod Identity installeren

Microsoft Entra Pod Identity biedt toegang op basis van tokens tot Azure Resource Manager (ARM).

Microsoft Entra Pod Identity voegt de volgende onderdelen toe aan uw Kubernetes-cluster:

Microsoft Entra Pod Identity installeren in uw cluster:

  • AKS-cluster met Kubernetes RBAC ingeschakeld

    kubectl create -f https://raw.githubusercontent.com/Azure/aad-pod-identity/master/deploy/infra/deployment-rbac.yaml
    
  • Kubernetes RBAC uitgeschakeld AKS-cluster

    kubectl create -f https://raw.githubusercontent.com/Azure/aad-pod-identity/master/deploy/infra/deployment.yaml
    

Helm installeren

Helm is een pakketbeheerder voor Kubernetes. We gebruiken het om het application-gateway-kubernetes-ingress pakket te installeren.

Notitie

Als u Cloud Shell gebruikt, hoeft u Helm niet te installeren. Azure Cloud Shell wordt geleverd met Helm versie 3. Sla de eerste stap over en voeg gewoon de AGIC Helm-opslagplaats toe.

  1. Installeer Helm en voer het volgende uit om het Helm-pakket toe te voegen application-gateway-kubernetes-ingress :

    • AKS-cluster met Kubernetes RBAC ingeschakeld

      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
      
    • Kubernetes RBAC uitgeschakeld AKS-cluster

      helm init
      
  2. Voeg de AGIC Helm-opslagplaats toe:

    helm repo add application-gateway-kubernetes-ingress https://appgwingress.blob.core.windows.net/ingress-azure-helm-package/
    helm repo update
    

Helm-grafiek voor inkomend verkeer installeren

  1. Gebruik het deployment-outputs.json bovenstaande bestand en maak de volgende variabelen.

    applicationGatewayName=$(jq -r ".applicationGatewayName.value" deployment-outputs.json)
    resourceGroupName=$(jq -r ".resourceGroupName.value" deployment-outputs.json)
    subscriptionId=$(jq -r ".subscriptionId.value" deployment-outputs.json)
    identityClientId=$(jq -r ".identityClientId.value" deployment-outputs.json)
    identityResourceId=$(jq -r ".identityResourceId.value" deployment-outputs.json)
    
  2. Download helm-config.yaml, waarmee AGIC wordt geconfigureerd:

    wget https://raw.githubusercontent.com/Azure/application-gateway-kubernetes-ingress/master/docs/examples/sample-helm-config.yaml -O helm-config.yaml
    

    Of kopieer het YAML-bestand hieronder:

    # This file contains the essential configs for the ingress controller helm chart
    
    # Verbosity level of the App Gateway Ingress Controller
    verbosityLevel: 3
    
    ################################################################################
    # Specify which application gateway the ingress controller will manage
    #
    appgw:
        subscriptionId: <subscriptionId>
        resourceGroup: <resourceGroupName>
        name: <applicationGatewayName>
    
        # Setting appgw.shared to "true" will create an AzureIngressProhibitedTarget CRD.
        # This prohibits AGIC from applying config for any host/path.
        # Use "kubectl get AzureIngressProhibitedTargets" to view and change this.
        shared: false
    
    ################################################################################
    # Specify which kubernetes namespace the ingress controller will watch
    # Default value is "default"
    # Leaving this variable out or setting it to blank or empty string would
    # result in Ingress Controller observing all acessible namespaces.
    #
    # kubernetes:
    #   watchNamespace: <namespace>
    
    ################################################################################
    # Specify the authentication with Azure Resource Manager
    #
    # Two authentication methods are available:
    # - Option 1: AAD-Pod-Identity (https://github.com/Azure/aad-pod-identity)
    armAuth:
        type: aadPodIdentity
        identityResourceID: <identityResourceId>
        identityClientID:  <identityClientId>
    
    ## Alternatively you can use Service Principal credentials
    # armAuth:
    #    type: servicePrincipal
    #    secretJSON: <<Generate this value with: "az ad sp create-for-rbac --subscription <subscription-uuid> --role Contributor --sdk-auth | base64 -w0" >>
    
    ################################################################################
    # Specify if the cluster is Kubernetes RBAC enabled or not
    rbac:
        enabled: false # true/false
    
    # Specify aks cluster related information. THIS IS BEING DEPRECATED.
    aksClusterConfiguration:
        apiServerAddress: <aks-api-server-address>
    
  3. Bewerk de zojuist gedownloade helm-config.yaml en vul de secties appgw en armAuthin.

    sed -i "s|<subscriptionId>|${subscriptionId}|g" helm-config.yaml
    sed -i "s|<resourceGroupName>|${resourceGroupName}|g" helm-config.yaml
    sed -i "s|<applicationGatewayName>|${applicationGatewayName}|g" helm-config.yaml
    sed -i "s|<identityResourceId>|${identityResourceId}|g" helm-config.yaml
    sed -i "s|<identityClientId>|${identityClientId}|g" helm-config.yaml
    

    Notitie

    Voor implementatie naar onafhankelijke clouds (bijvoorbeeld Azure Government) moet de appgw.environment configuratieparameter worden toegevoegd en ingesteld op de juiste waarde, zoals hieronder wordt beschreven.

    Waarden:

    • verbosityLevel: Hiermee stelt u het uitgebreidheidsniveau van de AGIC-logboekregistratie-infrastructuur in. Zie Logboekregistratieniveaus voor mogelijke waarden.
    • appgw.environment: Stelt de cloudomgeving in. Mogelijke waarden: AZURECHINACLOUD, AZUREGERMANCLOUD, AZUREPUBLICCLOUD, AZUREUSGOVERNMENTCLOUD
    • appgw.subscriptionId: de Azure-abonnements-id waarin Application Gateway zich bevindt. Voorbeeld: a123b234-a3b4-557d-b2df-a0bc12de1234
    • appgw.resourceGroup: Naam van de Azure-resourcegroep waarin Application Gateway is gemaakt. Voorbeeld: app-gw-resource-group
    • appgw.name: Naam van de Application Gateway. Voorbeeld: applicationgatewayd0f0
    • appgw.shared: Deze Booleaanse vlag moet standaard worden ingesteld op false. Ingesteld op true het geval u een gedeelde toepassingsgateway nodig hebt.
    • kubernetes.watchNamespace: Geef de naamruimte op die AGIC moet bekijken. De naamruimtewaarde kan één tekenreekswaarde of een door komma's gescheiden lijst met naamruimten zijn.
    • armAuth.type: kan of aadPodIdentityservicePrincipal
    • armAuth.identityResourceID: Resource-id van de Azure Managed Identity
    • armAuth.identityClientID: De client-id van de identiteit. Hieronder vindt u meer informatie over identityClientID .
    • armAuth.secretJSON: Alleen nodig wanneer het type service-principalgeheim is gekozen (wanneer armAuth.type dit is ingesteld op servicePrincipal)

    Notitie

    De identityResourceID waarden die identityClientID zijn gemaakt tijdens de stappen Onderdelen implementeren en kunnen opnieuw worden verkregen met behulp van de volgende opdracht:

    az identity show -g <resource-group> -n <identity-name>
    

    <resource-group> in de bovenstaande opdracht is de resourcegroep van uw Application Gateway. <identity-name> is de naam van de gemaakte identiteit. Alle identiteiten voor een bepaald abonnement kunnen worden weergegeven met: az identity list

  4. Installeer het controllerpakket voor inkomend verkeer van Application Gateway:

    helm install -f helm-config.yaml --generate-name application-gateway-kubernetes-ingress/ingress-azure
    

Een voorbeeld-app installeren

Nu Application Gateway, AKS en AGIC zijn geïnstalleerd, kunnen we een voorbeeld-app installeren 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/samples:aspnetapp"
    name: aspnetapp-image
    ports:
    - containerPort: 8080
      protocol: TCP

---

apiVersion: v1
kind: Service
metadata:
  name: aspnetapp
spec:
  selector:
    app: aspnetapp
  ports:
  - protocol: TCP
    port: 80
    targetPort: 8080

---

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: aspnetapp
  annotations:
    kubernetes.io/ingress.class: azure/application-gateway
spec:
  rules:
  - http:
      paths:
      - path: /
        pathType: Exact
        backend:
          service:
            name: aspnetapp
            port:
              number: 80
        pathType: Exact
EOF

U kunt ook het volgende doen:

  • Download het YAML-bestand hierboven:

    curl https://raw.githubusercontent.com/Azure/application-gateway-kubernetes-ingress/master/docs/examples/aspnetapp.yaml -o aspnetapp.yaml
    
  • Pas het YAML-bestand toe:

    kubectl apply -f aspnetapp.yaml
    

Andere voorbeelden

Deze handleiding bevat meer voorbeelden over het beschikbaar maken van een AKS-service via HTTP of HTTPS op internet met Application Gateway.