Build Your Azure Kubernetes Service (AKS) Cluster in Just 10 Minutes!
Kubernetes has become a go-to solution for deploying microservices and managing containerized applications. In this blog, we will walk through a real-world demo of how to deploy a Node.js app on Azure Kubernetes Service (AKS), referencing the hands-on transcript and official Microsoft Docs.
Introductionβ
Kubernetes lets you deploy web apps, data-processing pipelines, and backend APIs on scalable clusters. This walkthrough will guide you through:
- Preparing the app
- Building and pushing to Azure Container Registry (ACR)
- Creating the AKS cluster
- Deploying the app
- Exposing it to the internet
π§± Step 1: Prepare the Applicationβ
Start by organizing your code and creating a Dockerfile:
FROM node:18
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 80
CMD ["node", "app.js"]
For the setup we'll use code from repo: https://github.com/Azure-Samples/aks-store-demo. Clone the code and navigate to the directory.
The sample application you create in this tutorial uses the docker-compose-quickstart YAML file from the repository you cloned.
if you get error:
error during connect: Get "http://%2F%2F.%2Fpipe%2FdockerDesktopLinuxEngine/v1.46/containers/json?all=1&filters=%7B%22label%22%3A%7B%22com.docker.compose.config-hash%22%3Atrue%2C%22com.docker.compose.project%3Daks-store-demo%22%3Atrue%7D%7D": open //./pipe/dockerDesktopLinuxEngine: The system cannot find the file specified.
ensure that your docker desktop is running.
π¦ Step 2: Create a resource group using the az group create commandβ
Open Cloud Shell
az group create --name arinarg --location eastus
π¦ Step 2: Build and Push to Azure Container Registryβ
Create your Azure Container Registry:
az acr create --resource-group arinarg --name arinaacrrepo --sku Basic
Login and build your Docker image directly in the cloud:
az acr login --name arinaacrrepo
az acr build --registry arinaacrrepo --image myapp:v1 .
π¦ **Step 3: Build and push the images to your ACR using the Azure CLI az acr build command.β
az acr build --registry arinaacrrepo --image aks-store-demo/product-service:latest ./src/product-service/
az acr build --registry arinaacrrepo --image aks-store-demo/order-service:latest ./src/order-service/
az acr build --registry arinaacrrepo --image aks-store-demo/store-front:latest ./src/store-front/
This step creates and stores the image at:
arinaacrrepo.azurecr.io/
βΈοΈ Step 4: Create the AKS Clusterβ
Use the following command:
az aks create --resource-group arinarg --name myAKSCluster --node-count 1 --enable-addons monitoring --generate-ssh-keys --attach-acr arinaacrrepo
Then configure kubectl:
az aks get-credentials --resource-group arinarg --name myAKSCluster
π Step 4: Deploy the Appβ
Now apply the Kubernetes manifest:
# deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp-deployment
spec:
replicas: 2
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
spec:
containers:
- name: myapp
image: arinaacrrepo.azurecr.io/myapp:v1
ports:
- containerPort: 80
Apply it:
kubectl apply -f deployment.yaml
π Step 5: Expose the App via LoadBalancerβ
We will use a LoadBalancer to expose the service to the internet...
# service.yaml
apiVersion: v1
kind: Service
metadata:
name: myapp-service
spec:
type: LoadBalancer
selector:
app: myapp
ports:
- protocol: TCP
port: 80
targetPort: 80
Apply it:
kubectl apply -f service.yaml
Get the external IP:
kubectl get service myapp-service
Open the IP in your browser, and your app should now be live!
π Conclusionβ
Kubernetes on Azure is powerful and accessible. You've just deployed a containerized Node.js app to AKS, with best practices for build, deploy, and scale.
π Call to Actionβ
Choosing the right platform depends on your organizations needs. For more insights, subscribe to our newsletter for insights on cloud computing, tips, and the latest trends in technology. or follow our video series on cloud comparisons.
Need help launching your app on Azure AKS? Visit CloudMySite.com for expert help in cloud deployment and DevOps automation.
Interested in having your organization setup on cloud? If yes, please contact us and we'll be more than glad to help you embark on cloud journey.
π¬ Comment below:
Which tool is your favorite? What do you want us to review next?