Skip to content

Azure Pipeline

aaboyle878 edited this page Jan 13, 2024 · 5 revisions

To automate the building and pushing of our image from the dockerfile to Dockerhub and the application of our Kubernetes manifest to the cluster we have built a pipeline with Azure Devops to automate these tasks for us. For the pipeline to be successful it required some set up which comprised of:

  • Creating a new Organisation and project within Azure DevOps

  • Creating a service connection to github repo for the app
     - This is the github repo which will house the source code for our app, along side the Dockerfile, Terraform files and modular structure, the kubernetes cluster application manifest yaml file and ultimately our pipeline .yml file too

  • Creating a service connection for the pipelines to Docker Hub
     - This will act similarly to a service account in the sense that when the piepline is executed it will all an agent to build the image and push it to docker for us rather than having to manually change the image version with each docker push

  • Creating a serivce connection to our Kubernetes cluster hosted on using AKS
     -In much the same way the docker service connection acts as a service account for docker the same can be said for the Kubernetes service connection as it will allow us to apply any changes in our manifest/config file to the cluster and reduce the erro associated with inexperienced users using kubectl commands

  • Creating the azure-pipelines.yaml file
     - This file will house the pipeline trigger, agent pool and associated steps we wish to execute each time the pipeline runs, in our case we have set the trigger to main meaning that anytime there is a change to the main branch of the repo our pipeline should detect the change build the image from scratch push to docker hub and then use the application manifest to deploy the image to the pods within out cluster as can be seen below pipeline.yaml

  • Fixing any issues as they arose

Testing the pipeline

The testing of the pipeline was done in two phases after each step was added:

  1. To validate the step worked as expected and tune the parameters if required
  2. To allow for the investigation of issues should there be an problems with the steps selected

Phase 1

This was the inital set up and trail run of the pipeline building and pushing the image of our app to Docker Hub. In this phase the pipeline was run to ensure the set-up was correct i.e. nothing had be missed and to also verify that the image push could be automated.

There were a few issues that were discovered in this inital round of testing

  1. Azure Cloud subscription not linking to the Azure Devops Org correctly and the runners/build agents not allowing for parallelism.

    However this was resolved by updating the billing for the project.
  2. The docker image wasnt able to be pushed to the Docker Hub Repo

    This was resolved by adding the username to the repository field withint he task i.e. repository: username/app_name

Phase 2

This phase introduce the use the of the Kubernetes service connection to apply our manifest/config file and as such followed the approach in the Checking Deployment where we connected to the cluster via the shell and checked everything was running as expect using our kubectl command then also checking the deployment on our local machine via port forwarding.

An issue that was encountered during this phase of the deployment was due to the manifest file being located in the wrong place however this was rectified by moving the yaml file for the child directory into the parent thus ensuring the pipeline ran to success and the output of a successful run can be viewed below: pipline-steps

Clone this wiki locally