Hands-on Challenge Day - Deploying a Web Application on Kubernetes in Azure
Kubernetes, often abbreviated as K8s, is an open-source container orchestration platform that automates the deployment, scaling, and management of containerized applications. It groups containers that make up an application into logical units for easy management and discovery.
Azure Kubernetes Service (AKS) provides a managed Kubernetes service that reduces the complexity of deploying and managing Kubernetes clusters, offering easy scaling, self-healing, load balancing, and automated updates. It's an ideal platform for deploying containerized applications with all the benefits of cloud computing.
TechSolutions Inc., a software development company, has developed a new web application designed to streamline project management tasks. To meet their scalability and reliability needs, they've decided to deploy this application on Kubernetes in Azure. This move aligns with their goal to modernize their infrastructure and embrace cloud-native technologies.
Problem Statement: TechSolutions Inc. needs a scalable and resilient deployment solution for their new web application to ensure it can handle varying loads and provide a seamless user experience.
Your Mission: Deploy TechSolutions Inc.'s web application on Azure Kubernetes Service (AKS). The deployment should ensure the application is scalable, secure, and easily accessible.
Set Up Azure Kubernetes Service:
az aks create --resource-group myResourceGroup --name myAKSCluster --node-count 2 --enable-addons monitoring --generate-ssh-keys
Configure kubectl:
kubectl
to connect to your newly created AKS cluster.az aks get-credentials --resource-group myResourceGroup --name myAKSCluster
Prepare the Web Application:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, Kubernetes on Azure!'
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', port=5000)
FROM python:3.8-slim
WORKDIR /app
COPY . /app
RUN pip install Flask
EXPOSE 5000
CMD ["python", "app.py"]
Deploy the Application to AKS:
apiVersion: apps/v1
kind: Deployment
metadata:
name: flask-app
spec:
replicas: 2
selector:
matchLabels:
app: flask
template:
metadata:
labels:
app: flask
spec:
containers:
- name: flask
image: <your-docker-image>
ports:
- containerPort: 5000
---
apiVersion: v1
kind: Service
metadata:
name: flask-app-service
spec:
type: LoadBalancer
ports:
- port: 80
targetPort: 5000
selector:
app: flask
<your-docker-image>
with the path to your Docker image in ACR or Docker Hub.kubectl apply -f deployment.yaml