- 追加された行はこの色です。
- 削除された行はこの色です。
「[[マイクロソフト系技術情報 Wiki>http://techinfoofmicrosofttech.osscons.jp/]]」は、「[[Open棟梁Project>https://github.com/OpenTouryoProject/]]」,「[[OSSコンソーシアム .NET開発基盤部会>https://www.osscons.jp/dotNetDevelopmentInfrastructure/]]」によって運営されています。
-戻る
--[[AzureのPaaS]]
--[[Visual Studio Kubernetes Tools]]
--[[AzureのPaaS]](CaaS)
---Azure Kubernetes Service (AKS)
---[[Azure Container Instances (ACI)]]
---[[Azure Web App for Containers]]
---[[Azure Functions]] on Docker
--Tools
---[[Visual Studio Kubernetes Tools]]
--Container Registry
---[[Azure Container Registry]]
---[[Microsoft Container Registry]]
* 目次 [#o37c996f]
#contents
*概要 [#s3622952]
Azure の マネージド [[Kubernetes(k8s)>#x4a72daa]]
-Azure Kubernetes Service (AKS) は [[k8s>#x4a72daa]] のノードの利用に対してだけ課金を行う、Azure のサービス
-マスターノードや k8s のバージョン管理、必要なツール類の提供は全て Azure の機能と統合され Microsoft が管理する
*詳細 [#be17a29e]
&color(red){朱書き};はリスタート手順
**[[K8s 基本のアーキテクチャ>https://dotnetdevelopmentinfrastructure.osscons.jp/index.php?Kubernetes#xbc57197]] [#m25f1bee]
**AKS 追加のアーキテクチャ [#p3ca0985]
[[Kubernetesのアーキテクチャ>https://dotnetdevelopmentinfrastructure.osscons.jp/index.php?Kubernetes#xbc57197]]に追加されたアーキテクチャ。
***ノードプール [#yf99ad99]
-Azure Virtual Machine Scale Sets (VMSS)
-AKS基盤の[[制御プレーン>AKSをセキュアに利用するためのテクニカルリファレンス#gcac2445]]側にある。
-[[実行ノード>AKSをセキュアに利用するためのテクニカルリファレンス#gcac2445]]側に払い出すノードのプール。
-ノードプール内のノードは
--ノードプールに所属する。
--異なる VM で構成できる。
***コンテナ・レジストリ [#p30b0bb1]
AKSの[[コンテナ・レジストリ>Visual Studio Tools for Docker#d0aa0c82]]は、Azure Container Registry (ACR)と言う。
AKSの[[コンテナ・レジストリ>Visual Studio Tools for Docker#d0aa0c82]]は、[[Azure Container Registry (ACR)>Azure Container Registry]]と言う。
**ネットワーク関連の情報 [#w88b4977]
***[[Azureネットワークの基礎的な情報>Azure#r51c97ed]] [#bbfe67f4]
***[[テクニカルリファレンス(ネットワーク構成)>AKSをセキュアに利用するためのテクニカルリファレンス#h6e5b109]] [#i1cd1a5b]
***[[ACR(コンテナ・レジストリ)をプライベート化する。]] [#qd7391d0]
***[[Azure SQL Databaseをプライベート化する。]] [#d14d6d94]
***[[AKSのアウトバウンドをAzure Firewallで制限する。]] [#b5d292ee]
***[[プライベートAKSクラスタを作成する。]] [#m0c88b4a]
*** ※ [[OA-LANとAzureのVNETの分離]] [#o328ad8f]
**認証・認可関連の情報 [#u2964d2a]
***[[テクニカルリファレンス(認証・認可)>AKSをセキュアに利用するためのテクニカルリファレンス#h7815383]] [#l13a97a6]
***[[Azure サービス プリンシパル]] [#ra796984]
***[[サービス プリンシパル>Azure サービス プリンシパル]]と[[Managed ID>Azure Managed ID]] [#vddab2f1]
***[[AKSクラスタ作成・操作に必要な権限]] [#hc485bd1]
***[[AzADによる条件付きアクセス機能を構成する。]] [#t071fa52]
***[[AKS Master APIにAzAD認証を統合する。]] [#l1d8ceab]
***[[AKSユーザ・アプリからのリソース・アクセス]] [#qde0f8b9]
**その他の情報 [#d856e3d9]
***基盤保守 [#e755b2b0]
-[[テクニカルリファレンス(基盤保守)>AKSをセキュアに利用するためのテクニカルリファレンス#rd67a39f]]
-[[AKSのバージョン、サポート、基盤保守について。]]
***開発~デプロイ [#ja9f4fdf]
-[[テクニカルリファレンス(開発~デプロイ)>AKSをセキュアに利用するためのテクニカルリファレンス#ye9b2134]]
-[[ACR(コンテナ・レジストリ)をプライベート化する。]]
-[[CI/CD]]
--[[コンテナのチェーン]]
--[[CI/CD パイプライン]]
**参考情報 [#y0a77bc9]
***[[K8sのポイント>AKSをセキュアに利用するためのテクニカルリファレンス#vf319a19]] [#t61a375a]
***[[AKSのポイント>AKSをセキュアに利用するためのテクニカルリファレンス#bf07dd3a]] [#q3d2cb02]
*チュートリアル [#f0c15710]
**前提 [#md0ef3ce]
-[[Docker for Windows]]を使えるようにしておく。
-Azure
--サブスクリプションを利用可能にしておく。
--[[Azure CLI]]
---インストール
---確認
---ログイン
-Kubernetes CLI のインストール
>az aks install-cli
--&color(red){環境変数の登録};
>set PATH=%PATH%;C:\Users\nishi\.azure-kubectl
--Kubernetes CLI の確認
>kubectl version
Client Version: version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.8", ...
**voting-appのエビデンス [#c7683828]
***(1) アプリケーションを準備 [#m0d071ff]
-git clone でソースコードを取得。
>git clone https://github.com/Azure-Samples/azure-voting-app-redis.git
cd azure-voting-app-redis
-docker-compose でイメージを実行。
>docker-compose up -d
-ブラウザでアクセスし投票アプリを動作確認。~
http://localhost:8080
-動作確認が完了したらコンテナを終了。
>docker-compose down
***(2) コンテナ・レジストリを作成 [#m5d1d1b1]
コンテナ・レジストリ ≒ Azure Container Registry (ACR)
コンテナ・レジストリ ≒ [[Azure Container Registry (ACR)>Azure Container Registry]]
-&color(red){ログイン};
>az login
You have logged in. Now let us find all the subscriptions to which you have access...
-サブスクリプションを確認して選択
--一覧
>az account list
{...json...}
--選択
>az account set -s <subscription id>
--確認
>az account show
{...json...}
-&color(red){リソース・グループの作成};
>az group create --name daisukenishino --location japaneast
{...json...}
-&color(red){コンテナ・レジストリ(ACR)の作成};
-&color(red){コンテナ・レジストリ([[ACR>Azure Container Registry]])の作成};
>az acr create --resource-group daisukenishino --name daisukenishinoacr --sku basic
{...json...}
--参考
---Azure Container Registry(ACR) SKU~
https://docs.microsoft.com/ja-jp/azure/container-registry/container-registry-skus
-&color(red){コンテナ・レジストリ(ACR)へログイン};
-&color(red){コンテナ・レジストリ([[ACR>Azure Container Registry]])へログイン};
>az acr login -n daisukenishinoacr
Login Succeeded
-&color(red){コンテナ・レジストリ(ACR)のログイン・サーバ名を取得};
-&color(red){コンテナ・レジストリ([[ACR>Azure Container Registry]])のログイン・サーバ名を取得};
>az acr list --resource-group daisukenishino --query "[].{acrLoginServer:loginServer}" --output table
AcrLoginServer
----------------------------
daisukenishinoacr.azurecr.io
-コンテナ・イメージの確認
>docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
azure-vote-front latest 63465cde7b05 7 days ago 965MB
-タグを更新して
>docker tag azure-vote-front daisukenishinoacr.azurecr.io/azure-vote-front:v1
-コンテナ・レジストリ(ACR)にプッシュ
-コンテナ・レジストリ([[ACR>Azure Container Registry]])にプッシュ
>docker push daisukenishinoacr.azurecr.io/azure-vote-front:v1
The push refers to repository [daisukenishinoacr.azurecr.io/azure-vote-front]
...
-コンテナ・レジストリ(ACR)にプッシュしたイメージを確認
-コンテナ・レジストリ([[ACR>Azure Container Registry]])にプッシュしたイメージを確認
--ImageName
>az acr repository list --name daisukenishinoacr --output table
Result
----------------
azure-vote-front
--Tag
>az acr repository show-tags --name daisukenishinoacr --repository azure-vote-front --output table
Result
--------
v1
***(3) Kubernetesクラスタを作成 [#l3698aeb]
-[[サービス・プリンシパル>#ra796984]]の作成
>az ad sp create-for-rbac --skip-assignment
{
"appId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"displayName": "azure-cli-2019-12-12-08-08-32",
"name": "http://azure-cli-2019-12-12-08-08-32",
"password": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"tenant": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}
--ポイント
---上記の値は以下のコマンドから確認できる。~
(出力ファイルをdisplayNameの"azure-cli-"を頼りに検索)
>az ad sp list > sp_list.txt
---一度作成したら、ResourceGroupを削除しても残っているので再利用可能。
---ただし、前述のパスワード(シークレット)をメモしておかないと再利用が不可能。
---その場合、以下のコマンドを使用して一度削除し再作成する。
>az ad sp delete --id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Removing role assignments
-ACR に権限を付与する。
-[[ACR>Azure Container Registry]]に権限を付与する。
--&color(red){ACR のリソース名を取得。};
--&color(red){[[ACR>Azure Container Registry]]のリソース名を取得。};
>az acr show --resource-group daisukenishino --name daisukenishinoacr --query "id" --output tsv
/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/daisukenishino/providers/Microsoft.ContainerRegistry/registries/daisukenishinoacr
--&color(red){[[サービス・プリンシパル>#ra796984]]に ACR の acrpull 権限を付与。};
--&color(red){[[サービス・プリンシパル>#ra796984]]に [[ACR>Azure Container Registry]] の acrpull 権限を付与。};
---appId : xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
---acrId : /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/daisukenishino/providers/Microsoft.ContainerRegistry/registries/daisukenishinoacr
>az role assignment create --assignee "<appId>" --scope "<acrId>" --role acrpull
{...json...}
-&color(red){クラスタの作成};~
作成時、SSH キーがユーザーディレクトリの .ssh に作成される。
--appId : xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
--password : xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
>az aks create --resource-group daisukenishino --name daisukenishinoaks --node-count 2 --service-principal "<appId>" --client-secret "<password>" --generate-ssh-keys
SSH key files 'C:\Users\nishi\.ssh\id_rsa' and 'C:\Users\nishi\.ssh\id_rsa.pub' have been generated under ~/.ssh to allow SSH access to the VM.
If using machines without permanent storage like Azure Cloud Shell without an attached file share, back up your keys to a safe location
{...json...}
-&color(red){クラスタへの接続};~
(前提となる、Kubernetes CLIがインストールされていること)
>az aks get-credentials --resource-group daisukenishino --name daisukenishinoaks
Merged "daisukenishinoaks" as current context in C:\Users\nishi\.kube\config
-接続確認
--&color(red){ノードを取得};
---一覧(通常)
>kubectl get nodes
NAME STATUS ROLES AGE VERSION
aks-nodepool1-nnnnnnnn-vmss000000 Ready agent 21m v1.13.12
aks-nodepool1-nnnnnnnn-vmss000001 Ready agent 21m v1.13.12
---一覧(付加情報)
>kubectl get nodes -o wide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
...
---ノード情報
>kubectl describe node <NodeName>
...
--バージョンの確認~
(Serverも表示されるようになる)
>kubectl version
Client Version: version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.8", ...}
Server Version: version.Info{Major:"1", Minor:"13", GitVersion:"v1.13.12", ...}
--クラスタの確認
>kubectl cluster-info
Kubernetes master is running at https://...
CoreDNS is running at https://...
kubernetes-dashboard is running at https://...
Metrics-server is running at https://...
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
--クラスタの一覧~
(複数クラスタある場合)
>kubectl config get-contexts
--名前空間一覧
>kubectl get namespaces
NAME STATUS AGE
default Active 37m
kube-public Active 37m
kube-system Active 37m
--サービスの確認
>kubectl get services -o wide
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
kubernetes ClusterIP 10.0.0.1 <none> 443/TCP 41m <none>
-K8sダッシュボードから確認
--権限を付与する。
>kubectl create clusterrolebinding kubernetes-dashboard --clusterrole=cluster-admin --serviceaccount=kube-system:kubernetes-dashboard
--前述の「kubernetes-dashboard」のURLにProxy経由でアクセスする。
>az aks browse --resource-group daisukenishino --name daisukenishinoaks
Merged "daisukenishinoaks" as current context in C:\Users\nishi\AppData\Local\Temp\xxxxxxxxxxx
Proxy running on http://127.0.0.1:8001/
Press CTRL+C to close the tunnel...
バッチ ジョブを終了しますか (Y/N)? Y
>
-Azure ポータルから確認~
ここまでやったら、Azure ポータルから~
resource、resource-groupを確認してみてもイイ。
***(4) アプリケーションを実行 [#l09fa0fe]
-デプロイ・マニフェストを更新
--コンテナ・レジストリ(ACR)のログイン・サーバ名を取得(前述)
--コンテナ・レジストリ([[ACR>Azure Container Registry]])のログイン・サーバ名を取得(前述)
--azure-vote-all-in-one-redis.yamlの編集~
イメージの出所をACRのログイン・サーバ名に変更する。
イメージの出所を[[ACR>Azure Container Registry]]のログイン・サーバ名に変更する。
---変更前
containers:
- name: azure-vote-front
image: microsoft/azure-vote-front:v1
---変更後
containers:
- name: azure-vote-front
image: daisukenishinoacr.azurecr.io/azure-vote-front:v1
--azure-vote-all-in-one-redis.yamlの適用
>kubectl apply -f azure-vote-all-in-one-redis.yaml
deployment.apps/azure-vote-back created
service/azure-vote-back created
deployment.apps/azure-vote-front created
service/azure-vote-front created
--デプロイ・マニフェストについて。~
以下の4セクションで構成されている。
---(1) バックエンド(Redis)のデプロイメントの作成
---(2) バックエンド(Redis)に対するサービスの作成
---(3) フロントエンド・アプリのデプロイメントの作成
---(4) フロントエンド・アプリに対するサービスの作成
-アプリケーションをテストする
--進行状況を監視
>kubectl get service azure-vote-front --watch
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
azure-vote-front LoadBalancer 10.0.121.183 <pending> 80:31338/TCP 50s
--EXTERNAL-IPが割り当てられるまで待つ。
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
azure-vote-front LoadBalancer 10.0.121.183 xxx.xxx.xxx.xxx 80:31338/TCP 50s
--EXTERNAL-IPが割り当てられたらブラウザからアクセスする。~
http://xxx.xxx.xxx.xxx/
-k8s での動作を確認する
--デプロイメント
---一覧
>kubectl get deployments -o wide
NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
azure-vote-back 1/1 1 1 8m13s azure-vote-back redis app=azure-vote-back
azure-vote-front 1/1 1 1 8m13s azure-vote-front daisukenishinoacr.azurecr.io/azure-vote-front:v1 app=azure-vote-front
---詳細
>kubectl describe deployment azure-vote-front
--レプリカセット
>kubectl describe replicaset azure-vote-front-xnnnnnnx
--ポッド
---一覧
>kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
azure-vote-back-xxxxxxxxxx-xxxxx ...
azure-vote-front-xxxxxxxxxx-xxxxx ...
---詳細
>kubectl describe pods <PodName>
--サービス
---一覧(≒進行状況の監視)~
>kubectl get services -o wide
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
azure-vote-back ClusterIP 10.0.36.57 <none> 6379/TCP 18m app=azure-vote-back
azure-vote-front LoadBalancer 10.0.121.183 xxx.xxx.xxx.xxx 80:31338/TCP 18m app=azure-vote-front
kubernetes ClusterIP 10.0.0.1 <none> 443/TCP 18h <none>
---詳細~
フロント
>kubectl describe service azure-vote-front
...
バック
>kubectl describe service azure-vote-back
...
-K8sダッシュボードから確認(前述)~
リソースの消費状況を確認できる。
***(5-1) アプリケーションをスケール(pod) [#f1722533]
-ポッドの一覧
>kubectl get pods
NAME READY STATUS RESTARTS AGE
... ... ... ... ...
-ポッドを手動スケーリング~
デプロイ・マニフェストに対してポッド数を明示的に指定。
--スケーリング
>kubectl scale --replicas=5 deployment/azure-vote-front
deployment.extensions/azure-vote-front scaled
---deployments(ラベル指定)
>kubectl get deployments -l app=azure-vote-front
NAME READY UP-TO-DATE AVAILABLE AGE
azure-vote-front 5/5 5 5 72m
---replicasets(ラベル指定)
>kubectl get replicasets -l app=azure-vote-front
NAME DESIRED CURRENT READY AGE
azure-vote-front-64b548d9cf 5 5 5 72m
---pods(通常)
>kubectl get pods
NAME READY STATUS RESTARTS AGE
... ... ... ... ...
---pods(ラベル指定&詳細)
>kubectl get pods -l app=azure-vote-front -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
azure-vote-front-xxxxxxxxxx-xxxxx ...
---node(詳細)
>kubectl describe node aks-nodepooln-...
---service(詳細)
>kubectl describe service azure-vote-front
--元に戻す。
---replicas=1に変更する。
>kubectl scale --replicas=1 deployment/azure-vote-front
deployment.extensions/azure-vote-front scaled
---反映を確認する。
>kubectl get pods
NAME READY STATUS RESTARTS AGE
azure-vote-back-xxxxxxxxxx-xxxxx 1/1 Running 0 81m
azure-vote-front-xxxxxxxxxx-xxxxx 1/1 Running 0 81m
-ポッドを自動スケーリング~
閾値を用いて、自動でのスケールアウト
--CPU の使用率を閾値に指定
>kubectl autoscale deployment azure-vote-front --cpu-percent=50 --min=3 --max=10
horizontalpodautoscaler.autoscaling/azure-vote-front autoscaled
--設定の確認~
hpaは、horizontal pod autoscalersの略。
>kubectl get hpa --watch
NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE
azure-vote-front Deployment/azure-vote-front 0%/50% 3 10 3 5m29s
--スケールの確認~
azure-vote-frontのpodが増えている筈(必要に応じて[[負荷テスト>#u7911b01]]を実施)。
>kubectl get pods
NAME READY STATUS RESTARTS AGE
azure-vote-back-xxxxxxxxxx-xxxxx 1/1 Running 0 90m
azure-vote-front-xxxxxxxxxx-xxxxx 1/1 Running 0 5m34s
azure-vote-front-xxxxxxxxxx-xxxxx 1/1 Running 0 5m34s
azure-vote-front-xxxxxxxxxx-xxxxx 1/1 Running 0 90m
***(5-2) アプリケーションをスケール(node) [#ifab5104]
ポッドが増えた場合、ノードが不足するので、ノードを追加する必要がある。
-ノードの手動スケール
--ノードの追加
>az aks scale --resource-group daisukenishino --name daisukenishinoaks --node-count 3
{...json...}
--ノードの確認
>kubectl get nodes
NAME STATUS ROLES AGE VERSION
aks-nodepool1-nnnnnnnn-vmss000000 Ready agent 21h v1.13.12
aks-nodepool1-nnnnnnnn-vmss000001 Ready agent 21h v1.13.12
aks-nodepool1-nnnnnnnn-vmss000002 Ready agent 3m54s v1.13.12
-ノードの自動スケール~
プレビューとしてノードの自動スケールもサポート
***(5-3) ユーティリティによる負荷テスト [#u7911b01]
-スケーリング状況を監視
>kubectl get pods -o wide --watch
-負荷テスト(別窓から)
--実行
>kubectl run -i --tty load-generator --image=busybox /bin/sh
kubectl run --generator=deployment/apps.v1 is DEPRECATED and will be removed in a future version. Use kubectl run --generator=run-pod/v1 or kubectl create instead.
If you don't see a command prompt, try pressing enter.
/ # while true; do wget -q -O- http://xxx.xxx.xxx.xxx/; done
...ココで負荷テストが実行される。...
...終了するには「ctrl+c」を押下する。...
/ # exit
Session ended, resume using 'kubectl attach load-generator-xxxxxxxxxx-xxxxx -c load-generator -i -t' command when the pod is running
>kubectl attach load-generator-xxxxxxxxxx-xxxxx -c load-generator -i -t
If you don't see a command prompt, try pressing enter.
/ #
--破棄
>kubectl delete deployments load-generator
deployment.extensions "load-generator" deleted
***(6) アプリケーションを更新 [#t4f31ed0]
-ローカルでの更新作業
--アプリケーションを更新する。~
azure-vote 内の config_file.cfg のタイトル部分を変更
--Dockerイメージを更新する。
>docker-compose up --build -d
--Dockerコンテナを実行する。
>docker-compose up -d
--ブラウザでアクセスし投票アプリの更新を確認。~
http://localhost:8080
-ACRに登録
-[[ACR>Azure Container Registry]]に登録
--イメージにタグを付けて
>docker tag azure-vote-front daisukenishinoacr.azurecr.io/azure-vote-front:v2
--プッシュする
>az acr login -n daisukenishinoacr
Login Succeeded
>docker push daisukenishinoacr.azurecr.io/azure-vote-front:v2
The push refers to repository [daisukenishinoacr.azurecr.io/azure-vote-front]
...
--ACRに登録されたことを確認
--[[ACR>Azure Container Registry]]に登録されたことを確認
>az acr repository show-tags --name daisukenishinoacr --repository azure-vote-front --output table
Result
--------
v1
v2
-K8sで実行
--podsを確認しつつ、~
(v1 ポッドが停止され v2 ポッドが起動する)
>kubectl get pods -o wide --watch
--デプロイメントのイメージを更新(別窓から)
---kubectl setを使用する方法
>kubectl set image deployment azure-vote-front azure-vote-front=daisukenishinoacr.azurecr.io/azure-vote-front:v2
---kubectl applyを使用する方法(前述)
--AGEから、更新を確認できる。
>kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
azure-vote-back-xxxxxxxxxx-xxxxx 1/1 Running 0 3h59m 10.244.1.3 aks-nodepool1-nnnnnnnn-vmss000000 <none> <none>
azure-vote-front-xxxxxxxxxx-xxxxx 1/1 Running 0 6m1s 10.244.1.13 aks-nodepool1-nnnnnnnn-vmss000000 <none> <none>
azure-vote-front-xxxxxxxxxx-xxxxx 1/1 Running 0 6m8s 10.244.2.3 aks-nodepool1-nnnnnnnn-vmss000002 <none> <none>
azure-vote-front-xxxxxxxxxx-xxxxx 1/1 Running 0 6m8s 10.244.2.2 aks-nodepool1-nnnnnnnn-vmss000002 <none> <none>
--EXTERNAL-IPを確認(前述)
>kubectl get service azure-vote-front
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
azure-vote-front LoadBalancer 10.0.121.183 xxx.xxx.xxx.xxx 80:31338/TCP 4h28m
--テスト~
http://xxx.xxx.xxx.xxx/
-k8s での動作を確認する(前述)
追加の手順
--v1, v2のレプリカを確認できる。
>kubectl get replicasets -o wide -l app=azure-vote-front
NAME DESIRED CURRENT READY AGE CONTAINERS IMAGES SELECTOR
azure-vote-front-xxxxxxxxxx 0 0 0 4h17m azure-vote-front daisukenishinoacr.azurecr.io/azure-vote-front:v1 app=azure-vote-front,pod-template-hash=xxxxxxxxxx
azure-vote-front-yyyyyyyyyy 3 3 3 23m azure-vote-front daisukenishinoacr.azurecr.io/azure-vote-front:v2 app=azure-vote-front,pod-template-hash=yyyyyyyyyy
--デプロイメントのイベントで更新を確認できる。
>kubectl describe deployments azure-vote-front
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
v1のReplicaSetのpodがdown
v2のReplicaSetのpodがup ... みたいなログが出る。
--1つずつ処理される理由~
ローリングアップデートの定義は以下のようになっているため。
>kubectl describe deploy
...
RollingUpdateStrategy: 1 max unavailable, 1 max surge
...
***(7) クラスタのアップグレードと削除 [#s1f962be]
-アップグレード
--アップグレード可能バージョンの確認
>az aks get-upgrades --resource-group daisukenishino --name daisukenishinoaks
{
"agentPoolProfiles": null,
"controlPlaneProfile": {
"kubernetesVersion": "1.13.12",
"name": null,
"osType": "Linux",
"upgrades": [
{
"isPreview": null,
"kubernetesVersion": "1.14.7"
},
{
"isPreview": null,
"kubernetesVersion": "1.14.8"
}
]
},
"id": "",
"name": "default",
"resourceGroup": "daisukenishino",
"type": "Microsoft.ContainerService/managedClusters/upgradeprofiles"
}
--アップグレードの実行
>az aks upgrade --resource-group daisukenishino --name daisukenishinoaks --kubernetes-version 1.14.7
Kubernetes may be unavailable during cluster upgrades.
Are you sure you want to perform this operation? (y/n): y
Since control-plane-only argument is not specified, this will upgrade the
control plane AND all nodepools to version 1.14.7. Continue? (y/N): y
{...json...}
--アップグレードの検証
>az aks get-upgrades --resource-group daisukenishino --name daisukenishinoaks
{
"agentPoolProfiles": null,
"controlPlaneProfile": {
"kubernetesVersion": "1.14.7",
"name": null,
"osType": "Linux",
"upgrades": [
{
"isPreview": null,
"kubernetesVersion": "1.14.8"
},
{
"isPreview": true,
"kubernetesVersion": "1.15.4"
},
{
"isPreview": true,
"kubernetesVersion": "1.15.5"
}
]
},
"id": "",
"name": "default",
"resourceGroup": "daisukenishino",
"type": "Microsoft.ContainerService/managedClusters/upgradeprofiles"
}
--EXTERNAL-IPを確認(前述)
>kubectl get service azure-vote-front
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
azure-vote-front LoadBalancer 10.0.121.183 xxx.xxx.xxx.xxx 80:31338/TCP 4h28m
--テスト~
http://xxx.xxx.xxx.xxx/
-クラスタの削除
--[[Azure CLI]]から実行
>az group delete --name daisukenishino --yes --no-wait
--Azureポータルからも確認すると良い。
---MC_から始まる、ResourceGroupが作成されている。
MC_ResourceGroupName_AKSName_AzureLocationName
---ここには、nodesをホストする vm が含まれるらしい。
---依存関係があるらしく、az group deleteすると一緒に消える。
**SQL Serverのエビデンス [#n100e4bf]
***(0) 前提 [#j7aaecf0]
-[[Azure Data Studioをインストールしておく。>https://docs.microsoft.com/ja-jp/sql/azure-data-studio/download]]
-[[(3) Kubernetesクラスタを作成>#l3698aeb]]までを行い、~
コンテナ・レジストリとKubernetesクラスタを作成しておく。
***(1) ストレージの準備 [#v5360d83]
先ずは、ストレージとして、永続ボリュームを作成する。~
(非永続ボリュームの確認は、[[Qiitaの記事の手順>#z89c63b0]]を確認するだけに留める)
-以下の様に、mssql-storage.yamlを作成する。
kind: StorageClass
apiVersion: storage.k8s.io/v1beta1
metadata:
name: azure-disk
provisioner: kubernetes.io/azure-disk
parameters:
storageaccounttype: Premium_LRS
kind: Managed
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: mssql-data
annotations:
volume.beta.kubernetes.io/storage-class: azure-disk
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 8Gi
--kind: StorageClass~
前半はストレージ・クラス用
---metadata: name: azure-disk~
名前は azure-disk
---provisioner: kubernetes.io/azure-disk~
ストレージ実行サービスとして[[Azureのディスク ストレージ]]を指定~
・[[Azureのディスク ストレージ]] : 1つのポッドのみがアクセスする場合~
・Azure Files : 複数のポッドからアクセスする場合
---parameter:~
渡すパラメタを指定。~
・kind: Managed~
[[管理ディスク>Azureのディスク ストレージ#v086e7a2]]~
・storageaccounttype: Premium_LRS~
[[ストレージのsku>Azureのディスク ストレージ#c73b6f13]]
---その他~
・ReclaimPolicy の設定がないため、既定の Delete が適用
--kind: PersistentVolumeClaim~
後半は永続ボリューム要求用
---metadata:~
・name: mssql-data~
名前は mssql-data~
・annotations: volume.beta.kubernetes.io/storage-class: azure-disk~
ストレージクラスとして [[Azureのディスク ストレージ]] を指定
---spec:~
・accessModes: - ReadWriteOnce~
ボリュームに対するアクセス(1 つのポッドのみがアクセス)~
・resources: requests: storage: 8Gi~
容量を指定
-mssql-storage.yamlの適用
>kubectl apply -f mssql-storage.yaml
storageclass.storage.k8s.io/azure-disk created
persistentvolumeclaim/mssql-data created
-永続ボリュームの確認
--永続ボリューム
>kubectl get pv
--ストレージ・クラス
>kubectl get sc -o wide
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS
REASON AGE
pvc-... 8Gi RWO Delete Bound default/mssql-data azure-disk 15s
--永続ボリューム要求
---一覧
>kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
mssql-data Bound pvc-... 8Gi RWO azure-disk 2m9s
---詳細
>kubectl describe pvc mssql-data
...
--Azure ポータルから確認~
MC_から始まる、ResourceGroupの中に、~
「kubernetes-dynamic-pvc-...」のディスクを確認できる。
-削除
--永続ボリューム要求を削除。
>kubectl delete pvc mssql-data
persistentvolumeclaim "mssql-data" deleted
--永続ボリュームも削除される。
>kubectl get pv
No resources found.
--永続ボリューム要求の再作成
>kubectl apply -f mssql-storage.yaml
storageclass.storage.k8s.io/azure-disk unchanged
persistentvolumeclaim/mssql-data created
--再度チェック
>kubectl get pv --watch
...
***(2-1) SQL のインストール [#u339f348]
シークレットの作成や SQL Server 2017 の配置
-シークレットの作成
--mssqlのシークレットを作成(K=SA_PASSWORD, V="xxxxx")
>kubectl create secret generic mssql --from-literal=SA_PASSWORD="xxxxx"
secret/mssql created
--シークレットの確認(値はBase64エンコされている)
>kubectl get secret mssql -o yaml
...yaml...
-SQL Server 2017 の配置~
以下の様に、sqldeployment.yamlを作成する。
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: mssql-deployment
spec:
replicas: 1
template:
metadata:
labels:
app: mssql
spec:
terminationGracePeriodSeconds: 10
containers:
- name: mssql
image: mcr.microsoft.com/mssql/server:2017-latest
ports:
- containerPort: 1433
env:
- name: MSSQL_PID
value: "Developer"
- name: ACCEPT_EULA
value: "Y"
- name: MSSQL_SA_PASSWORD
valueFrom:
secretKeyRef:
name: mssql
key: SA_PASSWORD
volumeMounts:
- name: mssqldb
mountPath: /var/opt/mssql
volumes:
- name: mssqldb
persistentVolumeClaim:
claimName: mssql-data
---
apiVersion: v1
kind: Service
metadata:
name: mssql-deployment
spec:
selector:
app: mssql
ports:
- protocol: TCP
port: 1433
targetPort: 1433
type: LoadBalancer
--containers.env:~
コンテナに渡す各種引数を指定
---name: MSSQL_PID~
value: "Developer"(SQL Server Developer Edition)
---name: ACCEPT_EULA~
value: "Y"
---name: MSSQL_SA_PASSWORD~
作成したシークレットは valueFrom.secretKeyRef で取得
--containers.volumeMounts:~
ボリュームを「/var/opt/mssql」にマウント
--spec.volumes:~
前回作成した永続ボリューム要求を指定
-sqldeployment.yamlの適用
>kubectl apply -f sqldeployment.yaml
deployment.apps/mssql-deployment created
service/mssql-deployment created
-サービス・ポッドの確認
--サービス
>kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.0.0.1 <none> 443/TCP 31m
mssql-deployment LoadBalancer 10.0.148.142 xxx.xxx.xxx.xxx 1433:xxxxx/TCP 18s
--ポッド
>kubectl get pods --watch
NAME READY STATUS RESTARTS AGE
mssql-deployment-xxxxxxxxxx-xxxxx 1/1 Running 0 3m33s
***(2-2) SQL の障害復旧の検証 [#c68a16b1]
-mssqlにアクセスしてみる。
--[[Azure Data Studioで接続&ログインする。>https://docs.microsoft.com/ja-jp/sql/azure-data-studio/quickstart-sql-server]]
---Connection Type : Microsoft SQL Server
---Server : <External IP Address>
---Authentication : SQL Login
---Account
- UID : SA~
- PWD : xxxxxxx
--sqlcmd ユーティリティ で接続&ログインする。
>sqlcmd -S <External IP Address> -U SA -P "xxxxxxx"
--DDL、DML(INSERT)実行~
得意の「[[instnwnd.sql>https://github.com/OpenTouryoProject/OpenTouryo/tree/develop/root/files/resource/Sql/sqlserver]]」を使用して「SELECT * FROM SHIPPERS」でも実行する。~
(exec sp_dboptionの部分は旧ver向けstatementなのでコメントアウトするか削除する)
-ポッド再配置を行う。~
(これは、アプリではなくDBインスタンスの再起動になる。)
--ポッド一覧の取得
>kubectl get pods
NAME READY STATUS RESTARTS AGE
mssql-deployment-xxxxxxxxxx-xxxxx 1/1 Running 0 23m
--ポッドの削除
>kubectl delete pod mssql-deployment-xxxxxxxxxx-xxxxx
pod "mssql-deployment-xxxxxxxxxx-xxxxx" deleted
--ポッド一覧の取得(再配置の確認)
>kubectl get pods --watch
NAME READY STATUS RESTARTS AGE
mssql-deployment-yyyyyyyyyy-yyyyy 1/1 Running 0 3m33s
--再配置後、mssqlにアクセスできることを確認する。
---接続&ログインし、
---DML(SELECT)を実行する。
-ポッドの再配置(異なるノードへ再配置)
--ポッド一覧の取得
>kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
mssql-deployment-yyyyyyyyyy-yyyyy 1/1 Running 0 5m45s 10.244.1.4 aks-nodepool1-nnnnnnnn-vmss000001 <none> <none>
--ノードの一時停止
>kubectl drain aks-nodepool1-nnnnnnnn-vmss000001 --ignore-daemonsets --delete-local-data
node/aks-nodepool1-nnnnnnnn-vmss000001 cordoned
WARNING: ignoring DaemonSet-managed Pods: kube-system/kube-proxy-xxxxx
evicting pod "coredns-xxxxxxxxxx-xxxxx"
pod/coredns-xxxxxxxxxx-xxxxx evicted
node/aks-nodepool1-nnnnnnnn-vmss000001 evicted
--ノード一時停止の確認~
Status に SchedulingDisabledという文字を確認できる。
>kubectl get nodes
NAME STATUS ROLES AGE VERSION
aks-nodepool1-nnnnnnnn-vmss000000 Ready agent 91m v1.14.8
aks-nodepool1-nnnnnnnn-vmss000001 Ready,SchedulingDisabled agent 91m v1.14.8
--ポッドを削除してレプリカセットによって再配置。
>kubectl delete pod mssql-deployment-yyyyyyyyyy-yyyyy
--ポッド一覧の取得(再配置の確認 1→0)
>kubectl get pods -o wide --watch
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
mssql-deployment-zzzzzzzzzz-zzzzz 1/1 Running 0 2m53s 10.244.1.4 aks-nodepool1-nnnnnnnn-vmss000000 <none> <none>
--再配置後、mssqlにアクセスできることを確認する。
---接続&ログインし、
---DML(SELECT)を実行する。
--Azure ポータルから確認~
ディスクが新しいノードにアタッチされていることを確認できる。~
(「所有者 VM」の欄に、変更後のNODEのIDが表示される。)
-ノードの一時停止を解除(再び再配置してもイイ 0→1)
>kubectl uncordon aks-nodepool1-nnnnnnnn-vmss000001
node/aks-nodepool1-nnnnnnnn-vmss000001 uncordoned
-[[Azure CLI]]からクラスタの削除を実行
>az group delete --name daisukenishino --yes --no-wait
**ASP.NET Coreのエビデンス [#u25677fb]
***(0) 前提 [#sf0a8e79]
-Visual Studio 2019 または dotnet core 3.0 が利用できる環境
-[[(3) Kubernetesクラスタを作成>#l3698aeb]]までを行い、~
コンテナ・レジストリとKubernetesクラスタを作成しておく。
***(1) 事前準備 [#ca136b60]
-DBを作成するが、内容は「[[SQL Serverのエビデンス>#n100e4bf]]」と同じ。
-以下の様に、sql2017.yamlを作成する。
--差異
---2つのデプロイ・マニフェスト(StorageとRDBMS)が結合され、
---DBのシークレット作成処理が含まれる。~
("MyC0m9l&xP@ssw0rd"をBase64化した値を指定している)
--内容
kind: StorageClass
apiVersion: storage.k8s.io/v1beta1
metadata:
name: azure-disk
provisioner: kubernetes.io/azure-disk
parameters:
storageaccounttype: Premium_LRS
kind: Managed
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: mssql-data
annotations:
volume.beta.kubernetes.io/storage-class: azure-disk
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 8Gi
---
apiVersion: v1
kind: Secret
metadata:
name: mssql
type: Opaque
data:
SA_PASSWORD: "TXlDMG05bCZ4UEBzc3cwcmQ="
---
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: mssql-deployment
spec:
replicas: 1
template:
metadata:
labels:
app: mssql
spec:
terminationGracePeriodSeconds: 10
containers:
- name: mssql
image: mcr.microsoft.com/mssql/server:2017-latest
ports:
- containerPort: 1433
env:
- name: MSSQL_PID
value: "Developer"
- name: ACCEPT_EULA
value: "Y"
- name: MSSQL_SA_PASSWORD
valueFrom:
secretKeyRef:
name: mssql
key: SA_PASSWORD
volumeMounts:
- name: mssqldb
mountPath: /var/opt/mssql
volumes:
- name: mssqldb
persistentVolumeClaim:
claimName: mssql-data
---
apiVersion: v1
kind: Service
metadata:
name: mssql-deployment
spec:
selector:
app: mssql
ports:
- protocol: TCP
port: 1433
targetPort: 1433
type: LoadBalancer
-sql2017.yamlの適用
>kubectl apply -f sql2017.yaml
-mssql-deploymentのEXTERNAL-IPの確認。
>kubectl get service --watch
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.0.0.1 <none> 443/TCP 4h26m
mssql-deployment LoadBalancer 10.0.100.250 52.156.45.201 1433:30117/TCP 4h19m
-Azure Data Studioでデータを追加(前述)
--IPアドレス:SQL Serverのサービス名("mssql-deployment")に変更
--パスワード:作成したシークレット("MyC0m9l&xP@ssw0rd")に変更
-最後の「type: LoadBalancer」削除して再適用~
--ローカルでは10.0.75.1でブリッジ
---[[Docker Desktop 2.2.0 から 10.0.75.1 は使用できなくなっている。>Docker for Windowsのネットワーク設定#o0ae51ae]]
--[[Docker Compose>https://dotnetdevelopmentinfrastructure.osscons.jp/index.php?Docker%E3%82%B3%E3%83%B3%E3%83%9D%E3%83%BC%E3%82%BA]]ではlinks名を使用する。
---[[linksは古いらしいので、networksを使用する。>https://dotnetdevelopmentinfrastructure.osscons.jp/index.php?Docker%E3%81%AE%E3%83%8D%E3%83%83%E3%83%88%E3%83%AF%E3%83%BC%E3%82%AF%E8%A8%AD%E5%AE%9A#k76b1473]]
--AKSではService名を使用する。
>kubectl apply -f sql2017.yaml --force
storageclass.storage.k8s.io/azure-disk unchanged
persistentvolumeclaim/mssql-data unchanged
secret/mssql unchanged
deployment.apps/mssql-deployment unchanged
service/mssql-deployment configured
-mssql-deploymentのEXTERNAL-IPが<none>に変更されたことを確認。
>kubectl get service --watch
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.0.0.1 <none> 443/TCP 4h27m
mssql-deployment ClusterIP 10.0.254.191 <none> 1433/TCP 6s
***(2) アプリを開発 [#eca47597]
-チュートリアルのサンプルが微妙なので[[コチラ>Visual Studio Kubernetes Tools#e04f0515]]を使用する。
-ポイント
--[[voting-app>#c7683828]]と同様にRedisを使用する。~
(チュートリアルでは、Redisを使用していない)
--DBMSは、SQL Serverを使用する。~
(チュートリアルでは、K8s上のDBを直参照するが、)
---ローカルでは10.0.75.1でブリッジ
---[[Docker Compose>https://dotnetdevelopmentinfrastructure.osscons.jp/index.php?Docker%E3%82%B3%E3%83%B3%E3%83%9D%E3%83%BC%E3%82%BA]]ではlinks名を使用する。
---AKSではService名を使用する。
-ローカル、Docker Composeでテストしてから、[[AKSへデプロイ>#waa01867]]する。
***(3-1) アプリをデプロイ(ACRへ) [#waa01867]
***(3-1) アプリをデプロイ([[ACR>Azure Container Registry]]へ) [#waa01867]
-以下の接続文字列を変更する。
--SQL Server
---IPアドレス:SQL Serverのサービス名("mssql-deployment")に変更
---パスワード:作成したシークレット("MyC0m9l&xP@ssw0rd")に変更
--Redis
---IPアドレス:Redisのサービス名(webapplication1-back)に変更
---パスワード:なし
services.AddDistributedRedisCache(option =>
{
option.Configuration = "webapplication1-back";
option.InstanceName = "redis";
});
-コンテナ・レジストリへアップロード
--dotnet coreのみ、コンテナ・レジストリへアップロード
--Visual Studioの発行でも出来るようなのでこちらを使用。
-Visual Studioで発行(コンテナ・レジストリへアップロード)手順
--プロジェクトを右クリックし発行を選択する。
--「既存のAzure Container Registry(ACR)」を選択して、~
以下のダイアログから発行をする。
--「既存の[[ACR>Azure Container Registry]]」を選択して、以下のダイアログから発行をする。
#ref(1.png,left,nowrap,コンテナ・イメージの発行,60%)
--&color(red){エラーが起きるので、以下の開発用の設定をして再実行。};~
開発用の設定:レジストリの管理者ユーザの有効化
>az acr update -n daisukenishinoacr --admin-enabled true
{...json...}
--イメージを確認する。
---ローカル
>docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
daisukenishinoacr.azurecr.io:443/webapplication1 latest f8253a6af02f 17 minutes ago 354MB
webapplication1 latest f8253a6af02f 17 minutes ago 354MB
---リモート~
ImageName
>az acr repository list --name daisukenishinoacr --output table
Result
---------------
webapplication1
Tag
>az acr repository show-tags --name daisukenishinoacr --repository webapplication1 --output table
Result
--------
latest
-タグを設定する。~
直ぐに発行しないで、プロファイル作成を~
選択すると初回からこちらを選択可能。
--設定
#ref(2.png,left,nowrap,タグの設定,60%)
--削除
---ローカル
>docker rmi <IMAGE ID> -f
---リモート
>az acr repository delete --name daisukenishinoacr --image webapplication1:latest
This operation will delete the manifest 'sha256:3ebc46eb04906582a80aaa89edde8611eefece5af2518756cf451db74223825e' and all the following images: 'webapplication1:latest'.
Are you sure you want to continue? (y/n): y
--再発行(前述)
--イメージ確認
---ローカル
>docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
daisukenishinoacr.azurecr.io:443/webapplication1 yyyymmddhhmmss a41aed558746 42 seconds ago 354MB
webapplication1 latest a41aed558746 42 seconds ago 354MB
---リモート
ImageName
>az acr repository list --name daisukenishinoacr --output table
Result
---------------
webapplication1
Tag
>az acr repository show-tags --name daisukenishinoacr --repository webapplication1 --output table
Result
--------
yyyymmddhhmmss
***(3-2) アプリをデプロイ(K8sへ) [#c43a6232]
-以下の様に、webapplication1.yamlを作成する。
--追加分(azure-vote-backを流用)
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: webapplication1-back
spec:
replicas: 1
template:
metadata:
labels:
app: webapplication1-back
spec:
nodeSelector:
"beta.kubernetes.io/os": linux
containers:
- name: webapplication1-back
image: redis
ports:
- containerPort: 6379
name: redis
---
apiVersion: v1
kind: Service
metadata:
name: webapplication1-back
spec:
ports:
- port: 6379
selector:
app: webapplication1-back
---
--オリジナル部分~
<Tag>は前述で言う「yyyymmddhhmmss」相当で置き換える。
apiVersion: apps/v1
kind: Deployment
metadata:
name: webapplication1
namespace: default
labels:
app: webapplication1
spec:
replicas: 1
selector:
matchLabels:
app: webapplication1
template:
metadata:
name: webapplication1
labels:
app: webapplication1
spec:
containers:
- name: webapplication1
image: daisukenishinoacr.azurecr.io/webapplication1:<Tag>
resources:
requests:
cpu: "250m"
memory: "512Mi"
limits:
cpu: "500m"
memory: "1Gi"
imagePullPolicy: Always
restartPolicy: Always
terminationGracePeriodSeconds: 30
---
apiVersion: v1
kind: Service
metadata:
name: webapplication1
labels:
app: webapplication1
spec:
type: LoadBalancer
ports:
- protocol: TCP
port: 80
selector:
app: webapplication1
-webapplication1.yamlの適用
>kubectl apply -f webapplication1.yaml
-webapplication1のEXTERNAL-IPの確認。
>kubectl get service --watch
-開発中にイメージを更新する場合、
--再発行(前述)
--タグを確認し(前述)
>az acr repository show-tags --name daisukenishinoacr --repository
webapplication1 --output table
Result
--------
yyyymmddhhmmss
--webapplication1.yamlの<Tag>を更新し、
---変更前
image: daisukenishinoacr.azurecr.io/webapplication1:<Tag>
---変更後
image: daisukenishinoacr.azurecr.io/webapplication1:yyyymmddhhmmss
--再適用する。
>kubectl apply -f webapplication1.yaml --force
***(4) アプリの構成 [#gf90a69e]
-イングレス コントローラー(AKS独自)の構成~
EXTERNAL-IPをFQDNに変更できる。
--HTTP アプリケーションルーティング アドオンのインストール~
(Azureポータルから DNS ゾーンが追加されたことを確認できる)
>az aks enable-addons --resource-group daisukenishino --name daisukenishinoacr --addons http_application_routing
--登録されている DNS ゾーン名を取得する。
>az aks show --resource-group daisukenishino --name daisukenishinoacr --query addonProfiles.httpApplicationRouting.config.HTTPApplicationRoutingZoneName -o table
Result
----------------------------------------
xxxxxxxxxxxxxxxxxxxx.japaneast.aksapp.io
--イングレス コントローラーの追加
--webapplication1.yamlの編集
---サービスのタイプを変更(LoadBalancerを削除)し、
---イングレス コントローラーを追加
--webapplication1.yamlの適用
>kubectrl apply -f webapplication1.yaml --force
--webapplication1のEXTERNAL-IPが<none>に変更されたことを確認。
>kubectl get svc
--FQDN名の確認。
>kubectl get ingress
--ブラウザからアクセス~
http://webapplication1.xxxxxxxxxxxxxxxxxxxx.japaneast.aksapp.io
--Azureポータルから DNS ゾーンにAレコードが追加されたことを確認できる。
-アプリケーションの複数台構成
--Viewで、@Environment.MachineName を使用して実行中のポッド名を表示
--再発行(前述)
--webapplication1.yamlの編集~
webapplication1のDeploymentを変更する。
---タグを更新
---replicas: 2に変更
--webapplication1.yamlの適用
>kubectrl apply -f webapplication1.yaml --force
--ブラウザよりアプリにアクセス。~
F5 で更新してポッド名が変わることを確認。
***(5) 複数ノードプールの構成 [#vf5857a6]
おいおいヤる予
***(6) ネットワークの構成 [#je22a90b]
おいおいヤる予
***(7) Gatewayの構成 [#j4a5ea16]
おいおいヤる予
***(8) ラベル、セレクターと名前空間 [#e436e00a]
おいおいヤる予
***(9) 自動スケール [#j7a9f25c]
おいおいヤる予
*その他のコンテンツ [#x5e9a9d1]
**[[Azure Kubernetes Service ワークショップ]] [#y3bf9858]
**[[AKSをセキュアに利用するためのテクニカルリファレンス]] [#ja388af4]
*参考 [#g27c1ff6]
-Azure Kubernetes Service 2019 ふりかえり~
https://www.slideshare.net/ToruMakabe/azure-kubernetes-service-2019
**Microsoft Docs [#za5e452c]
***チュートリアル [#cd044dc3]
-Kubernetes on Azure のチュートリアル
--1 - AKS 用にアプリケーションを準備する~
https://docs.microsoft.com/ja-jp/azure/aks/tutorial-kubernetes-prepare-app
--2 - コンテナー レジストリを作成する~
https://docs.microsoft.com/ja-jp/azure/aks/tutorial-kubernetes-prepare-acr
--3 - Kubernetes クラスターを作成する~
https://docs.microsoft.com/ja-jp/azure/aks/tutorial-kubernetes-deploy-cluster
--4 - アプリケーションを実行する~
https://docs.microsoft.com/ja-jp/azure/aks/tutorial-kubernetes-deploy-application
--5 - アプリケーションのスケールを変更する~
https://docs.microsoft.com/ja-jp/azure/aks/tutorial-kubernetes-scale
--6 - アプリケーションを更新する~
https://docs.microsoft.com/ja-jp/azure/aks/tutorial-kubernetes-app-update
--7 - クラスターをアップグレードする~
https://docs.microsoft.com/ja-jp/azure/aks/tutorial-kubernetes-upgrade-cluster
-SQL Server on Linux のチュートリアル
--Azure Kubernetes Services (AKS) を使用して Kubernetes に SQL Server コンテナーを配置する - SQL Server~
https://docs.microsoft.com/ja-jp/sql/linux/tutorial-sql-server-containers-kubernetes?view=sql-server-2017
***サポート ポリシー [#ec9de178]
-Azure Kubernetes Service (AKS) のサポート ポリシー~
https://docs.microsoft.com/ja-jp/azure/aks/support-policies
**Qiita(ASK を使いこなす) [#g22fa8b4]
-Azure Kubernetes Service (AKS) を使いこなす : 目次~
https://qiita.com/kenakamu/items/e155740aa60c85a3d867
***AKS チュートリアルの深堀 [#n150fe66]
上記のMicrosoft Docsのチュートリアルの深堀しているQiita記事(MS社員)。
-Kubernetes と AKS 概要~
https://qiita.com/kenakamu/items/8f43163d1a42aca62fb7
-アプリケーションの準備~
https://qiita.com/kenakamu/items/50193c1b642cb3339b46
-コンテナレジストリを作成する~
https://qiita.com/kenakamu/items/bb876f17e4f6ecaf370b
-AKS クラスターのデプロイ~
https://qiita.com/kenakamu/items/fb8adae1c5ddb906e0f2
-アプリケーションの実行~
https://qiita.com/kenakamu/items/cac80a548b0b43a270fa
-アプリケーションのスケーリング~
https://qiita.com/kenakamu/items/af537527d4d899a8f80e
-アプリケーションの更新~
https://qiita.com/kenakamu/items/f6b2de045b76cc05b809
***SQL Server 2017 を AKS で使う [#z89c63b0]
-ストレージの準備~
https://qiita.com/kenakamu/items/8d584e6da3e93929b1d9
-SQL のインストールと障害復旧の検証~
https://qiita.com/kenakamu/items/a05843d8e5efd13eb009
***AKS で asp.net core アプリケーション [#e695711a]
-事前準備~
https://qiita.com/kenakamu/items/20194ace476d873b2949
-ローカルで開発する~
https://qiita.com/kenakamu/items/f61ed635a77b673e8164
-アプリをデプロイ~
https://qiita.com/kenakamu/items/c1ff282992bfc778000d
-イングレスとアプリ複数ポッド構成~
https://qiita.com/kenakamu/items/19b5eb067c9d40e47b0b
-複数ノードプールの構成~
https://qiita.com/kenakamu/items/aee6748b6d15b8aab34f
-Azure CNI ネットワーク と Application Gateway~
https://qiita.com/kenakamu/items/f4c0fabea8044a6b28cb
-Application Gateway と Application Gateway Ingress Controller~
https://qiita.com/kenakamu/items/6997c894e6cce58f2ea2
-ラベル、セレクターと名前空間~
https://qiita.com/kenakamu/items/7003b6013779f1a5bdb6
-自動スケール
--概要とポッドの水平スケール~
https://qiita.com/kenakamu/items/29acb5c79c6700eed814
--クラスターのスケール~
https://qiita.com/kenakamu/items/a4fe3769605795c23c24
--Azure Container Instance との統合~
https://qiita.com/kenakamu/items/6f3ed4be598d1c2ea8c2
**Azure | SIOS Tech. Lab [#v9c16bbe]
https://tech-lab.sios.jp/archives/category/azure/
-Azure Kubernetes Serviceで最速k8s~
https://tech-lab.sios.jp/archives/18536
-Azure Kubernetes Service + Seleniumでお手軽負荷テスト環境~
https://tech-lab.sios.jp/archives/18591
-Azure Kubernetes Serviceで実現する超低予算~
&(ほぼ)フルマネージド&本格的なWordPress環境~
https://tech-lab.sios.jp/archives/18794
***NGINX [#e2ad4628]
-Azure Kubernetes ServiceでNGINX
--Ingressによる負荷分散~
https://tech-lab.sios.jp/archives/18638
--IngressのSSL証明書更新~
https://tech-lab.sios.jp/archives/18657
***共有ストレージ [#m49421d1]
-Azure Kubernetes Serviceでの共有ストレージ
--(NFS Server on VM編)~
https://tech-lab.sios.jp/archives/18739
--(Azure Files編)~
https://tech-lab.sios.jp/archives/18735
--(Azure NetApp Files編)~
https://tech-lab.sios.jp/archives/18741
***kubectl [#gc579585]
-Kubernetes(kubectl)
--KubernetesでDeploymentのRollback~
https://tech-lab.sios.jp/archives/18550
--KubernetesでDeploymentの色々なアップデート方法~
https://tech-lab.sios.jp/archives/18553
--KubernetesでRollingUpdateするためのPodの安全な終了~
https://tech-lab.sios.jp/archives/18730
**OSSコンソーシアム [#w809fb59]
***Blog [#n95d96ef]
-Docker for Windows上で Docker Composeでテストし、Open PaaSにデプロイできる~
--(1):https://www.osscons.jp/joweexgq6-537/
--(2):https://www.osscons.jp/jo6610sfd-537/
***Wiki [#x4a72daa]
-マイクロソフト系技術情報 Wiki(当該Wiki)
--[[Visual Studio Tools for Docker]]
--[[Visual Studio Kubernetes Tools]]
-.NET 開発基盤部会 Wiki
--[[Kubernetes>https://dotnetdevelopmentinfrastructure.osscons.jp/index.php?Kubernetes]]
---[[Helm Charts>https://dotnetdevelopmentinfrastructure.osscons.jp/index.php?Helm%20Charts]]
---[[Kompose>https://dotnetdevelopmentinfrastructure.osscons.jp/index.php?Kompose]]
---[[Compose on Kubernetes>https://dotnetdevelopmentinfrastructure.osscons.jp/index.php?Compose%20on%20Kubernetes]]
----
Tags: [[:クラウド]], [[:コンテナ]], [[:Azure]], [[:AKS]]
Tags: [[:クラウド]], [[:コンテナ]], [[:Azure]], [[:AKS]], [[:IaC]]