Aks bash

From UVOO Tech Wiki
Revision as of 23:30, 3 June 2024 by Busk (talk | contribs) (Created page with "``` #!/bin/bash # Variables RESOURCE_GROUP="myResourceGroup" AKS_CLUSTER_NAME="myAKSCluster" LOCATION="eastus" VNET_NAME="myVNet" SUBNET_NAME="mySubnet" # Create resource gr...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
#!/bin/bash

# Variables
RESOURCE_GROUP="myResourceGroup"
AKS_CLUSTER_NAME="myAKSCluster"
LOCATION="eastus"
VNET_NAME="myVNet"
SUBNET_NAME="mySubnet"

# Create resource group (if it doesn't exist)
az group create --name $RESOURCE_GROUP --location $LOCATION

# Get the Virtual Network ID
VNET_ID=$(az network vnet show --resource-group $RESOURCE_GROUP --name $VNET_NAME --query id --output tsv)

# Get the Subnet ID
SUBNET_ID=$(az network vnet subnet show --resource-group $RESOURCE_GROUP --vnet-name $VNET_NAME --name $SUBNET_NAME --query id --output tsv)

# Create AKS cluster with Calico network policy and private cluster option
az aks create \
    --resource-group $RESOURCE_GROUP \
    --name $AKS_CLUSTER_NAME \
    --location $LOCATION \
    --enable-managed-identity \
    --vnet-subnet-id $SUBNET_ID \
    --network-plugin azure \
    --network-policy calico \
    --node-count 3 \
    --vnet-subnet-id $SUBNET_ID \
    --generate-ssh-keys \
    --enable-private-cluster

# Get the credentials for the new AKS cluster
az aks get-credentials --resource-group $RESOURCE_GROUP --name $AKS_CLUSTER_NAME

echo "AKS cluster $AKS_CLUSTER_NAME created with Calico network policy and connected to VNet $VNET_NAME in subnet $SUBNET_NAME. The cluster is private."