Amazon EKS クラスターを Azure Arc に追加してみた

2021.05.26

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

いわさです。

Azureとその他のパブリッククラウドをハイブリッドで使う方法として、Azure Arcというサービスがあります。 現在、Azure Arcを使うことで、AWSインフラ上でも稼働出来るようになったAzureサービスが次々と追加されています。(まだプレビュー)

本日は、AWS上でAzureサービスを稼働させるためのベースとなる、Azure Arc と Amazon EKSの接続について行いました。

Azure Arc とは

オンプレミスやパブリッククラウド(GCPやAWSなど)とのハイブリッドクラウドを実現するサービスです。 AzureArc上で管理されたKubernetes環境(EKS, GKEなど)へAzureの一部サービスをデプロイすることが可能です。

早速やってみる

EKSクラスターの構築

まずはマネジメントコンソールからEKSクラスターを作成します。

クラスター作成時のKubernetesバージョンに気をつけてください。
AzureArcでサポートされているKubernetes バージョン は 1.13 以降 です。

また、以下のネットワーク要件を満たしていることも確認してください。
アウトバウンドなのでEKSの場合、デフォルトで問題ないはずです。

EKSノードを作成

EKSクラスターが作成されたら、ノードグループを作成します。
今回は "AL2_x86_64", "t3.medium", "2台構成" にしました。

Azure Arcを作成

次に、Azureポータル上で AzureArcを作成し、EKS接続のための準備をします。

インフラストラクチャタブから"Kubernetes クラスター"の追加を選択します。
リソースグループを選択し、クラスター名を入力してください。
ここで入力するクラスター名はAzureで管理するための名称でありEKS上の名称を使用する必要はありません。

スクリプトの実行タブに以下の情報が表示されています。

# このスクリプトでは Kubernetes クラスターを Azure に接続するための Azure Arc リソースを作成します
# ドキュメント: https://aka.ms/AzureArcK8sDocs

# Azure にログイン
az login

# Azure サブスクリプションの設定
az account set --subscription 11111111-2222-3333-4444-555555555555

# 接続されたクラスターの作成
az connectedk8s connect --name iwasa-aws-cluster --resource-group 20210526-iwasa --location westus2 --tags Datacenter='' City=''

スクリプトを実行せずに、ここでAzureポータル上の作業はストップしてください。
次項でローカル環境をセットアップし、その後本画面で表示されているスクリプトを実行します。

ローカルCLI環境からEKSクラスターへ接続

まず、ローカル環境とEKSクラスターを接続します。
AWS CLIがインストールされていない場合は以下を参考にインストールをしてください。

eksctlがインストールされていない場合は以下を参考にインストールをしてください。

get-contextsで取得出来ればOKです。

iwasa.takahito@hoge ~ % aws eks --region ap-northeast-1 update-kubeconfig --name iwasa20210526
Added new context arn:aws:eks:ap-northeast-1:111111111111:cluster/iwasa20210526 to /Users/iwasa.takahito/.kube/config

iwasa.takahito@hoge ~ % kubectl config get-contexts
CURRENT NAME CLUSTER AUTHINFO NAMESPACE
* arn:aws:eks:ap-northeast-1:111111111111:cluster/iwasa20210526 arn:aws:eks:ap-northeast-1:111111111111:cluster/iwasa20210526 arn:aws:eks:ap-northeast-1:111111111111:cluster/iwasa20210526

ローカルCLI環境からAzure Arcへ接続

次にローカル環境とAzureを接続します。
Azure CLIがインストールされていない場合は以下を参考にインストールしてください。

Azureポータル上で確認したスクリプトのうち、ログインとサブスクリプションの設定までを済ませます。

iwasa.takahito@hoge ~ % az login
The default web browser has been opened at https://login.microsoftonline.com/common/oauth2/authorize. Please continue the login in the web browser. If no web browser is available or if the web browser fails to open, use device code flow with `az login --use-device-code`.
You have logged in. Now let us find all the subscriptions to which you have access...
[
  {
    "cloudName": "AzureCloud",
    "homeTenantId": "11111111-2222-3333-4444-555555555555",
    "id": "66666666-7777-8888-9999-AAAAAAAAAAAA",
    "isDefault": true,
    "managedByTenants": [],
    "name": "xxxxxx",
    "state": "Enabled",
    "tenantId": "11111111-2222-3333-4444-555555555555",
    "user": {
      "name": "iwasa.takahito@mail.xx",
      "type": "user"
    }
  }
]
iwasa.takahito@hoge ~ % az account set --subscription 66666666-7777-8888-9999-AAAAAAAAAAAA

EKSクラスターとAzure Arcを接続

では、ここからEKSクラスターとAzureArcを接続します。
接続コマンドの内部でHeimを使うので、以下を参考に事前にインストールを済ませてください。

準備が出来たら、Azureポータル上の接続コマンドの残りを実行します。

iwasa.takahito@hoge ~ % az connectedk8s connect --name iwasa-aws-cluster --resource-group 20210526-iwasa --location westus2 --tags Datacenter='' City=''  
The command requires the extension connectedk8s. Do you want to install it now? The command will continue to run after the extension is installed. (Y/n): Y
Run 'az config set extension.use_dynamic_install=yes_without_prompt' to allow installing extensions without prompt.
Ensure that you have the latest helm version installed before proceeding.
This operation might take a while...

'Custom-locations' feature couldn't be enabled on this cluster as the pre-requisite registration of 'Microsoft.ExtendedLocation' was not met. More details for enabling this feature later on this cluster can be found here - https://aka.ms/EnableCustomLocations
{                                                                     
  "agentPublicKeyCertificate": "xxx,
  "agentVersion": "1.2.0",
  "connectivityStatus": "Connected",
  "distribution": "eks",
  "id": "/subscriptions/66666666-7777-8888-9999-AAAAAAAAAAAA/resourceGroups/20210526-iwasa/providers/Microsoft.Kubernetes/connectedClusters/iwasa-aws-cluster",
  "identity": {
    "principalId": "11111111-2222-3333-4444-555555555555",
    "tenantId": "11111111-2222-3333-4444-555555555555",
    "type": "SystemAssigned"
  },
  "infrastructure": "aws",
  "kubernetesVersion": "1.19.8-eks-96780e",
  "lastConnectivityTime": "2021-05-26T07:05:12.270000+00:00",
  "location": "westus2",
  "managedIdentityCertificateExpirationTime": "2021-08-24T05:33:00+00:00",
  "name": "iwasa-aws-cluster",
  "offering": null,
  "provisioningState": "Succeeded",
  "resourceGroup": "20210526-iwasa",
  "systemData": {
    "createdAt": "2021-05-26T05:38:51.200931+00:00",
    "createdBy": "iwasa.takahito@mail.xxx",
    "createdByType": "User",
    "lastModifiedAt": "2021-05-26T07:05:25.188764+00:00",
    "lastModifiedBy": "11111111-2222-3333-4444-555555555555",
    "lastModifiedByType": "Application"
  },
  "tags": {
    "City": "",
    "Datacenter": ""
  },
  "totalCoreCount": 4,
  "totalNodeCount": 2,
  "type": "microsoft.kubernetes/connectedclusters"
}

コマンド実行後、Azureポータル上の検証タブで、検証ボタンを押下して接続検証に成功するか確認してください。
うまくいったら以下のようになります。

AzureArcのクラスター一覧でも確認してみましょう。

接続されていますね。

なお、コマンド内で出力されたlocationの対応は以下をCLIから実施します。

export subscription=66666666-7777-8888-9999-AAAAAAAAAAAA
export resourceGroup=20210526-iwasa
export resourceName=iwasa-aws-cluster
export clName=mycustomlocation
export clNamespace=arc
export hostClusterId=$(az connectedk8s show -g ${resourceGroup} -n ${resourceName} --query id -o tsv)
export extensionId=$(az k8s-extension show -g ${resourceGroup} -c ${resourceName} --cluster-type connectedClusters --name ${ADSExtensionName} --query id -o tsv)
az customlocation create -g ${resourceGroup} -n ${clName} --namespace ${clNamespace} \
  --host-resource-id ${hostClusterId} \
  --cluster-extension-ids ${extensionId} --location eastus                                           
az provider register -n Microsoft.ExtendedLocation --wait

こんな時エラーが発生します

connectedk8s実行時 Heimがインストールされていないとエラーが発生し中断します。

Helm is not installed or the helm binary is not accessible to the connectedk8s cli. Could be a permission issue.
Ensure that you have the latest version of Helm installed on your machine and run using admin privilege. Learn more at https://aka.ms/arc/k8s/onboarding-helm-install

クラスター作成のみで、ノードが起動されていないとエラーが発生します。

Please ensure that this Kubernetes cluster have any nodes with OS 'linux' and architecture 'amd64', for scheduling the Arc-Agents onto and connecting to Azure. Learn more at https://aka.ms/ArcK8sSupportedOSArchitecture

さいごに

本日は、AmazonEKSとAzureArcの接続までを行いました。
次回以降、プレビュー機能であるAzureマネージドサービスのデプロイを行っていきたいと思います。