Azure, How to, kubernetes

Kubernetes Integration Testing: MiniKube + Azure Pipelines = Happy

Update: With the release of KIND (Kubernetes in Docker) I’ve now moved to using this over minikube as it’s quicker and simpler.

I recently did some work on a fairly simple controller to run inside Kubernetes. It connects to the K8s API and watches for changes to ingress objects in the cluster.

I had a nice cluster spun up for testing which I could tweak and poke then observe the results. This was nice BUT I wanted to translate it into something that ran as part of my CI process to make it more repeatable. Having not played much with the new Azure Pipelines I decided to try and get this working using one.

Here was the goal:

    • Build the source for the controller
    • Spin up a Kuberentes cluster
    • Deploy test resources (Ingress and Services) into the cluster
    • Connect the controller code to the cluster and run it’s tests

The obvious choice was to look at creating the clusters inside a cloud provider and using it for testing but I wanted each PR/Branch to be validated independently in a separate cluster, ideally in parallel, so things get complicated and expensive if we go down that route.

Instead I worked with MiniKube which has a ‘no vm mode’, this spins up a whole cluster using just docker containers. The theory was, if the CI supports running docker containers it should support MiniKube clusters…

TLDR: Yes this is possible with MiniKube and Azure Pipelines or Travis CI – Skip to the end to see how.

Continue reading

Coding, How to

Build & Push a Docker Image using Visual Studio Online Build vNext

So I’ve got a nice and simple NodeJs app and I want to have a CI build which builds my Docker image and pushes it to my docker hub ready for deployment. I’ll look at deployment in a future post, this time round we’ll focus on the build process.

To get this setup we’ll need to go through two bits, basically VSO uses agents (machines used to execute builds) and a build, which defines some steps that output an artifact (in this case a docker image). So we’ll setup a build agent, where the docker build can run, and then setup the build itself.

Setup the Build Agent

We’re going to need a linux based build agent to build out our docker image and push it to docker hub, as we’re hosting on the linux version of docker. We could also look at using the Windows implementation of Docker, which is available in the most recently Window Server Preview, but I’ll leave this for another day.

To do this we can use the ARM templates from the Azure Marketplace in the new portal to spin up an ubuntu VM then install all the bits we need. One the machine is up and running connect up to it via SSH to start install stuff, if you don’t have a client puttys a good bet.

First up let’s install docker on the agent. (full guide )

sudo curl -sSL | sh

After the docker install I found I had to reboot the machine to get things to behave.

After the reboot, check docker is up and running on the box. Easy way to do this is to type “docker info” at command line and you should get an overview of the Docker install, like so.

Next let’s install the VSO agent so it can pick up and do the builds. (full guide here )

To do this we have to setup apt-get for Ubuntu to install Nodejs:

curl -sL | sudo -E bash -

Then install Nodejs:

sudo apt-get install –yes nodejs

So hopefully that went well and now if you type ‘node –v’ you see it all installed! (This may change over time, install docs for npm are here)

Continue reading