4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Azure Container Instances を Azure Container Registory からポートを複数持った状態でプロビジョンする

Posted at

今日は、Web App for Containers をハックしていたが、Web App なので、コンテナのポートを2つ以上公開することができない。その状況でもコンテナをデプロイするために、Azure Container Instances を使ってみた。時間がなかったので、30分以内に終わらせるため、この方法を選んだ。

コマンドラインでは複数ポートを指定できない

Azure Container Instance は、CLI, Portal, PowerShellの3つの方法がよく紹介されている。 Azure Container Registry においているコンテナをプロビジョンするにはどうしたらいいのだろう。パスワードで保護されているし。az コマンドでは、Container Registry のパスワードを入力できるが、ポータルや、CLI だと、ポートの複数指定ができない。

ARM テンプレートでデプロイする

ところが、Azure Container Instances REST-API を見るとどうやらできそう。具体的には、ARM テンプレートを使えば良い。

I upload the sample template on the gist. Please have a look. You can deploy it using az command.

ポイントはいくつかで、まずは複数ポート。簡単に設定できる。

                    "containers": [
                        {
                            "name": "kirinmq",
                            "properties": {
                                "image": "{YOUR_ACR_HOST_NAME}.azurecr.io/mq",
                                "ports": [
                                    {
                                        "port": "5555" 
                                    },
                                    {
                                        "port": "5556"
                                    }
                                ],

次に、ACR のクレデンシャル。そのままだ。ちなみにこのコンフィグをどこから見つけてきたかというと、ACI の REST API スペックから。

                "properties": {
                    "imageRegistryCredentials": [
                        {"password": "{YOUR_ACR_PASSWORD}",
                            "server": "{YOUR_ACR_HOST_NAME}.azurecr.io",
                            "username": "{YOUR_ACR_USER_NAME"}

                    ],

デプロイ。ちなみに、現在は使えるロケーションが限られてるので、注意。

az group create --name resourceGroupName --location westus
az group deployment create -n someDeploy --template-file azuredeploy.json -g resourceGroupName

Rest API を観察する

を観察して見ると色々面白い設定ができる。先の Gist にもしてあるが、コンテナで使う、CPUとか、メモリの確保とかができる。まるで、オーケストレータのようだ。Win/Linux の両方に対応している。マウントもできるようす。これは面白いね!

コンテナグループ

ちなみに、アーキテクチャ的には、同じVMに乗っかるコンテナグループという概念がある様子。Kubernetes の pod に似た概念で、同じコンテナグループのコンテナはVMを共有する。

container-groups-example.png

コンテナインスタンスの課金を見ると、CPU、メモリとか、リクエスト単位みたい。とかそういうものなので、コンテナグループを分けると、別のVMであることを保証するなら、コンテナグループを作ると、基本的にVMを占有とか可能なのだろうか?

Screen Shot 2017-10-13 at 11.53.34 PM.png

Debugの方法

さて、ハック時間内にできなかったことは、Debug の方法。やっぱコンテナはログが命。コンテナグループ、リソースグループ、コンテナ名を指定したらログが見える。

$ az container logs -n myContainerGroup -g resourceGroupName --container-name mq
Stopping nginx: [FAILED]
Starting nginx: [  OK  ]
Stopping sshd: [FAILED]
Generating SSH2 RSA host key: [  OK  ]
Generating SSH1 RSA host key: [  OK  ]
Generating SSH2 DSA host key: [  OK  ]
Starting sshd: [  OK  ]

おお、手元からログ見れた。Migration tips from IaaS to Web App for Containers on Azure の作戦で、シンボリックリンクを貼るとちゃんとデバッグできそう。また、コンテナ自身のコンフィグもみれる。先ほどの ARM テンプレートの実行結果みたいな感じ。

$ az container show -n myContainerGroup -g resourceGroupName
{
  "containers": [
    {
      "command": null,
      "environmentVariables": [],
      "image": "{YOUR_ACR_HOST_NAME}.azurecr.io/mq",
      "instanceView": {
        "currentState": {
          "detailStatus": "",
          "exitCode": null,
          "finishTime": null,
          "startTime": "2017-10-13T06:15:13+00:00",

見れない時は、Activity Log で。エラーはこんなのが書いてあった。

Error code
LocationNotAvailableForResourceType
Message
The provided location 'japaneast' is not available for resource type 'Microsoft.ContainerInstance/containerGroups'. List of available regions for the resource type is 'westus,eastus,westeurope'.

明らか!

削除もあるね

$ az container delete -n mq -g resourceGroupName -y
$ az container list -g resourceGroupName
[]

うん、簡単だ!

まとめ

ほんまこれサーバーレスよね。思ったより、細かく設定できそうなので、これは色々遊べそうだ!

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?