what is AKS and how it will work on deploys in CI CD pipeline.yaml - kondareddypp/azure-network-fundamentals GitHub Wiki
Azure Kubernetes Service (AKS) does in the context of your CI/CD pipeline and how it fits into the overall process.
What is AKS?
Azure Kubernetes Service (AKS) is a managed Kubernetes service provided by Azure. It simplifies the deployment, management, and scaling of containerized applications using Kubernetes. Kubernetes is an open-source platform for automating deployment, scaling, and operations of application containers.
What Does AKS Do in Your Pipeline?
If you include AKS in your pipeline, it will handle the deployment and orchestration of your containerized application. Here’s what AKS does in this context:
-
Deploys Your Application:
- AKS takes the Docker image (stored in Azure Container Registry) and deploys it to a Kubernetes cluster.
- The
deployment.yaml
file defines how the application should be deployed (e.g., number of replicas, resource limits, etc.).
-
Manages Containers:
- AKS ensures that the specified number of container instances (pods) are running at all times.
- If a container crashes, AKS automatically restarts it.
-
Scales Your Application:
- AKS can automatically scale your application based on CPU/memory usage or custom metrics.
- For example, if traffic to your application increases, AKS can spin up additional instances of your container to handle the load.
-
Load Balancing:
- AKS can expose your application to the internet using a LoadBalancer service (as defined in the
deployment.yaml
file). - This ensures that traffic is distributed evenly across all running instances of your application.
- AKS can expose your application to the internet using a LoadBalancer service (as defined in the
-
Rolling Updates and Rollbacks:
- AKS supports rolling updates, which allow you to deploy new versions of your application without downtime.
- If something goes wrong, you can easily roll back to a previous version.
-
Self-Healing:
- AKS monitors the health of your application and automatically replaces unhealthy containers.
Why Use AKS?
If your application is containerized (using Docker), AKS provides a robust platform to:
- Deploy your application in a scalable and reliable way.
- Manage the lifecycle of your containers.
- Scale your application based on demand.
- Ensure high availability by distributing your application across multiple nodes in the cluster.
When Do You Need AKS?
You need AKS if:
- Your application is containerized (e.g., using Docker).
- You want to deploy your application to a Kubernetes cluster for scalability and reliability.
- You need advanced features like auto-scaling, rolling updates, and self-healing.
What Happens if You Don’t Use AKS?
If you don’t use AKS, your pipeline will only build and push the Docker image to Azure Container Registry (ACR). The image will sit in ACR as an artifact, but it won’t be deployed anywhere. You would need to manually deploy the image to a hosting environment (e.g., Azure App Service, VM, or another Kubernetes cluster).
Example Workflow with AKS
Here’s how AKS fits into your CI/CD pipeline:
- Build: Your Java application is compiled and packaged into a Docker image.
- Push: The Docker image is pushed to Azure Container Registry (ACR).
- Deploy: AKS pulls the Docker image from ACR and deploys it to the Kubernetes cluster.
- Run: Your application is now running in the AKS cluster, and Kubernetes manages its lifecycle.
deployment.yaml
for AKS
Example Here’s an example of a Kubernetes manifest (deployment.yaml
) that AKS uses to deploy your application:
apiVersion: apps/v1
kind: Deployment
metadata:
name: java-app
spec:
replicas: 3 # Run 3 instances of the application
selector:
matchLabels:
app: java-app
template:
metadata:
labels:
app: java-app
spec:
containers:
- name: java-app
image: your-acr-name.azurecr.io/your-java-app:$(Build.BuildId) # Docker image from ACR
ports:
- containerPort: 80 # Expose port 80
---
apiVersion: v1
kind: Service
metadata:
name: java-app-service
spec:
type: LoadBalancer # Expose the application to the internet
ports:
- port: 80
targetPort: 80
selector:
app: java-app
Summary
- AKS is used to deploy, manage, and scale your containerized application in a Kubernetes cluster.
- If you include AKS in your pipeline, it will pull the Docker image from ACR and deploy it to the cluster.
- If you don’t use AKS, your Docker image will remain in ACR as an artifact, and you’ll need to manually deploy it elsewhere.