There are many reasons to host your own build agents in Azure DevOps, including cost savings, better control over your agents, and, of course, all the benefits of the cloud. However, private build agents do require their own maintenance. Wouldn’t it be nice to have a short-lived, customized agent ready whenever you needed it? This is possible using Kubernetes and Docker.

Getting Started

Before you get started, you will need Docker, an Azure DevOps account, and a Kubernetes cluster. You could use Windows Server Core or an Ubuntu container for your self-hosted agent to run inside. However, we will be running our agent inside Kubernetes in order to take advantage of the power of this technology.

To get started, we are going to create a self-hosted Agent Pool in Azure DevOps. This can be done simply in the UI.

We will also need to create a Personal Access Token.

Next, we need to create and build a Dockerfile. A Dockerfile is a text file that contains instructions to build a Docker image. So, we must give the Dockerfile all the information it needs to build the image, including where the directory will be and what executables you need. This is like the recipe for the Docker image. This is also where you would make alterations to your agent’s specifications should your needs change over time.

Once the Docker image is built, push it to a registry, such as Azure Container Registry.

Using Docker, you’re able to avoid the maintenance associated with a self-hosted build agent. You can configure a new Docker image every time you want to spin up an agent. This allows you to create the agent you need, perfectly every single time.

Running Your Agent in Kubernetes

Finally, we need to deploy to Kubernetes using a Deployment manifest. Applying the Deployment manifest will create Azure agents in your Agent Pool. You can check that this was successful by simply viewing your Agent Pools in Azure DevOps.

By provisioning agents this way, you’re able to scale to your needs on demand. Additionally, you can spin up customized agents easily and only have them running as long as you need them.

For more information, or to see how to take advantage of this technology in your organization, contact our team of experts at PRAKTIK here.