-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaks.tf
188 lines (154 loc) · 4.97 KB
/
aks.tf
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# aks and vmss examples from "https://github.com/iljoong/azure-terraform"
# Configure the Microsoft Azure Provider
provider "azurerm" {
subscription_id = var.subscription_id
client_id = var.client_id
client_secret = var.client_secret
tenant_id = var.tenant_id
features {}
}
# Create a resource group if it doesn’t exist
resource "azurerm_resource_group" "tfrg" {
name = "${var.prefix}-rg"
location = var.location
tags = {
environment = var.tag
}
}
# Create virtual network
resource "azurerm_virtual_network" "tfvnet" {
name = "${var.prefix}-vnet"
address_space = ["10.1.0.0/16"]
location = var.location
resource_group_name = azurerm_resource_group.tfrg.name
tags = {
environment = var.tag
}
}
resource "azurerm_subnet" "tfaksvnet" {
name = "aks-net"
virtual_network_name = azurerm_virtual_network.tfvnet.name
resource_group_name = azurerm_resource_group.tfrg.name
# 10.1.0.1 ~ 10.1.15.254
address_prefix = "10.1.0.0/20"
}
resource "azurerm_subnet_network_security_group_association" "tfaksvnet" {
subnet_id = azurerm_subnet.tfaksvnet.id
network_security_group_id = azurerm_network_security_group.tfaksnsg.id
}
resource "azurerm_subnet_route_table_association" "tfaksvnet" {
subnet_id = azurerm_subnet.tfaksvnet.id
route_table_id = azurerm_route_table.nattable.id
}
resource "azurerm_subnet" "tfjboxvnet" {
name = "jbox-subnet"
virtual_network_name = azurerm_virtual_network.tfvnet.name
resource_group_name = azurerm_resource_group.tfrg.name
address_prefix = "10.1.200.0/24"
}
# NSG
resource "azurerm_network_security_group" "tfaksnsg" {
name = "${var.prefix}-aksnsg"
location = var.location
resource_group_name = azurerm_resource_group.tfrg.name
security_rule {
name = "HTTP"
priority = 1000
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "80"
source_address_prefix = "Internet"
destination_address_prefix = "*"
}
tags = {
environment = var.tag
}
}
# UDR
resource "azurerm_route_table" "nattable" {
name = "${var.prefix}-natroutetable"
location = var.location
resource_group_name = azurerm_resource_group.tfrg.name
route {
name = "natrule1"
address_prefix = "10.100.0.0/14"
next_hop_type = "VirtualAppliance"
next_hop_in_ip_address = "10.10.1.1"
}
}
resource "azurerm_kubernetes_cluster" "tfaks" {
name = "${var.prefix}-aks"
location = var.location
resource_group_name = azurerm_resource_group.tfrg.name
dns_prefix = "${var.prefix}dns"
#kubernetes_version = "1.13.11"
default_node_pool {
name = "default"
node_count = 2
min_count = 2
max_count = 3
vm_size = "Standard_DS1_v2"
#os_type = "Linux"
os_disk_size_gb = 128
# Autoscale
type = "VirtualMachineScaleSets"
enable_auto_scaling = true
# AZ
availability_zones = [1, 2]
vnet_subnet_id = azurerm_subnet.tfaksvnet.id
}
linux_profile {
admin_username = var.admin_username
ssh_key {
key_data = var.admin_keydata
}
}
network_profile {
network_plugin = "azure"
load_balancer_sku = "standard"
}
service_principal {
client_id = var.client_id
client_secret = var.client_secret
}
tags = {
environment = var.tag
}
}
resource "azurerm_kubernetes_cluster_node_pool" "tfgpupool" {
name = "gpu"
kubernetes_cluster_id = azurerm_kubernetes_cluster.tfaks.id
node_count = 1
min_count = 1
max_count = 2
vm_size = "Standard_DS1_v2" #"Standard_NC6"
os_type = "Linux"
os_disk_size_gb = 128
# Autoscale
enable_auto_scaling = true
vnet_subnet_id = azurerm_subnet.tfaksvnet.id
}
data "azurerm_public_ip" "example" {
name = reverse(split("/", tolist(azurerm_kubernetes_cluster.example.network_profile.0.load_balancer_profile.0.effective_outbound_ips)[0]))[0]
resource_group_name = azurerm_kubernetes_cluster.example.node_resource_group
}
output "client_certificate" {
value = azurerm_kubernetes_cluster.tfaks.kube_config[0].client_certificate
}
output "kube_config" {
value = azurerm_kubernetes_cluster.tfaks.kube_config_raw
}
output "cluster_egress_ip" {
value = data.azurerm_public_ip.example.ip_address
}
resource "azurerm_container_registry" "example" {
name = "${var.prefix}registry"
resource_group_name = "${azurerm_resource_group.example.name}"
location = "${azurerm_resource_group.example.location}"
sku = "Standard"
}
output "login_server" {
value = "${azurerm_container_registry.example.login_server}"
}