Azure Kubernetes Service
CICD Workflow for AKS
Push Based CICD Workflow
In this guide, you’ll learn how to convert an imperative AKS deployment into a declarative setup with YAML manifests and integrate it into a push-based CI/CD pipeline. We cover:
- Exporting existing Kubernetes resources to YAML
- Cleaning up and reapplying manifests
- Deleting old imperative resources
- Redeploying declaratively
- Designing a push-based CI/CD workflow with Azure DevOps
Preparing Your Environment
- Log in to your Azure subscription (local machine or Cloud Shell).
- Fetch and merge your AKS credentials into
kubeconfig
:
az aks get-credentials \
--name AKS1-KodeKloudApp \
--resource-group MyResourceGroup
# Merged "AKS1-KodeKloudApp" as current context in /home/user/.kube/config
- Verify your existing Service and Deployment:
kubectl get service
kubectl get deployment
Note
Make sure your current context points to the correct AKS cluster. Use kubectl config current-context
to check.
1. Export the Deployment to YAML
Run the following command to export the kodekloudapp
Deployment manifest:
kubectl get deployment kodekloudapp \
--namespace default \
--output yaml > deployment.yaml
A portion of the generated deployment.yaml
:
apiVersion: apps/v1
kind: Deployment
metadata:
name: kodekloudapp
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: kodekloudapp
strategy:
type: RollingUpdate
template:
metadata:
labels:
app: kodekloudapp
spec:
containers:
- name: kodekloudapp
image: <your-image>
ports:
- containerPort: 80
Tip: Customize
replicas
,strategy
, and container resources to match your production requirements.
2. Export the Service to YAML
Export the Service object:
kubectl get service kodekloudapp \
--namespace default \
--output yaml > service.yaml
Remove dynamic fields from service.yaml
:
clusterIP
status.loadBalancer.ingress
spec.ports[*].nodePort
Your cleaned-up service.yaml
should look like:
apiVersion: v1
kind: Service
metadata:
name: kodekloudapp
namespace: default
spec:
type: LoadBalancer
selector:
app: kodekloudapp
ports:
- port: 80
targetPort: 80
protocol: TCP
Warning
If you switch to type: NodePort
, ensure nodePort
values are in the 30000–32767 range.
3. Delete Imperative Resources
Remove the existing Deployment and Service:
kubectl delete deployment kodekloudapp
kubectl delete service kodekloudapp
Verify they’re gone:
kubectl get deployment # No resources found
kubectl get service # No resources found
4. Redeploy Declaratively
Apply your YAML manifests:
kubectl apply -f deployment.yaml
kubectl apply -f service.yaml
Check the status:
kubectl get deployment
kubectl get service
Open the external IP in your browser to confirm the application is running.
5. Push-Based CI/CD Pipeline Overview
Below is a sample push-based pipeline in Azure DevOps. You can adapt these stages for GitHub Actions, GitLab CI, or other tools.
Stage | Description | Example Tools |
---|---|---|
Source Control | Push code & manifests to Git repo | Azure Repos, GitHub, GitLab |
Continuous Integration | Build container image and run unit tests | Azure Pipelines, GitHub Actions |
Artifact Publishing | Push Docker image to registry | ACR, Docker Hub, ECR |
Continuous Deployment | Detect new image; apply YAML to AKS | kubectl apply , Helm, Flux CD |
Monitoring & Feedback | Collect logs/metrics, update backlog | Azure Monitor, Application Insights |
- Commit & Push your application code and
deployment.yaml
+service.yaml
to your repo. - CI Pipeline: Build the container image, run tests, and publish to Azure Container Registry (ACR).
- CD Trigger: ACR webhook invokes the CD pipeline upon new image push.
- Deploy: Execute
kubectl apply -f
on your manifests to update AKS. - Monitor: Use Azure Monitor or Application Insights for observability.
References
- Azure Kubernetes Service (AKS)
- Kubernetes YAML Configuration
- Azure DevOps CI/CD
- Azure Container Registry
Watch Video
Watch video content