Fixing article
This commit is contained in:
parent
4832632b2c
commit
1f4ae04892
77
quickstart/201-k8s-cluster-with-tf-and-aks/main.tf
Normal file
77
quickstart/201-k8s-cluster-with-tf-and-aks/main.tf
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
# Generate random resource group name
|
||||||
|
resource "random_pet" "rg_name" {
|
||||||
|
prefix = var.resource_group_name_prefix
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "azurerm_resource_group" "rg" {
|
||||||
|
name = random_pet.rg_name.id
|
||||||
|
location = var.resource_group_location
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "random_id" "log_analytics_workspace_name_suffix" {
|
||||||
|
byte_length = 8
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "azurerm_log_analytics_workspace" "test" {
|
||||||
|
# The WorkSpace name has to be unique across the whole of azure, not just the current subscription/tenant.
|
||||||
|
name = "${var.log_analytics_workspace_name}-${random_id.log_analytics_workspace_name_suffix.dec}"
|
||||||
|
location = var.log_analytics_workspace_location
|
||||||
|
resource_group_name = azurerm_resource_group.k8s.name
|
||||||
|
sku = var.log_analytics_workspace_sku
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "azurerm_log_analytics_solution" "test" {
|
||||||
|
solution_name = "ContainerInsights"
|
||||||
|
location = azurerm_log_analytics_workspace.test.location
|
||||||
|
resource_group_name = azurerm_resource_group.k8s.name
|
||||||
|
workspace_resource_id = azurerm_log_analytics_workspace.test.id
|
||||||
|
workspace_name = azurerm_log_analytics_workspace.test.name
|
||||||
|
|
||||||
|
plan {
|
||||||
|
publisher = "Microsoft"
|
||||||
|
product = "OMSGallery/ContainerInsights"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "azurerm_kubernetes_cluster" "k8s" {
|
||||||
|
name = var.cluster_name
|
||||||
|
location = azurerm_resource_group.k8s.location
|
||||||
|
resource_group_name = azurerm_resource_group.k8s.name
|
||||||
|
dns_prefix = var.dns_prefix
|
||||||
|
|
||||||
|
linux_profile {
|
||||||
|
admin_username = "ubuntu"
|
||||||
|
|
||||||
|
ssh_key {
|
||||||
|
key_data = file(var.ssh_public_key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
default_node_pool {
|
||||||
|
name = "agentpool"
|
||||||
|
node_count = var.agent_count
|
||||||
|
vm_size = "Standard_D2_v2"
|
||||||
|
}
|
||||||
|
|
||||||
|
service_principal {
|
||||||
|
client_id = var.aks_service_principal_app_id
|
||||||
|
client_secret = var.aks_service_principal_client_secret
|
||||||
|
}
|
||||||
|
|
||||||
|
addon_profile {
|
||||||
|
oms_agent {
|
||||||
|
enabled = true
|
||||||
|
log_analytics_workspace_id = azurerm_log_analytics_workspace.test.id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
network_profile {
|
||||||
|
load_balancer_sku = "Standard"
|
||||||
|
network_plugin = "kubenet"
|
||||||
|
}
|
||||||
|
|
||||||
|
tags = {
|
||||||
|
Environment = "Development"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
33
quickstart/201-k8s-cluster-with-tf-and-aks/outputs.tf
Normal file
33
quickstart/201-k8s-cluster-with-tf-and-aks/outputs.tf
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
output "resource_group_name" {
|
||||||
|
value = azurerm_resource_group.rg.name
|
||||||
|
}
|
||||||
|
|
||||||
|
output "client_key" {
|
||||||
|
value = azurerm_kubernetes_cluster.k8s.kube_config.0.client_key
|
||||||
|
}
|
||||||
|
|
||||||
|
output "client_certificate" {
|
||||||
|
value = azurerm_kubernetes_cluster.k8s.kube_config.0.client_certificate
|
||||||
|
}
|
||||||
|
|
||||||
|
output "cluster_ca_certificate" {
|
||||||
|
value = azurerm_kubernetes_cluster.k8s.kube_config.0.cluster_ca_certificate
|
||||||
|
}
|
||||||
|
|
||||||
|
output "cluster_username" {
|
||||||
|
value = azurerm_kubernetes_cluster.k8s.kube_config.0.username
|
||||||
|
}
|
||||||
|
|
||||||
|
output "cluster_password" {
|
||||||
|
value = azurerm_kubernetes_cluster.k8s.kube_config.0.password
|
||||||
|
}
|
||||||
|
|
||||||
|
output "kube_config" {
|
||||||
|
value = azurerm_kubernetes_cluster.k8s.kube_config_raw
|
||||||
|
sensitive = true
|
||||||
|
}
|
||||||
|
|
||||||
|
output "host" {
|
||||||
|
value = azurerm_kubernetes_cluster.k8s.kube_config.0.host
|
||||||
|
}
|
||||||
|
|
14
quickstart/201-k8s-cluster-with-tf-and-aks/providers.tf
Normal file
14
quickstart/201-k8s-cluster-with-tf-and-aks/providers.tf
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
terraform {
|
||||||
|
required_version = ">=1.0"
|
||||||
|
|
||||||
|
required_providers {
|
||||||
|
azurerm = {
|
||||||
|
source = "hashicorp/azurerm"
|
||||||
|
version = "~>3.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
provider "azurerm" {
|
||||||
|
features {}
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
aks_service_principal_app_id = "<service_principal_app_id>"
|
||||||
|
|
||||||
|
aks_service_principal_client_secret = "<service_principal_password>"
|
||||||
|
|
||||||
|
aks_service_principal_object_id = "<service_principal_object_id>"
|
61
quickstart/201-k8s-cluster-with-tf-and-aks/variables.tf
Normal file
61
quickstart/201-k8s-cluster-with-tf-and-aks/variables.tf
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
variable "resource_group_name_prefix" {
|
||||||
|
default = "rg"
|
||||||
|
description = "Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription."
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "resource_group_location" {
|
||||||
|
default = "eastus"
|
||||||
|
description = "Location of the resource group."
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "agent_count" {
|
||||||
|
default = 3
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "ssh_public_key" {
|
||||||
|
default = "~/.ssh/id_rsa.pub"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "dns_prefix" {
|
||||||
|
default = "k8stest"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "cluster_name" {
|
||||||
|
default = "k8stest"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "resource_group_name" {
|
||||||
|
default = "azure-k8stest"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "location" {
|
||||||
|
default = "Central US"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "log_analytics_workspace_name" {
|
||||||
|
default = "testLogAnalyticsWorkspaceName"
|
||||||
|
}
|
||||||
|
|
||||||
|
# refer https://azure.microsoft.com/global-infrastructure/services/?products=monitor for log analytics available regions
|
||||||
|
variable "log_analytics_workspace_location" {
|
||||||
|
default = "eastus"
|
||||||
|
}
|
||||||
|
|
||||||
|
# refer https://azure.microsoft.com/pricing/details/monitor/ for log analytics pricing
|
||||||
|
variable "log_analytics_workspace_sku" {
|
||||||
|
default = "PerGB2018"
|
||||||
|
}
|
||||||
|
|
||||||
|
# these following three entries are placeholder references; we will specify values later in terraform.tfvars
|
||||||
|
variable "aks_service_principal_app_id" {
|
||||||
|
default = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "aks_service_principal_client_secret" {
|
||||||
|
default = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "aks_service_principal_object_id" {
|
||||||
|
default = ""
|
||||||
|
}
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user