DEV Community

Cover image for Learning the Kubernetes codebase
Chuck Ha
Chuck Ha

Posted on

Learning the Kubernetes codebase

Date: July 5th, 2018
Most recent Kubernetes release: 1.11.0
Enter fullscreen mode Exit fullscreen mode

Kubernetes is a big piece of software clocking in just shy of 2 million lines of code. It can be intimidating to get started, but once you get the hang of it, you'll be amazed at how many tickets start to make sense and how you can quickly identify and fix bugs!

The very beginning

If you are just starting your Kubernetes journey, I would encourage you to read this documentation and get a high level understanding of the major components. To call something a Kubernetes cluster it needs most of the components listed there running on at least one node. Conveniently, all of the code for the components lives in the Kubernetes monorepo.

The first step

Now that you know what each component does, you can pick a component that sounds interesting to you. If you're having trouble picking a component, one thing I like to do is pick the thing that is farthest outside of my comfort zone. For example, if networking is a weak spot of yours, pick the kube-proxy. If you've got the network chops but don't really do web servers, pick the kube-apiserver.

One foot after the other

One tool every coder needs is a good code editor. The feature that helps me the most when reading code is jump to definition. I use VSCode with the typical Go plugins and that fulfills that requirement to my satisfaction. You could use vim, Goland, or emacs, just so long as you are comfortable with the tool and you can jump between functions effectively, you'll be ready to go.

One small step

Kubernetes lives at Usually, the import path for Go code that lives on github is the URL without the scheme (https://). So you might expect go get -d to work, but that's going to confuse your tools. The package name is actually So go ahead and clone the repo using this command go get -d If you don't have go installed, follow the instructions on

Another small step

Open up the Kubernetes directory with your trusted code editor. Take a look inside cmd/. This is where you find the entry point to all of the components that live inside Kubernetes. Every component in Kubernetes is run as a command line program and the references are all online. Here is where the kube-proxy's entry point is. This patter of cmd/<component>/<component>.go is going to be pretty much the same across every component.

Repeat forever

Now start exploring the file! Chances are the first file you open under cmd/<component>/<component>.go is going to be very small. Read through each line. Do you know what it does? If you go to the definition of the function call on this line you will realize how deep this code goes. You have a lot to read!

Now do this until you are satisfied with your understanding. It will take a while and that's totally normal. This stuff is not easy to pick up. Heck, you could even get a post or two out about what you found useful, interesting rabbit holes, and things you found surprising about the Kubernetes code base!

If you're trying to break into Kubernetes development, there's no better way to read lots of the code!

Top comments (0)