新しい Application Gateway を使用して Application Gateway イングレス コントローラー (AGIC) をインストールする方法
以下の手順は、既存のコンポーネントが存在しない環境に Application Gateway イングレス コントローラー (AGIC) をインストールすることを前提としています。
ヒント
また、「Application Gateway for Containers とは」も参照してください。
必須のコマンド ライン ツール
次のすべてのコマンドライン操作に対して Azure Cloud Shell を使用することをお勧めします。 shell.azure.com から、または次のリンクをクリックして、シェルを起動します。
または、次のアイコンを使用して Azure portal から Cloud Shell を起動します。
Azure Cloud Shell には、必要なすべてのツールが既に含まれています。 別の環境を使用する場合は、次のコマンドライン ツールがインストールされていることを確認してください。
az
- Azure CLI: インストール手順kubectl
- Kubernetes コマンド ライン ツール: インストール手順helm
- Kubernetes パッケージ マネージャー: インストール手順jq
- コマンド ライン JSON プロセッサ: インストール手順
ID を作成する
Microsoft Entra サービス プリンシパル オブジェクトを作成するには、次の手順に従います。 appId
、password
、objectId
の値を記録してください。これらの値は次の手順で使用します。
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 出力の
appId
とpassword
の値は、次の手順で使用します。前のコマンドの出力の
appId
を使用して、新しいサービス プリンシパルのid
を取得します。objectId=$(az ad sp show --id $appId --query "id" -o tsv)
このコマンドの出力は
objectId
です。これは、以下の Azure Resource Manager テンプレートで使用されます後で Azure Resource Manager テンプレートのデプロイで使用されるパラメーター ファイルを作成します。
cat <<EOF > parameters.json { "aksServicePrincipalAppId": { "value": "$appId" }, "aksServicePrincipalClientSecret": { "value": "$password" }, "aksServicePrincipalObjectId": { "value": "$objectId" }, "aksEnableRBAC": { "value": false } } EOF
Kubernetes RBAC が有効のクラスターをデプロイするには、
aksEnableRBAC
フィールドをtrue
に設定します
コンポーネントをデプロイする
この手順では、サブスクリプションに次のコンポーネントを追加します。
- Azure Kubernetes Service
- Application Gateway v2
- 2 つのサブネットのある仮想ネットワーク
- パブリック IP アドレス
- Microsoft Entra ポッド ID で使用されるマネージド ID
Azure Resource Manager テンプレートをダウンロードし、必要に応じてそのテンプレートを変更します。
wget https://raw.githubusercontent.com/Azure/application-gateway-kubernetes-ingress/master/deploy/azuredeploy.json -O template.json
Azure CLI を使用して Azure Resource Manager テンプレートをデプロイします。 展開には、最大 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
デプロイが完了したら、
deployment-outputs.json
という名前のファイルにデプロイ出力をダウンロードします。az deployment group show -g $resourceGroupName -n $deploymentName --query "properties.outputs" -o json > deployment-outputs.json
Azure Application Gateway イングレス コントローラーを設定する
前のセクションの手順に従って、新しい AKS クラスターと Application Gateway を作成し、構成しました。 これで、新しい Kubernetes インフラストラクチャにサンプル アプリとイングレス コントローラーをデプロイする準備ができました。
Kubernetes 資格情報を設定する
次の手順では、新しい Kubernetes クラスターへの接続に使用する kubectl コマンドを設定する必要があります。 Cloud Shell には kubectl
が既にインストールされています。 az
CLI を使用して、Kubernetes の資格情報を取得します。
新しくデプロイされた 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 ポッド ID をインストールする
Microsoft Entra ポッド ID は、Azure Resource Manager (ARM) へのトークンベースのアクセスを提供します。
Microsoft Entra ポッド ID によって、次のコンポーネントが Kubernetes クラスターに追加されます。
- Kubernetes CRD:
AzureIdentity
、AzureAssignedIdentity
、AzureIdentityBinding
- Managed Identity Controller (MIC) コンポーネント
- Node Managed Identity (NMI) コンポーネント
Microsoft Entra ポッド 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
パッケージをインストールします。
Note
Cloud Shell を使用する場合は、Helm をインストールする必要はありません。 Azure Cloud Shell には Helm バージョン 3 が付属しています。 最初のステップをスキップして、AGIC Helm リポジトリを追加するだけです。
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
AGIC Helm リポジトリを追加します。
helm repo add application-gateway-kubernetes-ingress https://appgwingress.blob.core.windows.net/ingress-azure-helm-package/ helm repo update
イングレス コントローラーの Helm Chart をインストールする
上記で作成した
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)
AGIC の構成を行う helm-config.yaml をダウンロードします。
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>
新しくダウンロードした helm-config.yaml を編集し、
appgw
とarmAuth
のセクションに入力します。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
Note
ソブリン クラウド (例: 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 リソース グループの名前。 例: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 のリソース IDarmAuth.identityClientID
: ID のクライアント ID。 以下に、identityClientID の詳細を示します。armAuth.secretJSON
: サービス プリンシパル シークレットの種類を選択した場合 (armAuth.type
がservicePrincipal
に設定されている場合) にのみ必要です
Note
identityResourceID
とidentityClientID
は、「コンポーネントのデプロイ」手順で作成された値であり、次のコマンドを使用すると再び取得できます。az identity show -g <resource-group> -n <identity-name>
上記のコマンドの
<resource-group>
は、Application Gateway のリソース グループです。<identity-name>
は、作成された ID の名前です。 特定のサブスクリプションのすべての ID は、az identity list
を使用して一覧表示できます。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
その他の例
この攻略ガイドには、Application Gateway を使用して、HTTP または HTTPS 経由で AKS サービスをインターネットに公開する方法の例が含まれています。