Skip to main content

One post tagged with "AKS"

View All Tags

Build Your Azure Kubernetes Service (AKS) Cluster in Just 10 Minutes!

Β· 4 min read
Cloud & AI Engineering
Arina Technologies
Cloud & AI Engineering

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:


  1. Preparing the app
  2. Building and pushing to Azure Container Registry (ACR)
  3. Creating the AKS cluster
  4. Deploying the app
  5. 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?