Sitemap
Arjun

Arjun

Passionate to learn about software, AI, automation, finance, and more. Software Engineer @ Microsoft Follow me on LinkedIn: www.linkedin.com/in/mr-arjun-patel

Hosting a Website on Azure Kubernetes Cluster

3 min readApr 28, 2025

--

Press enter or click to view image in full size
Photo by Aldebaran S on Unsplash

Introduction

Kubernetes has become a go-to solution for hosting websites due to its scalability, resilience, and security. However, this article focuses not on why Kubernetes is beneficial, but rather how to deploy a basic application on Azure Kubernetes Service (AKS) using best practices widely adopted in the industry.

Tools

To follow this guide, ensure you have access to the following tools:

  • GitHub (for storing the website’s source code)
  • Azure Subscription (for cloud hosting)
  • Azure CLI (for managing Azure resources)
  • Docker (for containerizing the application)

Containerizing your website

Before deployment, you need a webpage to host. This guide uses an Angular-based personal webpage as a sample, but the same method applies to a wide range of applications — beyond just frontends.

Get Arjun’s stories in your inbox

Join Medium for free to get updates from this writer.

Containerization isolates the app and its dependencies, ensuring consistent behavior across environments. Docker is widely used for this purpose. To containerize the Angular app, create the following Dockerfile in the project root:

# Step 1: Use Node.js image to build the Angular app
FROM node:18 AS build-stage
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm install
COPY . .
RUN npm run build --prod

# Step 2: Use Nginx to serve the built Angular app
FROM nginx:alpine
COPY --from=build-stage /app/dist/angular-app /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

Tip: Add a .dockerignore file to prevent unnecessary files from being copied into the container.

node_modules  
dist
.git
.gitignore

Deploy the containerized application to Azure

Once the Docker image is built, it must be stored in Azure Container Registry (ACR) for deployment. Use the Azure CLI to create an ACR:

az acr create --resource-group myResourceGroup --name $ACRNAME --sku Basic

For a detailed guide, refer to Azure’s official documentation.

Creating an AKS Cluster

To host the application, create an Azure Kubernetes Cluster and link it to ACR:

az aks create --resource-group myResourceGroup --name myAKSCluster --node-count 3 --node-vm-size standard_l8s_v3 --generate-ssh-keys --attach-acr $ACRNAME

Refer to Azure’s AKS guide for further details.

Automating Image Builds on GitHub Commits

Azure provides automation tools to rebuild and deploy container images whenever code is pushed to the repository. Use ACR Tasks to streamline this process:

az acr task create - registry <ACR_name> - name <ACR_task_name> - image <image_name>:latest - context <github_url> - file Dockerfile - git-access-token <github_access_token>

Note: You can generate a GitHub access token from your account settings.

Press enter or click to view image in full size

For more details, refer to Microsoft’s ACR Task documentation.

Creating and Running an AKS Manifest File

Once the container image is stored in ACR, define the workload using an AKS manifest file (deployment.yaml). Example:

apiVersion: apps/v1
kind: Deployment
metadata:
name: frontend
spec:
replicas: 1
selector:
matchLabels:
app: frontend
template:
metadata:
labels:
app: frontend
spec:
nodeSelector:
"kubernetes.io/os": linux
containers:
- name: frontend
image: <acr_name>.azurecr.io/<image_name>:latest
ports:
- containerPort: 8080
name: frontend
resources:
requests:
cpu: 1m
memory: 200Mi
limits:
cpu: 1000m
memory: 512Mi
---
apiVersion: v1
kind: Service
metadata:
name: frontend
spec:
ports:
- port: 80
targetPort: 8080
selector:
app: frontend
type: LoadBalancer

Apply the manifest file using kubectl:

kubectl apply -f <yaml_file_path>

Or via Azure Portal:

Press enter or click to view image in full size

Once the application is created you can will see the workload in portal or using kublet.

kubectl get service <service_name>  - watch

Once deployed, the application will be accessible via the assigned external IP.

Conclusion

Deploying applications using Azure Kubernetes Service (AKS) ensures scalability and resilience. With containerization, cloud-native applications can be managed efficiently. By leveraging Azure’s ACR Tasks, Kubernetes manifests, and GitHub automation, you can streamline deployments and maintain a robust CI/CD pipeline.

--

--

Written by Arjun

Passionate to learn about software, AI, automation, finance, and more. Software Engineer @ Microsoft Follow me on LinkedIn: www.linkedin.com/in/mr-arjun-patel