LoginSignup
4
1

More than 3 years have passed since last update.

AKSでWindowsコンテナを動かす

Posted at

※2020/04/11時点

意外とハマりました。
基本的にはドキュメントの通り
https://docs.microsoft.com/ja-jp/azure/aks/windows-container-cli

.NETFrameworkで適当なコンソールアプリ作成

結論からいうと、ここのwindowsservercoreイメージの指定が悪くハマりました。
気軽に mcr.microsoft.com/dotnet/framework/runtime:4.8
ではだめでした。

Dockerfile
FROM mcr.microsoft.com/dotnet/framework/runtime:4.8-20200211-windowsservercore-ltsc2019 AS runtime
WORKDIR /app
COPY bin/Debug .
ENTRYPOINT ["Docker48.exe"]

ACR作成

sample1222 という名前
リソースグループはakstest という名前にしています。

az acr create -n sample1222 -g akstest --sku basic

buildしてpush

--platform Windows いります

az acr build --registry sample1222 --image dotnetapp48:v1.0 --platform Windows .

AKSクラスター作成

az aks create --resource-group akstest --name myAKSCluster --node-count 2 --enable-addons monitoring --kubernetes-version 1.15.7 --generate-ssh-keys --windows-admin-password P@ssw0rd1234 --windows-admin-username azureuser --vm-set-type VirtualMachineScaleSets --load-balancer-sku standard --network-plugin azure  --attach-acr sample1222

--attach-acr でACRと紐づけ。 便利になりました。

az aks create gives Could not create a role assignment for subnet. Are you an Owner on this subscription?
というエラーでましたが、C:\Users\XXXXXX.azure\aksServicePrincipal.jsonを消して
何度か実行したら作成できました。

Windows Server ノード プール追加

az aks nodepool add  --resource-group akstest --cluster-name myAKSCluster --os-type Windows  --name npwin  --node-count 1  --kubernetes-version 1.15.7

クラスターに接続する

az aks get-credentials --resource-group akstest --name myAKSCluster

マニフェスト作成してデプロイ

sample.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: sample
  labels:
    app: sample
spec:
  template:
    metadata:
      name: sample
      labels:
        app: sample
    spec:
      nodeSelector:
        "beta.kubernetes.io/os": windows
      containers:
      - name: sample
        image: sample1222.azurecr.io/dotnetapp48:v1.0
        resources:
        ports:
          - containerPort: 80
  selector:
    matchLabels:
      app: sample
---
apiVersion: v1
kind: Service
metadata:
  name: sample
spec:
  type: LoadBalancer
  ports:
  - protocol: TCP
    port: 80
  selector:
    app: sample
kubectl apply -f sample.yaml

最初に書いたとおりベースイメージ間違っているとpodが起動しないのですが、イメージのバージョン関連のエラーの後にunauthorized: authentication required というエラーがでるのでACRの認証周りかと勘違いして時間を無駄にしました。

最後に

構築後からすぐにAzure Monitorでモニタリングできてログが見れるのはちょっとした検証に便利です。

2020-04-11_01h29_22.png

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