Skip to content

Instantly share code, notes, and snippets.

View AymenSegni's full-sized avatar

asegni AymenSegni

View GitHub Profile
resource "azurerm_kubernetes_cluster" "cluster" {
name = var.cluster_name
location = var.location
resource_group_name = var.resource_group_name
dns_prefix = var.dns_prefix
kubernetes_version = var.kubernetes_version
default_node_pool {
name = var.agent_pool_name
variable "dns_prefix" {
description = "DNS prefix"
}
variable "location" {
description = "azure location to deploy resources"
}
variable "cluster_name" {
description = "AKS cluster name"
}
variable "resource_group_name" {
output "azurerm_kubernetes_cluster_id" {
value = azurerm_kubernetes_cluster.cluster.id
}
output "azurerm_kubernetes_cluster_fqdn" {
value = azurerm_kubernetes_cluster.cluster.fqdn
}
output "azurerm_kubernetes_cluster_node_resource_group" {
value = azurerm_kubernetes_cluster.cluster.node_resource_group
# Cluster Resource Group
resource "azurerm_resource_group" "aks" {
name = var.resource_group_name
location = var.location
}
# AKS Cluster Network
module "aks_network" {
source = "../modules/aks_network"
subnet_name = var.subnet_name
terraform {
backend "azurerm" {}
}
provider "azurerm" {
version = "~> 2.4"
features {}
}
#!/bin/bash
# Provide your own unique aksname within the Azure AD tenant
aksname="run-it-on-cloud"
resourcegroup="runItOnCloud"
location="westeurope"
# Create the Azure AD application Server
serverApplicationId=$(az ad app create \
--display-name "${aksname}Server" \
resource "azurerm_kubernetes_cluster" "cluster" {
name = var.cluster_name
location = var.location
resource_group_name = var.resource_group_name
dns_prefix = var.dns_prefix
kubernetes_version = var.kubernetes_version
agent_pool_profile {
name = var.agent_pool_name
count = var.node_count
# Cluster Resource Group
resource "azurerm_resource_group" "aks" {
name = var.resource_group_name
location = var.location
}
# AKS Cluster Network
module "aks_network" {
source = "../modules/aks_network"
subnet_name = var.subnet_name
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: contoso-cluster-admins
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- apiGroup: rbac.authorization.k8s.io
kind: NetworkPolicy
apiVersion: networking.k8s.io/v1
metadata:
name: backend-policy
namespace: development
spec:
podSelector:
matchLabels:
app: webapp
role: backend