Azure Kubernetes Service (aks)


Microsoft Azure provides a cloud-based platform called Azure Kubernetes Service (AKS) to make it easier to build, manage, and scale Kubernetes-based containerised applications. By providing a managed environment, AKS goes beyond Kubernetes, an open-source system for automating the deployment, scaling, and management of containerised applications, allowing users to concentrate on their applications rather than the hassles of Kubernetes setup and administration.
AKS gives users access to features like auto-scaling, extensive security settings, and easy connection with Azure DevOps, while Azure manages crucial tasks like Kubernetes node configuration, upgrades, and monitoring. Organisations looking to modernise apps and effectively implement microservices architectures will find it particularly helpful.
We will demonstrate how to use the Azure Command-Line Interface (CLI) to create a Kubernetes cluster on Azure in this technical blog.
Requirements
Below are the requirements needed for this lab
Azure Account: You need an active Azure subscription.
Azure CLI: Install the Azure CLI on your local machine. If you haven't installed it yet, you can follow the instructions on;👉🏼 How to install the Azure CLI | Microsoft Learn
Install the extension of Azure CLI in Visual Studio Code by opening VS code, search for Azure CLI in its market place and install
Minikube: Install Minikube on your local machine so you can run Kubectl commands. https://minikube.sigs.k8s.io/docs/start/
Create a new Workspace
Open VS code
Click on Open Folder
Choose a location to create the folder in your local machine
Click on Select Folder
- Click the Yes, I trust the author button
- Close the welcome page
- Using the 3 dotted lines at the end of the Menu bar, choose new terminal
- Click on the drop down arrow and choose Git Bash
In the terminal, type the following commands
- minikube start - is used to initialize and start a local Kubernetes cluster on your machine
- Use the mkdir .ssh command to create a hidden folder called .ssh in your work directory.
- Type ssh-keygen -f .ssh/aks-ssh to generate public/private key pair and will be stored in the .ssh folder created earlier.
- Create a Resource Group using the following command: az group create --name testrg --location eastus
Replace "testrg" with a name of your choice and choose a suitable Azure region.
- Create an Azure Kubernetes cluster using the following command: az aks create --resource-group testrg --name MyAKSCluster --node-count 1 --nodepool-name systemp --node-resource-group myNodeRG --ssh-key-value .ssh/aks-ssh.pub --network-plugin azure --enable-cluster-autoscaler --min-count 1 --max-count 2 --zones 2
Confirm the progress made by opening the GUI interface of your Azure portal.
- After the AKS cluster is provisioned, you need to configure
kubectl
to interact with it. Use the following command: az aks get-credentials --resource-group testrg --name MyAKSCluster
- Execute the following command to verify that your AKS cluster is up and running: kubectl get node
The kubectl get namespace -A command shows the namespaces we have already.
- Create the “frontend“ Namespace by executing the following command: kubectl create namespace frontend
- Rerun the kubectl get namespace -A to verify the new addition.
You have the option to choose which namespace to use when deploying resources. For instance, the following command can be used to launch an NGINX deployment in the "frontend" namespace: kubectl create deployment nginx-deployment --image=nginx:latest --replicas=3 -n frontend
- To create a basic NGINX with 3 replicas, run the following command: kubectl create deployment nginx-deployment --replicas=3 --image=nginx:latest --port=80
- kubectl get deployments check the status of your NGINX deployment by running
kubectl get deployments -A
kubectl get deployment --namespace default
You should see the nginx-deployment
listed with the desired and current replicas both set to 3.
- Expose the NGINX deployment as a service to make it accessible externally: kubectl expose deployment nginx-deployment --name=nginx-service --type=LoadBalancer --port=80 --protocol=TCP
- Wait for a few moments until the external IP address is assigned to your service. Retrieve the external IP by running: kubectl get services
In the “External IP“ column, you will see the public IP 172.171.76.11. Copy the address and paste on your browser.
- Check Pods
- Check Replica Set
- Clean up resources.
Subscribe to my newsletter
Read articles from Adekunle Fatunde directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
