LoginSignup
1
2

More than 3 years have passed since last update.

Azure Kubernetes Service(既存仮想ネットワーク)をAzure CLIで構築する

Posted at

Azure Kubernetes Serviceを既存仮想ネットワーク上に作成します。
ついでに、サービスエンドポイント経由でAzure SQL Databaseに繋がる環境も構築します。

この手順で出来上がるリソース

image.png

環境構築

PowerShell起動

  • PowerShellでAzure CLIを実行します。Linuxの場合は適宜置き換えてください。

Azure login

az login

環境変数設定

$RG = "[Resource Group Name]"

リソースグループ作成

az group create -l japaneast -n $RG

vNet作成

az network vnet create -g $RG -n [vNet Name] --address-prefix 192.168.1.0/24 --subnet-name [Subnet Name] --subnet-prefix 192.168.1.0/24

vNet Service Endpoint作成

az network vnet subnet update -g $RG --vnet-name [vNet Name] -n [Subnet Name] --service-endpoints Microsoft.Sql

ACR作成

az acr create -n [ACR Name] -g $RG --sku Basic

サービスプリンシパル作成

  • コマンド実行後に表示されるappIdとpasswordは後の手順で使います。
az ad sp create-for-rbac -n "[Service Principal Name]" --skip-assignment --years 10

サービスプリンシパルにACRPull権限付与

$APP = "[appId]"
$SECRET = "[password]"
$ACRID = az acr show -n [ACR Name] --query id --output tsv
az role assignment create --assignee $APP --scope $ACRID --role acrpull

Log Analytics作成

Log Analytics WorkSpace ID取得

$WORKSPACE = az resource list -l japaneast -n [Log Analytics Name] -g $RG --query [].id -o tsv

サブネットID取得

$SUBNETID = az network vnet subnet show -n [Subnet Name] -g $RG --vnet-name [vNet Name] --query id -o tsv

AKS作成

az aks create `
    -n [AKS Cluster Name] `
    -g $RG `
    -s Standard_B2s `
    --node-count 2 `
    --service-principal $APP `
    --client-secret $SECRET `
    --generate-ssh-keys `
    --kubernetes-version 1.13.5 `
    --dns-name-prefix [DNS Prefix] `
    --vnet-subnet-id $SUBNETID `
    --network-plugin azure `
    --service-cidr 172.16.100.0/24 `
    --dns-service-ip 172.16.100.10 `
    --docker-bridge-address 172.16.101.1/24 `
    --workspace-resource-id $WORKSPACE `
    --enable-addons monitoring

SQL Server作成

az sql server create -g $RG -n [SQL Server Name] -u [Admin User Name] -p [Admin User Password]

SQL Server FW設定

az sql server firewall-rule create -g $RG -s [SQL Server Name] -n [FW Rule Name] --start-ip-address [Start IpAddr] --end-ip-address [End IpAddr]

SQL Server仮想ネットワークルール追加

az sql server vnet-rule create -g $RG -s [SQL Server Name] -n [Network Rule Name] --subnet $SUBNETID

SQL Database作成

az sql db create -g $RG -s [SQL Server Name] -n [SQL Database Name] --service-objective Basic

※ 照合順序をデフォルトから変えたい場合は、Azure PortalかARM Templateから作るしかなさそうです。

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