Yeni Application Gateway Kullanarak Application Gateway Giriş Denetleyicisi (AGIC) Yükleme

Aşağıdaki yönergelerde Application Gateway Giriş Denetleyicisi'nin (AGIC) önceden var olan bileşenler içermeyen bir ortama yükleneceği varsayılır.

İpucu

Ayrıca bkz. Kapsayıcılar için Application Gateway nedir?

Gerekli Komut Satırı Araçları

Aşağıdaki tüm komut satırı işlemleri için Azure Cloud Shell kullanılmasını öneririz. kabuğunuzu shell.azure.com veya bağlantıya tıklayarak başlatın:

Alternatif olarak, aşağıdaki simgeyi kullanarak Azure portalından Cloud Shell'i başlatın:

Portal launch

Azure Cloud Shell'inizde zaten tüm gerekli araçlar vardır. Başka bir ortam kullanmayı seçerseniz aşağıdaki komut satırı araçlarının yüklendiğinden emin olun:

Kimlik Oluşturma

Microsoft Entra hizmet sorumlusu nesnesi oluşturmak için aşağıdaki adımları izleyin. appId, passwordve objectId değerlerini kaydedin. Bu değerler aşağıdaki adımlarda kullanılır.

  1. AD hizmet sorumlusu oluşturma (Azure RBAC hakkında daha fazla bilgi edinin):

    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)
    

    appId Aşağıdaki adımlarda JSON çıkışından ve password değerleri kullanılacaktır

  2. appId Yeni hizmet sorumlusunun değerini almak için önceki komutun id çıktısından öğesini kullanın:

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

    Bu komutun çıktısı aşağıdaki Azure Resource Manager şablonunda kullanılacak olan komutudur objectId.

  3. Daha sonra Azure Resource Manager şablon dağıtımında kullanılacak parametre dosyasını oluşturun.

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

    Kubernetes RBAC özellikli bir kümeyi dağıtmak için alanı olarak ayarlayın aksEnableRBACtrue

Bileşenleri Dağıtma

Bu adım, aboneliğinize aşağıdaki bileşenleri ekler:

  1. Azure Resource Manager şablonunu indirin ve şablonu gerektiği gibi değiştirin.

    wget https://raw.githubusercontent.com/Azure/application-gateway-kubernetes-ingress/master/deploy/azuredeploy.json -O template.json
    
  2. Azure CLI kullanarak Azure Resource Manager şablonunu dağıtın. Dağıtım 5 dakika kadar sürebilir.

    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. Dağıtım tamamlandıktan sonra dağıtım çıkışını adlı deployment-outputs.jsonbir dosyaya indirin.

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

Application Gateway Giriş Denetleyicisi'ni ayarlama

Önceki bölümdeki yönergelerle yeni bir AKS kümesi ve application gateway oluşturup yapılandırdık. Artık yeni Kubernetes altyapımıza örnek bir uygulama ve giriş denetleyicisi dağıtmaya hazırız.

Kubernetes Kimlik Bilgilerini ayarlama

Aşağıdaki adımlar için, yeni Kubernetes kümemize bağlanmak için kullanacağımız kubectl komutunu ayarlamamız gerekir. Cloud Shellkubectl zaten yüklü. Cli kullanarak Kubernetes kimlik bilgilerini alacağız az .

Yeni dağıtılan AKS'niz için kimlik bilgilerini alın (daha fazla bilgi edinin):

# 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 Kimliğini Yükleme

Microsoft Entra Pod Identity, Azure Resource Manager'a (ARM) belirteç tabanlı erişim sağlar.

Microsoft Entra Pod Identity , Kubernetes kümenize aşağıdaki bileşenleri ekler:

Microsoft Entra Pod Identity'i kümenize yüklemek için:

  • Kubernetes RBAC özellikli AKS kümesi

    kubectl create -f https://raw.githubusercontent.com/Azure/aad-pod-identity/master/deploy/infra/deployment-rbac.yaml
    
  • Kubernetes RBAC devre dışı AKS kümesi

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

Helm'i yükleme

Helm , Kubernetes için bir paket yöneticisidir. Paketi yüklemek application-gateway-kubernetes-ingress için kullanacağız.

Not

Cloud Shell kullanıyorsanız Helm'i yüklemeniz gerekmez. Azure Cloud Shell Helm sürüm 3 ile birlikte gelir. İlk adımı atlayın ve AGIC Helm deposunu ekleyin.

  1. Helm'i yükleyin ve helm paketi eklemek application-gateway-kubernetes-ingress için aşağıdakileri çalıştırın:

    • Kubernetes RBAC özellikli AKS kümesi

      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 devre dışı AKS kümesi

      helm init
      
  2. AGIC Helm deposunu ekleyin:

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

Giriş Denetleyicisi Helm Grafiğini Yükleme

  1. deployment-outputs.json Yukarıda oluşturulan dosyayı kullanın ve aşağıdaki değişkenleri oluşturun.

    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. AGIC'i yapılandıracak helm-config.yaml dosyasını indirin:

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

    Ya da aşağıdaki YAML dosyasını kopyalayın:

    # 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. Yeni indirilen helm-config.yaml dosyasını düzenleyin ve ve armAuthbölümlerini appgw doldurun.

    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
    

    Not

    Bağımsız Bulutlara (örneğin, Azure Kamu) dağıtmak için yapılandırma parametresinin appgw.environment eklenmesi ve aşağıda açıklandığı gibi uygun değere ayarlanması gerekir.

    Değerler:

    • verbosityLevel: AGIC günlük altyapısının ayrıntı düzeyini ayarlar. Olası değerler için bkz . Günlük Düzeyleri .
    • appgw.environment: Bulut ortamını ayarlar. Olası değerler: AZURECHINACLOUD, AZUREGERMANCLOUD, AZUREPUBLICCLOUD, AZUREUSGOVERNMENTCLOUD
    • appgw.subscriptionId: Application Gateway'in bulunduğu Azure Abonelik Kimliği. Örnek: a123b234-a3b4-557d-b2df-a0bc12de1234
    • appgw.resourceGroup: Application Gateway'in oluşturulduğu Azure Kaynak Grubunun adı. Örnek: app-gw-resource-group
    • appgw.name: Application Gateway'in adı. Örnek: applicationgatewayd0f0
    • appgw.shared: Bu boole bayrağı varsayılan olarak falseayarlanmalıdır. Paylaşılan Application Gateway'e ihtiyacınız varsa olarak true ayarlayın.
    • kubernetes.watchNamespace: AGIC'in izlemesi gereken ad alanını belirtin. Ad alanı değeri tek bir dize değeri veya virgülle ayrılmış ad alanları listesi olabilir.
    • armAuth.type: veya olabilir aadPodIdentityservicePrincipal
    • armAuth.identityResourceID: Azure Yönetilen Kimliğinin Kaynak Kimliği
    • armAuth.identityClientID: Kimliğin İstemci Kimliği. identityClientID hakkında daha fazla bilgi aşağıda verilmiştir.
    • armAuth.secretJSON: Yalnızca Hizmet Sorumlusu Gizli Anahtarı türü seçildiğinde gerekir ( armAuth.type olarak ayarlandığında servicePrincipal)

    Not

    identityResourceID veidentityClientID, Bileşenleri Dağıtma adımları sırasında oluşturulan değerlerdir ve aşağıdaki komut kullanılarak yeniden elde edilebilir:

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

    <resource-group> yukarıdaki komutta Application Gateway'inizin kaynak grubu yer alır. <identity-name> , oluşturulan kimliğin adıdır. Belirli bir abonelik için tüm kimlikler şu şekilde listelenebilir: az identity list

  4. Application Gateway giriş denetleyicisi paketini yükleyin:

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

Örnek Uygulama Yükleme

Application Gateway, AKS ve AGIC'yi yüklediğimize göre Azure Cloud Shell aracılığıyla örnek bir uygulama yükleyebiliriz:

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

Alternatif olarak:

  • Yukarıdaki YAML dosyasını indirin:

    curl https://raw.githubusercontent.com/Azure/application-gateway-kubernetes-ingress/master/docs/examples/aspnetapp.yaml -o aspnetapp.yaml
    
  • YAML dosyasını uygulayın:

    kubectl apply -f aspnetapp.yaml
    

Diğer Örnekler

Bu nasıl yapılır kılavuzu , APPLICATION Gateway ile HTTP veya HTTPS aracılığıyla bir AKS hizmetini İnternet'te kullanıma sunma hakkında daha fazla örnek içerir.