Skip to main content
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:
  1. Exporting existing Kubernetes resources to YAML
  2. Cleaning up and reapplying manifests
  3. Deleting old imperative resources
  4. Redeploying declaratively
  5. Designing a push-based CI/CD workflow with Azure DevOps

Preparing Your Environment

  1. Log in to your Azure subscription (local machine or Cloud Shell).
  2. Fetch and merge your AKS credentials into kubeconfig:
  1. Verify your existing Service and Deployment:
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:
A portion of the generated deployment.yaml:
Tip: Customize replicas, strategy, and container resources to match your production requirements.

2. Export the Service to YAML

Export the Service object:
Remove dynamic fields from service.yaml:
  • clusterIP
  • status.loadBalancer.ingress
  • spec.ports[*].nodePort
Your cleaned-up service.yaml should look like:
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:
Verify they’re gone:

4. Redeploy Declaratively

Apply your YAML manifests:
Check the status:
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.
  1. Commit & Push your application code and deployment.yaml + service.yaml to your repo.
  2. CI Pipeline: Build the container image, run tests, and publish to Azure Container Registry (ACR).
  3. CD Trigger: ACR webhook invokes the CD pipeline upon new image push.
  4. Deploy: Execute kubectl apply -f on your manifests to update AKS.
  5. Monitor: Use Azure Monitor or Application Insights for observability.

References

Watch Video