LoginSignup
4
1

More than 5 years have passed since last update.

Check! AKS `az aks create` で、あるはずの Service Principal が not found になってしまうときの対処方法

Last updated at Posted at 2017-11-20

こんにちは、 @dz_ こと大平かづみです。

Prologue - はじめに

AKS (Azure Container Service: Managed Kubernetes) を、Azure Cloud Shell で作成したときは問題なく作成できたのですが、

手元のマシンで実施すると、以下のようなエラーが出てうまくいきませんでした。

その対処法を書き留めておきます。

 az aks create -g <resource group> -n <aks name> --node-count 1 --generate-ssh-key
AAD role propagation done[############################################]  100.0000%
Operation failed with status: 'Bad Request'. Details: Service principal clientID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx not found in Active Directory tenant xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx, Please see https://aka.ms/acs-sp-help for more details.

<resource group>, <aks name> は任意の文字列

考察と対処

考察

考察としては、私の場合、1つのAzure アカウントで複数のサブスクリプションを使用していて、デフォルト(Pay as you go)ではないサブスクリプションでやりたかったのですが、それが関連してるように思いました。

ちなみに、上記エラーの tenant ID や client ID はあってました。

サブスクリプション切替え例
az login
az account set -s <使いたいサブスクリプションID>

# この後、続いて AKS の作成を行うと上記のエラー... (´・ω・`)

対処

ともあれ、以下のように AKS を作り直せばよいようです。

まず、上記のエラーが発生したとき、 ${HOME}/.azure/acsServicePrincipal.json がある場合は、すでに Service Principal ができてるようです。

cat ${HOME}/.azure/acsServicePrincipal.json | jq

{
  "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx": {
    "client_secret": "xxxxxxxxxxxxxxxxxxxx",
    "service_principal": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
  }
}

この Service Principal を指定して、 AKS を作成すればエラーになることなく作成できました。

Service Principal を指定して aks を作成する手順

まず、上記 json に書かれている Service Principal が存在するか確認します。

# 上記の Service Principal が存在するか確認する
az ad sp show --id <service_principal>

Service Principal があれば、下記のコマンドで AKS を作成しなおしましょう。 <service_principal>, <client_secret> は上記の json に書かれた値を指定してください。

もし Service Principal がない場合は、 AKS を最初から作成するか、別途 Service Principal を作って、その client secret を控えておき、下記のコマンドで使用すればよさそうです。

# Service Principal を指定して AKS を作成する
az aks create -g <resource_group>-n <aks name> --node-count 1 --service-principal <service_principal> --client-secret <client_secret>

--generate-ssh-key を指定してないのは、本記事の冒頭でエラーが出た段階ですでにキーができてるはずだからです。キーがない場合は、 --generate-ssh-key を指定して作成してください。

Epilogue - おわりに

ちょっとてこずりましたが、これを除けば、めちゃくちゃ使いやすい感じです!

引き続き AKS を勉強します~

4
1
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
4
1