オウルです。
今回はパブリッククラウドであるAzure・AWS(Amazon Web Services)・GCP(Google Cloud Platform)のクラウドコンピューティングの紹介です。その中で比較的イメージし易いIaaSの仮想マシンの紹介となります。ローカル環境にHyper-V(Microsoft)、Oracle VM VirtualBox、VMwareを利用して仮想マシンを動作させている方もいらっしゃるのではないでしょうか。簡単に言うとデプロイ先がローカル⇒クラウドへと変わっただけです。後半ではAzureの仮想マシンをデプロイするサンプルを紹介します。
Azure・AWS・GCP 仮想マシン
Azure
AWS
GCP
Azure Virtual Machines
EC2※1
Compute Engine
※1 EC2:Elastic Compute Cloudインスタンス
各パブリッククラウドの仮想マシンは必要に応じたスペックを選択可能です。また、名称は違いますが、「シリーズ」「インスタンスタイプ」「マシンタイプ」はスペック選択という意味でほぼ同義です。
Azure
AWS
GCP
※リンクをクリックすると公式サイトに遷移します。
ポイント
Azure、AWSは予め定義されたスペックからの選択になりますが、唯一GCPのみ、カスタムマシンタイプ(vCPU・メモリ)が可能です。
仮想マシンの従量課金
ここでは各仮想マシンの具体的な従量課金の紹介は割愛します。理由としては主に以下になります。
- 各仮想マシンのスペックの定義は全く同じではない※1
- 各パブリッククラウドの料金は変動する※2
- 各パブリッククラウドで割引の特典が存在する
※1 例えばGCPではWindowsServerイメージの場合、1コアあたり$0.04 米ドル/時間が追加で発生します(n1-standard-2:2 x $0.04 米ドル/時間)
※2 例としてAWSの料金値下げのお知らせです。
正確な料金を知る必要がある場合は、各パブリッククラウドが提供している下記の公式見積ツールをご利用ください。
仮想マシンのコストを抑えるポイント
Azureでは従量課金 < 1年予約 < 3年予約とコストを抑えることが可能です。AWS、GCPも確約利用割引という概念があり、同様の考え方でコストを抑えることが可能です。
例)スペック:D2 v3 2vCPU 8GiB RAM(ハイブリッド特典ありの場合)
従量課金
1年予約
3年予約
$0.096/時間
$0.055/時間
$0.037/時間
コスト見積ツール
Azure
AWS
GCP
仮想マシンのデプロイ
各パブリッククラウドはオペレーションツールとしてWebコンソールがあります。上記でリンクを貼っている見積りツールのUIとWebコンソールのUIは似たデザインだと個人的に思います。今回は、Azure Virtual Machinesをデプロイします。Webコンソール(Azureポータル)からポチポチっとクリックで簡単にデプロイできますが、Infrastructure as Code の学習も兼ねて、ARM(Azure Resource Manager)テンプレート機能でデプロイしてみます。
東日本リージョンにリソースグループを作成
1 |
az group create --name myResourceGroup --location japaneast |
Azure Virtual Machinesをデプロイ
- デプロイ名は適当な名前を指定してください。
- テンプレートファイルは下にあるMyComputer.jsonファイルを指定してください。
- パラメータファイルは下にあるMyComputerParameters.jsonを指定してください。
1 2 3 4 5 |
az group deployment create \ --name "デプロイ名" \ --resource-group myResourceGroup \ --template-file テンプレートファイル \ --parameters @パラメータファイル |
テンプレートファイルの作成
アドレス空間、サブネットのCIDRは必要に応じて編集してください。
RDPのsourceAddressPrefixは必要に応じて編集してください。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
{ "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { "adminUsername": { "type": "string" }, "adminPassword": { "type": "securestring" } }, "variables": { "publicIpName": "[concat(resourceGroup().name,'-pip-',uniquestring(resourceGroup().id))]", "domainName": "[concat(resourceGroup().name,'-dns-',uniquestring(resourceGroup().id))]", "vNetName": "[concat(resourceGroup().name,'-vnet-',uniquestring(resourceGroup().id))]", "vnetID": "[resourceId('Microsoft.Network/virtualNetworks',variables('vNetName'))]", "subnetName": "[concat('subnet-',uniquestring(resourceGroup().id))]", "subnetRef": "[concat(variables('vnetID'),'/subnets/',variables('subnetName'))]" , "nicName": "[concat(resourceGroup().name,'-nic-',uniquestring(resourceGroup().id))]", "vmName": "[concat(resourceGroup().name,'-vm-',uniquestring(resourceGroup().id))]", "computerName": "[concat(resourceGroup().name,'-vm')]", "managedOSDiskName": "[concat('managedOsDisk-',variables('vmName'))]", "nstName": "[concat(resourceGroup().name,'-nst-',uniquestring(resourceGroup().id))]" }, "resources": [ { "apiVersion": "2016-03-30", "type": "Microsoft.Network/publicIPAddresses", "name": "[variables('publicIpName')]", "location": "[resourceGroup().location]", "properties": { "publicIPAllocationMethod": "Dynamic", "dnsSettings": { "domainNameLabel": "[variables('domainName')]" } } }, { "apiVersion": "2016-03-30", "type": "Microsoft.Network/virtualNetworks", "name": "[variables('vNetName')]", "location": "[resourceGroup().location]", "properties": { "addressSpace": { "addressPrefixes": [ "10.6.0.0/16" ] }, "subnets": [ { "name": "[variables('subnetName')]", "properties": { "addressPrefix": "10.6.0.0/24" } } ] } }, { "apiVersion": "2016-03-30", "type": "Microsoft.Network/networkInterfaces", "name": "[variables('nicName')]", "location": "[resourceGroup().location]", "dependsOn": [ "[resourceId('Microsoft.Network/publicIPAddresses/', variables('publicIpName'))]", "[resourceId('Microsoft.Network/virtualNetworks/', variables('vNetName'))]", "[resourceId('Microsoft.Network/networkSecurityGroups', variables('nstName'))]" ], "properties": { "ipConfigurations": [ { "name": "ipconfig1", "properties": { "privateIPAllocationMethod": "Dynamic", "publicIPAddress": { "id": "[resourceId('Microsoft.Network/publicIPAddresses', variables('publicIpName'))]" }, "subnet": { "id": "[variables('subnetRef')]" } } } ], "networkSecurityGroup": { "id": "[resourceId('Microsoft.Network/networkSecurityGroups', variables('nstName'))]" } } }, { "apiVersion": "2016-04-30-preview", "type": "Microsoft.Compute/virtualMachines", "name": "[variables('vmName')]", "location": "[resourceGroup().location]", "dependsOn": [ "[resourceId('Microsoft.Network/networkInterfaces/', variables('nicName'))]" ], "properties": { "hardwareProfile": { "vmSize": "Standard_DS1" }, "osProfile": { "computerName": "[variables('computerName')]", "adminUsername": "[parameters('adminUsername')]", "adminPassword": "[parameters('adminPassword')]" }, "storageProfile": { "imageReference": { "publisher": "MicrosoftWindowsServer", "offer": "WindowsServer", "sku": "2016-Datacenter", "version": "latest" }, "osDisk": { "name": "[variables('managedOSDiskName')]", "caching": "ReadWrite", "createOption": "FromImage" } }, "networkProfile": { "networkInterfaces": [ { "id": "[resourceId('Microsoft.Network/networkInterfaces',variables('nicName'))]" } ] } } }, { "apiVersion": "2016-03-30", "type": "Microsoft.Network/networkSecurityGroups", "name": "[variables('nstName')]", "location": "[resourceGroup().location]", "properties": { "securityRules": [ { "name": "HTTP", "properties": { "description": "Allow HTTP", "protocol": "Tcp", "sourcePortRange": "*", "destinationPortRange": "80", "sourceAddressPrefix": "*", "destinationAddressPrefix": "*", "access": "Allow", "priority": 100, "direction": "Inbound" } }, { "name": "HTTPS", "properties": { "description": "Allow HTTPS", "protocol": "Tcp", "sourcePortRange": "*", "destinationPortRange": "443", "sourceAddressPrefix": "*", "destinationAddressPrefix": "*", "access": "Allow", "priority": 101, "direction": "Inbound" } }, { "name": "RDP", "properties": { "description": "Allow RDP", "protocol": "Tcp", "sourcePortRange": "*", "destinationPortRange": "3389", "sourceAddressPrefix": "***.***.***.***", "destinationAddressPrefix": "*", "access": "Allow", "priority": 102, "direction": "Inbound" } } ] } } ] } |
パラメータファイルの作成
“adminUsername”、”adminPassword”を編集してください。
1 2 3 4 5 6 7 8 |
{ "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json", "contentVersion": "1.0.0.0", "parameters": { "adminUsername": { "value": "azureuser" }, "adminPassword": { "value": "hogehoge" } } } |
リソースグループの削除
1 |
az group delete --name myResourceGroup --no-wait |
今回はイメージを掴むために簡単に仮想マシンを紹介しましたが、実はクラウドストレージを考慮する必要があります。そのあたりも含めて継続的に具体的な利用方法・説明を紹介できればと考えています。次回はDocker + Kubernetesの環境をローカルに構築して簡単なDockerコンテナをデプロイする方法を紹介したいと思います。
ローカル環境にKubernetesの環境を準備するのは、こちらの記事を参考にしてください。