Using container labels for Kubernetes deployment

Liz Rice
Microscaling Systems
2 min readJan 10, 2017

Just before the holidays, Kelsey Hightower joined us for a webinar on container metadata. Here’s a great demo he did during the session, showing how you can use a Dockerfile label to identify the Kubernetes deploy file. We’ve built on this t0 show how you can fully automate the process using the new MicroBadger API.

Kelsey’s Dockerfile includes a line like this:

LABEL io.kubernetes.deploy-url=https://storage.googleapis.com/hightowerlabs/helloworld.yaml

and you can see how this translates into image metadata by inspecting his helloworld image on MicroBadger.

This metadata tells you where to find the kubernetes file that you need for deployment. Imagine you’ve found this Docker image — now you have all the information you need to run the following kubernetes command and get it running on your own deployment.

kubectl create -f https://storage.googleapis.com/hightowerlabs/helloworld.yaml

You could imagine similar labels pointing at, say, Helm charts to indicate how to deploy an image.

With the introduction of the MicroBadger API we’ve taken this a step further, so you can fully automate the whole process. By hitting the API for Kelsey’s image, you can get its metadata at the command line (I’ve edited the output for brevity).

The output includes the labels for the latest version* for the image at the top level of the json, and then also embeds labels for each version. For the sake of simplicity I’m going to pretend that the first instance we find of the io.kubernetes.deploy-url is correct (you can obviously make this properly robust).

$ curl -s https://api.microbadger.com/v1/images/kelseyhightower/helloworld | json_pp | grep io.kubernetes.deploy-url | head -1 | awk '{print $3}'"https://storage.googleapis.com/hightowerlabs/helloworld.yaml"

Feed something this into your Kubernetes deployment command and you‘ll automatically get the deploy file that the author referred to in their metadata.

I should point out that the API is still in early, experimental stages, and you should exercise caution as it is not in any way security-hardened. You’ll notice that Kelsey checks that the the curl command gives him the output he expected.

But we’d love you to kick the tyres and let us know your thoughts. Although for now the API only supports public images on Docker Hub, we’re planning to support other registries and private images. Get in touch today if that’s something you’d like to see.

*What do we mean by “latest version”? If there’s a version tagged “latest”, we’ll use that — and if this version has additional tags, we’ll use the longest of those tags. If there is no version tagged “latest” we’ll use the most recent version. Take care when using “latest”!

If you think container metadata is useful, please click the Recommend button! And follow Microscaling Systems to keep up-to-date with developments.

--

--

Liz Rice
Microscaling Systems

Containers / eBPF / security / open source @isovalent @ciliumproject / cycling / music @insidernine