If you are interested in cloud computing you have and maybe even read a few blogs about this cool thing called “Kubernetes”. It’s all good and fancy, but it’s best to actually lay your hands on it and experiment with that it has to offer.
A quick search for “try out Kubernetes” doesn’t really help, so what can you do to get Kubernetes out for a spin without installing lots of software on your machine and not paying a penny? Well, there is an easy way! Take advantage of cloud computing and see how it is to be at the helm of everyone’s favorite containers’ orchestrator!
Prerequisites
- Create free Azure subscription. This will give you access to Azure Kubernetes Service where you can get your hands dirty with Kubernetes. You can do the same creating Kubernetes clusters in Google Cloud (GCP) or Amazon Web Services (AWS).
- Install Terraform CLI. This is required to create and destroy resources you will need to check out Kubernetes.
- Install kubectl. This will enable you to communicate with your kubernetes cluster.
Let’s get to it!
- Create Azure resources. Please note that commands assume Linux bash/zsh, so if you are on windows use WSL or git bash.
# Create general purpose V2 storage accountaccountName=fancyaccountmanemustbeunique123
rg=uniquergname123az group create — name $rg — location westeurope — output jsonaz storage account create \
-- name $accountName \
-- resource-group $rg \
-- location westeurope \
-- sku Standard_RAGRS \
-- kind StorageV2 # Create container to host terraform state
# Retrieve storage account key:accountKey=$(az storage account keys list — account-name $accountName — resource-group $rg \
-- query “[?keyName == ‘key1’].value” -o tsv)az storage container create -n tfstate — account-name $accountName — account-key $accountKeyterraform init -backend-config=”storage_account_name=$accountName” \
- backend-config=”container_name=tfstate” \
- backend-config=”access_key=$accountKey” \
- backend-config=”key=dev.tfstate”
2. Run terraform plan -out out.plan
- prepare terraform deployment
3. Run terraform apply out.plan
- deploy AKS and store terraform state in the storage container created in step 1
4. Run az aks get-credentials -g azure-k8stest -n k8stest
to merge newly created config with local kubectl config file and switch to the new cluster
5. Run kubectl get nodes
- verify that the cluster is selected and you can access it
Play around with Kubernetes cluster
Once cluster deployment is done and you can access your cluster via kubeclt, there are a few fun things you can try out before you get rid of the cluster
- create a deployment and scale it up/down
- check out AKS (Azure Kubernetes Service) metrics on Azure portal
- deploy nginx pod and expose a service that you can access from outside
- deploy job and see it complete
Play with official “Guestbook” example
Kubernetes docs site has a very easy to follow sample called “Guestbook” which allows you to test a few k8s features and have a running sample in minutes. Follow the tutorial here.
Cleanup deployed resources
So now let’s get back to the “.. for free” part! In order not go get any costs, it is important to destroy all the resources. Follow those steps to do so:
- Run
terraform destroy
- cleanup all AKS related resources - Run
az group delete -n \<resource group name created earlier>
- remove storage account and terraform state - Run
rm -Rf .terraform
- run locally, this is needed to reset the state which is gone when removing the storage account and container