Skip to content

Commit 80f9d12

Browse files
authored
Merge pull request #160 from yunkon-kim/250626-11
Add Azure Kubernetes Service (AKS) example
2 parents 9605bde + de8acfc commit 80f9d12

File tree

7 files changed

+182
-7
lines changed

7 files changed

+182
-7
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ terraform.tfvars.json
3535
*credential*
3636
project-gcp.txt
3737
*.pem
38+
kubeconfig
3839

3940
# Sensitive data
4041
.env

docker-compose.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ services:
1616
published: 8055
1717
protocol: tcp
1818
env_file:
19-
- ./secrets/credentials # AWS credential
20-
- ./secrets/credential-azure.env # Azure credential
21-
- ./secrets/credential-alibaba.env # Alibaba credential
22-
- ./secrets/credential-tencent.env # Tencent credential
23-
- ./secrets/credential-ibm.env # IBM credential
24-
- ./secrets/credential-ncp.env # NCP credential
19+
- ${HOME}/.cloud-barista/secrets/credentials # AWS credential
20+
- ${HOME}/.cloud-barista/secrets/credential-azure.env # Azure credential
21+
- ${HOME}/.cloud-barista/secrets/credential-alibaba.env # Alibaba credential
22+
- ${HOME}/.cloud-barista/secrets/credential-tencent.env # Tencent credential
23+
- ${HOME}/.cloud-barista/secrets/credential-ibm.env # IBM credential
24+
- ${HOME}/.cloud-barista/secrets/credential-ncp.env # NCP credential
2525
volumes:
26-
- ./secrets/credential-gcp.json:/app/secrets/credential-gcp.json:ro # GCP credential
26+
- ${HOME}/.cloud-barista/secrets/credential-gcp.json:/app/secrets/credential-gcp.json:ro # GCP credential
2727
- ./container-volume/mc-terrarium-container/.terrarium:/app/.terrarium
2828
- /etc/ssl/certs:/etc/ssl/certs:ro
2929
environment:
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Creating a Service Account
2+
apiVersion: v1
3+
kind: ServiceAccount
4+
metadata:
5+
name: admin-user
6+
namespace: kubernetes-dashboard
7+
8+
---
9+
# Creating a ClusterRoleBinding
10+
apiVersion: rbac.authorization.k8s.io/v1
11+
kind: ClusterRoleBinding
12+
metadata:
13+
name: admin-user
14+
roleRef:
15+
apiGroup: rbac.authorization.k8s.io
16+
kind: ClusterRole
17+
name: cluster-admin
18+
subjects:
19+
- kind: ServiceAccount
20+
name: admin-user
21+
namespace: kubernetes-dashboard
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Terraform and Azure Provider configuration
2+
terraform {
3+
required_providers {
4+
azurerm = {
5+
source = "hashicorp/azurerm"
6+
version = "~> 3.0"
7+
}
8+
}
9+
}
10+
11+
provider "azurerm" {
12+
features {}
13+
}
14+
15+
# Data source to get existing Resource Group
16+
data "azurerm_resource_group" "existing" {
17+
name = var.resource_group_name
18+
}
19+
20+
# Data source to get existing VNet
21+
data "azurerm_virtual_network" "existing" {
22+
name = var.vnet_name
23+
resource_group_name = var.vnet_resource_group_name
24+
}
25+
26+
# Data source to get existing subnet
27+
data "azurerm_subnet" "existing" {
28+
name = var.subnet_name
29+
virtual_network_name = var.vnet_name
30+
resource_group_name = var.vnet_resource_group_name
31+
}
32+
33+
# Create AKS cluster using existing infrastructure
34+
resource "azurerm_kubernetes_cluster" "aks" {
35+
name = var.cluster_name
36+
location = data.azurerm_resource_group.existing.location
37+
resource_group_name = data.azurerm_resource_group.existing.name
38+
dns_prefix = var.dns_prefix
39+
40+
# Default node pool configuration
41+
default_node_pool {
42+
name = "default"
43+
node_count = 2 # 2 worker nodes
44+
vm_size = "Standard_D2_v2" # Good general-purpose VM size
45+
vnet_subnet_id = data.azurerm_subnet.existing.id
46+
}
47+
48+
# Network profile configuration (required when using existing VNet)
49+
network_profile {
50+
network_plugin = "azure"
51+
service_cidr = var.service_cidr
52+
dns_service_ip = var.dns_service_ip
53+
}
54+
55+
# Cluster identity configuration (using system-managed identity)
56+
# Required permissions for AKS to access other Azure resources (e.g., storage, network)
57+
identity {
58+
type = "SystemAssigned"
59+
}
60+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Output resource group name
2+
output "resource_group_name" {
3+
value = data.azurerm_resource_group.existing.name
4+
}
5+
6+
# Output cluster name
7+
output "cluster_name" {
8+
value = azurerm_kubernetes_cluster.aks.name
9+
}
10+
11+
# Output Kubeconfig file content
12+
# The azurerm provider provides kubeconfig content directly through the 'kube_config_raw' attribute, which is very convenient.
13+
output "kube_config" {
14+
description = "Kubeconfig content to connect to the AKS cluster."
15+
sensitive = true # Contains sensitive information, so it won't be exposed in the terminal
16+
value = azurerm_kubernetes_cluster.aks.kube_config_raw
17+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Example configuration for using existing Azure infrastructure
2+
# Copy this file to terraform.tfvars and update with your actual values
3+
4+
# Existing Resource Group where AKS will be deployed
5+
resource_group_name = "my-aks-rg"
6+
7+
# Azure region
8+
location = "my-aks-region"
9+
10+
# AKS cluster configuration
11+
cluster_name = "my-aks-cluster"
12+
dns_prefix = "my-aks-dns" # Must be globally unique
13+
14+
# Existing network infrastructure
15+
vnet_resource_group_name = "my-network-rg" # Can be same as resource_group_name
16+
vnet_name = "my-aks-vnet" # Virtual Network name
17+
subnet_name = "my-aks-subnet" # Subnet name for AKS nodes
18+
19+
# Kubernetes service networking (must not overlap with existing VNet CIDR)
20+
service_cidr = "10.7.0.0/16" # Adjust based on your network setup
21+
dns_service_ip = "10.7.0.10" # Must be within service_cidr
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
variable "resource_group_name" {
2+
description = "The name of the existing Azure Resource Group where AKS will be deployed."
3+
type = string
4+
# No default - must be provided
5+
}
6+
7+
variable "location" {
8+
description = "The Azure region to deploy AKS to."
9+
type = string
10+
default = "Korea Central" # Korea Central region
11+
}
12+
13+
variable "cluster_name" {
14+
description = "The name for the AKS cluster."
15+
type = string
16+
default = "my-first-aks-cluster"
17+
}
18+
19+
variable "dns_prefix" {
20+
description = "A unique DNS prefix for the AKS cluster."
21+
type = string
22+
default = "myaks-cluster-dns" # Must be unique within the region
23+
}
24+
25+
# Network configuration variables (required for existing infrastructure)
26+
variable "vnet_resource_group_name" {
27+
description = "The name of the resource group containing the existing virtual network."
28+
type = string
29+
# No default - must be provided when using existing VNet
30+
}
31+
32+
variable "vnet_name" {
33+
description = "The name of the existing virtual network to use for AKS."
34+
type = string
35+
# No default - must be provided
36+
}
37+
38+
variable "subnet_name" {
39+
description = "The name of the existing subnet to use for AKS nodes."
40+
type = string
41+
# No default - must be provided
42+
}
43+
44+
# Optional: Kubernetes service networking configuration
45+
variable "service_cidr" {
46+
description = "The CIDR range for Kubernetes services. Only used when creating a new network."
47+
type = string
48+
default = "10.1.0.0/16"
49+
}
50+
51+
variable "dns_service_ip" {
52+
description = "The IP address for the Kubernetes DNS service. Must be within service_cidr range."
53+
type = string
54+
default = "10.1.0.10"
55+
}

0 commit comments

Comments
 (0)