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!


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:

$ node --version v8.1.3 $ npm --version 5.0.3 $ npm install -g generator-kubegen

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:

$ yo ? 'Allo Sergio! What would you like to do? (Use arrow keys) Run a generator ❯ Kubegen ────────────── Update your generators Install a generator Find some help Get me out of here! (Move up and down to reveal more choices)

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.

minikube addons enable ingress

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

minikube start

Creating our first service with kubegen

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

$ yo kubegen 

Welcome to Kubernetes Generator (kubegen)! ? 
How the service should be named? nginx ? 
In which Namespace should be deployed? default ?
Which type of Pod controller mechanism whould you like to use? Deployment ? 
(Deployment) Which Docker image should the Deployment use? nginx ? 
(Deployment) How much container replicas should be created? 1 ? 
(Service) In which port is the Container listening? 80 ? 
(Service) In which port should the Service listen? 80 ? 
(Ingress) Would like to expose the service out of the cluster? yes ? 
(Ingress) Does the service have a hostname? ? 
(Ingress) Ingress root path? / ? 
(Ingress) In which port should the Ingress listen? 80 create deployment.yml create svc.yml create ing.yml

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:

$ ls nginx $ ls nginx deployment.yml ing.yml svc.yml

Now, we are ready to deploy using kubectl:

kubectl create -f ./nginx/ deployment "nginx" created ingress "nginx" created service "nginx" created

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:

$ minikube ip

$ nano /etc/hosts GNU nano 2.0.6 File: /etc/hosts ## # Host Database # # localhost is used to configure the loopback interface # when the system is booting. Do not change this entry. ## localhost broadcasthost ::1 localhost

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.


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:

The real wins of @kubernetesio are the abstractions that it enables you to create. Everything else is plumbing.

— Bryan Liles (@bryanl) 20 de junio de 2017

💯Kubernetes is fundamentally a tool box. The real power is what you can build with it.

— Joe Beda (@jbeda) 20 de junio de 2017

So true. The key philosophy that makes the project successful (and special)
Ala carte tools and utilities not monolithic platform.

— brendandburns (@brendandburns) 21 de junio de 2017

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…