In this article, you are going to discover generator-kubegen (a.k.a. kubegen). A yeoman generator helper thats aims to speed up you in the setup of Kubernetes deployments.

At the end of this article, you will be able to los a nginx server inside a Kubernetes cluster with few commands and few Questions and responses.

kubegen is an open source project hosted on GitHub, so you are welcome to join, contribute and debate!

Disclaimer

I don’t believe in magic. This includes the “magic” of code autogeneration. However, something I hate more than magic is copy/pasting, and those tasks where people don’t add value. While working with Kubernetes, I’ve found a process I can automate, letting me (and my teams) to focus in the part where we add value.

There is no value in the creation of boilerplate YAML files for Kubernetes. So, let’s automate and speed-up the process! Obviously, you need to pay attention to all the details of the configuration, and probably you’ll need to make changes manually after the initial “launch”.

At the end of the post, I’ll extend this. But, now, just get to the point.

Installing generator-kubegen (kubegen)

To install and run kubegen, you’ll need to have installed NodeJS, NPM and Yeoman (Windows, Linux or Mac alike).

I skip NodeJS and Yeoman setups. But be sure you have both installed.

Focusing in kubegen, go straight to the CMD/Terminal and type:

Please check that you have a recent node and npm versions. This are mine as of writing kubegen and the blog post.

Then, just simply install yeoman (yo) and kubegen (generator-kubegen).

Ready to go :). Type “yo” and check that yeoman can start and kubegen is on the list of installed generators:

Optional: Setting up a minikube environment

Probably, you want to deploy and test the files we are going to create. Minikube is the best way to run Kubernetes locally right now, and the project has a great (and simple) installation process described in their GitHub repo. If you do not have minikube (or any Kubernetes cluster to deploy), please install minikube.

Ready to go? If you are using minikube, just a final step. Don’t forget to enable ingress controllers to check the YAML we are going to create in full.

Of course, minikube should be up and running!!!

Creating our first service with kubegen

Get back to the Terminal/PowerShell/CMD and type:

kubegen ask you all the questions it needs to host a solution in Kubernetes (end to end). This includes the Pod Controller Type (Replication Controller or Deployment), the Service and (optionally) the Ingress.

Obviously you need to know what you are doing to use kubegen. If you are not familiar with all the concepts, you will find plenty of information on the net about it. Understanding the basic things is essential to see the true power of Kubernetes.

kubegen creates, by default, a folder named the same you responded in the first question (“How the service should be named?”). In this case, the folder is called “nginx”. Just check it out:

Now, we are ready to deploy using kubectl:

Create your DNS (or update your hosts files)

This example uses and NGINX Ingress, what requires you to specify a hostname, allowing the ingress to route the traffic properly. In my basic scenario, where you running minikube, you need to check your minikube IP and add it to your hosts files:

Check nginx is up and running

We have minkube started, the ingress addon enabled, three Kubernetes object YAML files created with kubegen, a DNS record in our hosts file (or DNS provider) AND we have applied the files. Browser time:

Easy. Isn’t it? 🙂

Work in progress. Contribute!

Travis CI Build Coveralls NPM Downloads

Fork Watch Star Issue

I should admit that I am just starting in the Kubernetes universe, so I have a very limited vision of all the things, combinations, needs and improvements points that kubegen could contribute to. Kubegen source code is available on GitHub. Contributions, ideas, enhancements, bugs… are all welcome.

Or simply, just play with kubegen and let me know how it feels like.

The projects starts with a 100% code coverage (mocha, istanbul, coveralls) and Travis CI integration up and running, check software health and publishing when is necessary.

Why?

Lately, I’ve been doing a lot Kubernetes with .NET. I should admit that I am really impressed about its potential to create cloud solutions. I think that the power of this technology can be resumed with this three tweets:

Even for those that are working with .NET Technologies, Kuberentes is a tool box with the power to create amazing things. A kind of “Lego” for cloud computing solutions. BUT, as I stated at the beginning, I think there is an small improvement boosting the creation of the configuration files.

Because, having this file, you can version in Git also all your cluster configuration, for all the environments.

More to come…

Some time ago, I blogged an introductory articles about how to setup a Kubernetes cluster on Azure Container Services. And in the past months, we’ve been doing serious progress putting .NET solutions inside Kubernetes and Azure. Something we will talk about in the near future, during my summer holidays :). Sorry about not having enough time to keep the blog as updated as I would…