Running Habitat Applications on Kubernetes

Containers continue to take the IT world by storm and container orchestration platforms are a major part of how you build and ship software in a modern way. Kubernetes is a great example of the growth of this segment, and has emerged as one of the leaders of this space. Chef has been actively involved in this space, and as a continuation of this work, we are happy to announce a few patterns that help you deploy Habitat built applications to Kubernetes.

Management Supervisor Ring

The first pattern we’ve defined is the concept of a management supervisor ring. Applications launching on Kubernetes need a common end point to bootstrap themselves upon launch. In order to run the management supervisors, we’ve defined a Daemon Set in Kubernetes that runs an “empty” service. The service is simply there to provide the necessary Habitat Supervisor API  end points to query the health of the ring.  The management supervisor ring also provides a Kubernetes Service that new applications can use as a common end point to peer to. You can find the yaml required for spinning up the Service and Daemon Set in this Github repo.

Create Habitat Management Ring on Kubernetes

Labels from Elections

One of the benefits of using Habitat for your containers is the built in ability for containers to self organize into a clustering topology. Containers within the Habitat service group will automatically know which of its peers are a leader or follower based on the election the supervisor performs. This information may need to be propagated to other systems. For example, with Kubernetes you might want to label the pods running Habitat built containers with the results of an election to route traffic from Services.

The Habitat Supervisor allows you to to take action once an election is complete. Using a Redis plan as an example, a Habitat election will generate a config file with the label to apply to a Pod. Before the Redis service is started, kubectl is called to label the Pod, then Redis starts with the appropriate configuration.

You can find the Redis example in this Github repo, along with the Redis Habitat plan, and a Habitat plan for kubectl. Eventually kubectl should be available as a core plan.

Create Redis Deployment on Kubernetes

Special Thanks

Over the past several months, we’ve been working with a few partners to make Habitat better. Container Solutions has provided lots of guidance around running Habitat applications on Kubernetes and has been publishing their experience working with Habitat. Specifically I’d like to thank Maarten Hoogendoorn and Pini Reznik. I’d also like to thank Chef Community member Nick Leli who gave me some good guidance on how to best run Habitat Supervisors on Kubernetes  (use a Daemon Set).

Learn More

If you want to learn more about Habitat and how it simplifies the container experience you can watch my talk from Kubecon (below). You can also find me at ChefConf where I’ll be talking more about running Habitat applications on Kubernetes.

Michael Ducy

Former Chef Employee