Skip to content

Instantly share code, notes, and snippets.

@ruzickap
Created March 15, 2023 07:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ruzickap/9e1d3253e638e8c0ec393e28fc8c44ed to your computer and use it in GitHub Desktop.
Save ruzickap/9e1d3253e638e8c0ec393e28fc8c44ed to your computer and use it in GitHub Desktop.
Deploy Azure AKS
#!/usr/bin/env bash
export AZURE_LOCATION=westeurope
export CLUSTER_FQDN="ruzickap2aks.k8s.mylabs.dev"
# CLUSTER_NAME must have max 12 character due to "--nodepool-name" parameter
export CLUSTER_NAME="${CLUSTER_FQDN%%.*}"
export KUBECONFIG="/tmp/kubeconfig-${CLUSTER_NAME}.conf"
set -euxo pipefail
# az aks get-versions --location=westeurope | jq
if ! az aks list --query '[].name' | grep -q "${CLUSTER_NAME}" ; then
az group create -n "${CLUSTER_NAME}" -l "${AZURE_LOCATION}"
az aks create \
--auto-upgrade-channel stable \
--enable-cluster-autoscaler \
--kubernetes-version 1.26.0 \
--max-count 5 \
--min-count 2 \
--name "${CLUSTER_NAME}" \
--node-count 2 \
--node-osdisk-size 30 \
--node-vm-size Standard_B2ms \
--nodepool-name "${CLUSTER_NAME}" \
--nodepool-tags "Owner=petr.ruzicka@gmail.com" "Environment=dev" "Cluster_FQDN=${CLUSTER_FQDN}" \
--resource-group "${CLUSTER_NAME}" \
--tags "Owner=petr.ruzicka@gmail.com" "Environment=dev" "Cluster_FQDN=${CLUSTER_FQDN}"
fi
az aks get-credentials --resource-group "${CLUSTER_NAME}" --name "${CLUSTER_NAME}" --admin --file "${KUBECONFIG}" --overwrite-existing
cat << EOF
*** Cluster DELETE
export CLUSTER_FQDN="ruzickap2aks.k8s.mylabs.dev"
az group delete --resource-group "${CLUSTER_FQDN%%.*}" --yes
EOF
echo -e "\n*****\n export KUBECONFIG=${KUBECONFIG} \n*****\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment