새 Application Gateway를 사용하여 AGIC(Application Gateway 수신 컨트롤러)를 설치하는 방법

아래 지침에서는 AGIC(Application Gateway 수신 컨트롤러)가 기존 구성 요소가 없는 환경에 설치되어 있다고 가정합니다.

컨테이너용 Application Gateway란?도 참조 하세요.

필요한 명령줄 도구

아래의 모든 명령줄 작업에 Azure Cloud Shell을 사용하는 것이 좋습니다. shell.azure.com에 접속하거나 링크를 클릭하여 셸을 시작합니다.

또는 다음 아이콘을 사용하여 Azure Portal에서 Cloud Shell을 시작합니다.

Portal launch

Azure Cloud Shell에는 이미 필요한 도구가 모두 있습니다. 다른 환경을 사용하는 경우 다음 명령줄 도구가 설치되어 있는지 확인하세요.

ID 만들기

아래 단계를 수행하여 Microsoft Entra 서비스 주체 개체를 만듭니다. appId, passwordobjectId 값을 기록하세요. 이 값은 다음 단계에서 사용됩니다.

  1. AD 서비스 주체 만들기(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)
    

    JSON 출력의 appIdpassword 값은 다음 단계에서 사용됩니다.

  2. 이전 명령의 출력에서 appId를 사용하여 새 서비스 주체의 id를 가져옵니다.

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

    이 명령의 출력은 objectId이며, 아래 Azure Resource Manager 템플릿에서 사용됩니다.

  3. 나중에 Azure Resource Manager 템플릿 배포에 사용할 매개 변수 파일을 만듭니다.

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

    Kubernetes RBAC를 사용하는 클러스터를 배포하려면 aksEnableRBAC 필드를 true로 설정합니다.

구성 요소 배포

이 단계에서는 구독에 다음 구성 요소가 추가됩니다.

  1. Azure Resource Manager 템플릿을 다운로드하고 필요에 따라 템플릿을 수정합니다.

    wget https://raw.githubusercontent.com/Azure/application-gateway-kubernetes-ingress/master/deploy/azuredeploy.json -O template.json
    
  2. Azure CLI를 사용하여 Azure 리소스 관리자 템플릿 배포 배포에는 최대 5분이 소요될 수 있습니다.

    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. 배포가 완료되면 배포 출력을 deployment-outputs.json이라는 파일로 다운로드합니다.

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

Application Gateway 수신 컨트롤러 설정

이전 섹션의 지침을 사용하여 새 AKS 클러스터 및 Application Gateway를 만들고 구성했습니다. 이제 샘플 앱 및 수신 컨트롤러를 새로운 Kubernetes 인프라에 배포할 준비가 되었습니다.

Kubernetes 자격 증명 설정

다음 단계에서는 새 Kubernetes 클러스터에 연결하는 데 사용할 수 있는 kubectl 명령을 설정해야 합니다. Cloud Shell에는 이미 kubectl이 설치되어 있습니다. Kubernetes에 대한 자격 증명을 얻기 위해 az CLI를 사용합니다.

새로 배포된 AKS에 대한 자격 증명을 가져옵니다(자세히 알아보기).

# 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 ID 설치

Microsoft Entra Pod ID는 ARM(Azure Resource Manager)에 대한 토큰 기반 액세스를 제공합니다.

Microsoft Entra Pod ID는 Kubernetes 클러스터에 다음 구성 요소를 추가합니다.

Microsoft Entra Pod ID를 클러스터에 설치하려면 다음을 수행합니다.

  • Kubernetes RBAC를 사용하는 AKS 클러스터

    kubectl create -f https://raw.githubusercontent.com/Azure/aad-pod-identity/master/deploy/infra/deployment-rbac.yaml
    
  • Kubernetes RBAC를 사용하지 않는 AKS 클러스터

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

Helm 설치

Helm은 Kubernetes 패키지 관리자입니다. 이를 사용하여 application-gateway-kubernetes-ingress 패키지를 설치합니다.

참고 항목

Cloud Shell을 사용하는 경우에는 Helm을 설치할 필요가 없습니다. Azure Cloud Shell은 Helm 버전 3과 함께 제공됩니다. 첫 번째 단계를 건너뛰고 AGIC Helm 리포지토리만 추가합니다.

  1. Helm을 설치하고 다음을 실행하여 application-gateway-kubernetes-ingress Helm 패키지를 추가합니다.

    • Kubernetes RBAC를 사용하는 AKS 클러스터

      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를 사용하지 않는 AKS 클러스터

      helm init
      
  2. AGIC 리포지토리를 추가합니다.

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

수신 컨트롤러 Helm 차트 설치

  1. 위에서 만든 deployment-outputs.json 파일을 사용하고 다음 변수를 만듭니다.

    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를 구성하는 helm-config.xml을 다운로드합니다.

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

    또는 아래에서 YAML 파일을 복사합니다.

    # 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. 새로 다운로드한 helm-config.xml을 편집하고 섹션 appgwarmAuth를 작성합니다.

    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
    

    참고 항목

    소버린 클라우드(예: Azure Government)에 배포하려면appgw.environment 구성 매개 변수를 추가하고 아래 설명된 대로 적절한 값으로 설정해야 합니다.

    값:

    • verbosityLevel: AGIC 로깅 인프라의 세부 정보 표시 수준을 설정합니다. 가능한 값은 로깅 수준을 참조하세요.
    • appgw.environment: 클라우드 환경을 설정합니다. 가능한 값: AZURECHINACLOUD, AZUREGERMANCLOUD, AZUREPUBLICCLOUD, AZUREUSGOVERNMENTCLOUD
    • appgw.subscriptionId: Application Gateway가 있는 Azure 구독 ID입니다. 예: a123b234-a3b4-557d-b2df-a0bc12de1234
    • appgw.resourceGroup: Application Gateway가 만들어진 Azure Resource Group의 이름입니다. 예: app-gw-resource-group
    • appgw.name: Application Gateway의 이름입니다. 예: applicationgatewayd0f0
    • appgw.shared: 이 부울 플래그는 기본적으로 false로 설정되어야 합니다. 공유 Application Gateway가 필요하면 true로 설정합니다.
    • kubernetes.watchNamespace: AGIC에서 확인해야 하는 네임스페이스를 지정합니다. 네임스페이스 값은 단일 문자열 값 또는 쉼표로 구분된 네임스페이스 목록일 수 있습니다.
    • armAuth.type: aadPodIdentity 또는 servicePrincipal일 수 있습니다.
    • armAuth.identityResourceID: Azure 관리 ID의 리소스 ID입니다.
    • armAuth.identityClientID: ID의 클라이언트 ID입니다. identityClientID에 대한 자세한 내용은 아래에 나와 있습니다.
    • armAuth.secretJSON: 서비스 주체 비밀 유형을 선택한 경우(armAuth.typeservicePrincipal로 설정한 경우)에만 필요합니다.

    참고 항목

    identityResourceIDidentityClientID구성 요소 배포 단계 중에 만들어진 값으로, 다음 명령을 사용하여 다시 가져올 수 있습니다.

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

    위의 명령의 <resource-group>에는 Application Gateway의 리소스 그룹이 있습니다. <identity-name>은 만들어진 ID의 이름입니다. 지정된 구독에 대한 모든 ID는 az identity list를 사용하여 나열할 수 있습니다.

  4. Application Gateway 수신 컨트롤러 패키지 설치

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

샘플 앱 설치

Application Gateway, AKS 및 AGIC가 설치되면 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

또는 다음을 수행할 수 있습니다.

  • 위의 YAML 파일을 다운로드합니다.

    curl https://raw.githubusercontent.com/Azure/application-gateway-kubernetes-ingress/master/docs/examples/aspnetapp.yaml -o aspnetapp.yaml
    
  • YAML 파일을 적용합니다.

    kubectl apply -f aspnetapp.yaml
    

기타 예

방법 가이드에는 HTTP 또는 HTTPS를 통해 AKS 서비스를 Application Gateway 인터넷에 공개하는 방법에 대한 더 많은 예가 포함되어 있습니다.