1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

つづくAdvent Calendar 2023

Day 8

Azure Arc 対応の Kubernetes クラスターを設定して Logic Apps をデプロイ

Posted at

その日試していたことを書いていたらアドベントカレンダー 25 日が溶けている。

変数は以下で試した。

AKS_CLUSTER_GROUP_NAME="noyclustergroup"
AKS_NAME="noyclustergroup-aks"
RESOURCE_LOCATION="eastus" 
GROUP_NAME="noyclustergroup"
CLUSTER_NAME="noyclustergroup-cluster"
EXTENSION_NAME="noy-appservice-ext"
NAMESPACE="noy-appservice-ns"
KUBE_ENVIRONMENT_NAME="noykube" 

セットアップ

Azure CLI に拡張機能追加

bash
az extension add --upgrade --yes --name connectedk8s
az extension add --upgrade --yes --name k8s-extension
az extension add --upgrade --yes --name customlocation
az provider register --namespace Microsoft.ExtendedLocation --wait
az provider register --namespace Microsoft.Web --wait
az provider register --namespace Microsoft.KubernetesConfiguration --wait
az extension remove --name appservice-kube
az extension add --upgrade --yes --name appservice-kube

Kubectl まで

bash
# 変数
AKS_CLUSTER_GROUP_NAME="noyclustergroup"
AKS_NAME="noyclustergroup-aks"
RESOURCE_LOCATION="eastus" 

# リソース グループ作成
az group create -g $AKS_CLUSTER_GROUP_NAME -l $RESOURCE_LOCATION
az aks create --resource-group $AKS_CLUSTER_GROUP_NAME --name $AKS_NAME --enable-aad --generate-ssh-keys
az aks get-credentials --resource-group $AKS_CLUSTER_GROUP_NAME --name $AKS_NAME --admin

kubectl get ns

image.png

接続

bash
GROUP_NAME="noyclustergroup"
CLUSTER_NAME="noyclustergroup-cluster"
az connectedk8s connect --resource-group $GROUP_NAME --name $CLUSTER_NAME
az connectedk8s show --resource-group $GROUP_NAME --name $CLUSTER_NAME

Log Analytics 用変数設定

bash
WORKSPACE_NAME="$GROUP_NAME-workspace" # Name of the Log Analytics workspace
az monitor log-analytics workspace create --resource-group $GROUP_NAME --workspace-name $WORKSPACE_NAME

LOG_ANALYTICS_WORKSPACE_ID=$(az monitor log-analytics workspace show --resource-group GROUP_NAME --workspace-name $WORKSPACE_NAME --query customerId --output tsv)
LOG_ANALYTICS_WORKSPACE_ID_ENC=$(printf %s $LOG_ANALYTICS_WORKSPACE_ID | base64 -w0) 
LOG_ANALYTICS_KEY=$(az monitor log-analytics workspace get-shared-keys --resource-group GROUP_NAME --workspace-name $WORKSPACE_NAME --query primarySharedKey --output tsv)
LOG_ANALYTICS_KEY_ENC=$(printf %s $LOG_ANALYTICS_KEY | base64 -w0) # Needed for the next step

拡張機能インストール

bash
EXTENSION_NAME="noy-appservice-ext"
NAMESPACE="noy-appservice-ns"
KUBE_ENVIRONMENT_NAME="noykube" 

az k8s-extension create --resource-group $GROUP_NAME --name $EXTENSION_NAME --cluster-type connectedClusters --cluster-name $CLUSTER_NAME --extension-type 'Microsoft.Web.Appservice' --release-train stable --auto-upgrade-minor-version true --scope cluster --release-namespace $NAMESPACE --configuration-settings "Microsoft.CustomLocation.ServiceAccount=default" --configuration-settings "appsNamespace=${NAMESPACE}" --configuration-settings "clusterName=${KUBE_ENVIRONMENT_NAME}" --configuration-settings "keda.enabled=true" --configuration-settings "buildService.storageClassName=default" --configuration-settings "buildService.storageAccessMode=ReadWriteOnce" --configuration-settings "customConfigMap=${NAMESPACE}/kube-environment-config" --configuration-settings "envoy.annotations.service.beta.kubernetes.io/azure-load-balancer-resource-group=${aksClusterGroupName}" --configuration-settings "logProcessor.appLogs.destination=log-analytics" --config-protected-settings "logProcessor.appLogs.logAnalyticsConfig.customerId=${LOG_ANALYTICS_WORKSPACE_ID_ENC}" --config-protected-settings "logProcessor.appLogs.logAnalyticsConfig.sharedKey=${LOG_ANALYTICS_KEY_ENC}"

ID を取っておく

bash
EXTENSION_ID=$(az k8s-extension show --cluster-type connectedClusters --cluster-name $CLUSTER_NAME --resource-group $GROUP_NAME --name $EXTENSION_NAME --query id --output tsv)

az resource wait --ids $EXTENSION_ID --custom "properties.installState!='Pending'" --api-version "2020-07-01-preview"

kubectl get pods -n $NAMESPACE

一旦この段階で以下となることを確認

image.png

カスタムの場所を作成

bash
CUSTOM_LOCATION_NAME="noy-custom-location" 

CONNECTED_CLUSTER_ID=$(az connectedk8s show --resource-group $GROUP_NAME --name $CLUSTER_NAME --query id --output tsv)

EXTENSION_ID=$(az k8s-extension show \
    --cluster-type connectedClusters \
    --cluster-name $CLUSTER_NAME \
    --resource-group $GROUP_NAME \
    --name $EXTENSION_NAME \
    --query id \
    --output tsv)


az customlocation create --resource-group $GROUP_NAME --name $CUSTOM_LOCATION_NAME --host-resource-id $CONNECTED_CLUSTER_ID --namespace $NAMESPACE --cluster-extension-ids $EXTENSION_ID


az customlocation show --resource-group $GROUP_NAME --name $CUSTOM_LOCATION_NAME

image.png

場所確認

bash
CUSTOM_LOCATION_ID=$(az customlocation show --resource-group $GROUP_NAME --name $CUSTOM_LOCATION_NAME --query id --output tsv)

App Service Kubernetes 環境を作成する

bash
az appservice kube create \
    --resource-group $GROUP_NAME \
    --name $KUBE_ENVIRONMENT_NAME \
    --custom-location $CUSTOM_LOCATION_ID 

az appservice kube show --resource-group $GROUP_NAME --name $KUBE_ENVIRONMENT_NAME

ここまで来た段階でようやく次

Logic Apps 作成

Azure CLI に拡張機能追加

bash
az extension add --yes --source "https://aka.ms/logicapp-latest-py2.py3-none-any.whl"

ここからは通常の Logic Apps デプロイ

bash
az logicapp create --name AKSLogicApps --resource-group $GROUP_NAME --subscription <SubscriptionID> --storage-account '<Storage Account Resouce ID>' --custom-location $CUSTOM_LOCATION_ID

できた。

image.png

めっちゃエラーが出ている

image.png

OS は Linux

image.png

Zip デプロイ

image.png

image.png

image.png

以上です~

つづく。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?