Kubernetes explained in pictures: the theme park analogy
Tags: architecture, kubernetes, docker, explainlikeimfive
Published: 2018-07-22 22:00:02

---
title: Kubernetes explained in pictures: the theme park analogy
published: true
tags: Architecture,Kubernetes,Docker,explainlikeimfive
canonical_url: https://danlebrero.com/2018/07/09/kubernetes-explained-in-pictures-the-theme-park-analogy/
cover_image: https://danlebrero.com/images/blog/kubernetes-explained/kubernetes-explained-theme-park.jpg
description: This is an attempt to explain Kubernetes core concepts with a theme park analogy.
---

Kubernetes (k8s from now on) comes with its own set of abstractions, its own lingo, but with a little bit of imagination we can correlate those abstractions with more familiar concepts.

I was hoping for the sausage factory analogy to work, but unfortunately k8s is more than sausages, so we will have to settle for a theme park analogy. 

The following is based on [Google Kubernetes Engine](https://cloud.google.com/kubernetes-engine/); some of the concepts may work slightly different in other providers or if you run k8s yourself.

## Who are you 

You are Kubenelius Fizzbuzz, a newly graduated MBA, with the speciality on Boxes Of All Sizes and you are about to embark in your greatest idea: KubePark Theme World.

## The fun ride plans

To start KubePark, you need to plan its fun rides. You decide that, for each attraction, you will just need to fill a template like this **(k8s [deployment](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/))**:

![kubernetes deployment](https://danlebrero.com/images/blog/kubernetes-explained/kubernetes-deployment.jpg "Kubernetes deployment")

Here you say that KubePark will have three 1909 carousels. 

A 1909 carousel is composed of two parts: a classic carousel plus a candy floss booth. Each part **(k8s [container](https://www.docker.com/what-container))** will be delivered by drone in a huge box, completely assembled and ready to roll once unboxed.

Each attraction will be surrounded by a fence, isolating them from other attractions, so that a problem in one attraction is not spread to other attractions. But the parts of the attraction form an inseparable whole **(k8s [pod](https://kubernetes.io/docs/concepts/workloads/pods/pod-overview/))**, so there are no barriers or firewalls that could difficult the communication or movement between the parts, ruining the enjoyment of visitors **(k8s except if you want to [share files](https://www.mirantis.com/blog/multi-container-pods-and-container-communication-in-kubernetes/) which requires a little bit of configuration)**.

Having a fence means that you need to plan where the doors **(k8s [containerPort](https://kubernetes.io/docs/concepts/services-networking/connect-applications-service/))** for visitors should be. In the case of the 1909 carousel, visitors will come through the candy floss booth: a carousel ride is always more fun while enjoying a big fluffy sugar cloud.

The template also specifies the size **(k8s memory)** and power **(k8s CPU)** requirements **(k8s [resources](http://www.noqcks.io/notes/2018/02/03/understanding-kubernetes-resources/))**, and tags **(k8s [labels](https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/))**  the 1909 carousel as a carousel, kid friendly and classic attraction. We will see later how you will use all this information.

<a name="maintenance"></a>In the reverse of the template, not shown above, you write down the maintenance instructions **(k8s [probes](https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/))** for each part. Your crew will periodically follow those instructions to know if any of the parts needs replacement. If it does, the maintenance crew will burn the faulty part to the ground and drones will bring another huge box with the replacement. So no fiddling around to try to fix anything, but just a plain simple replacement of the whole booth or carousel. During the replacement the attraction will be closed to visitors, even if some parts are still in a working state: the 1909 carousel experience must have candy floss and must include a carousel ride, both things are inseparable.

## The land

With the fun rides planned, it is time to build the park. 

You sign a rent contract **(k8s [node pool](https://cloud.google.com/kubernetes-engine/docs/concepts/node-pools))** with a landlord:

![kubernetes node pool](https://danlebrero.com/images/blog/kubernetes-explained/kubernetes-node-pool.jpg "Kubernetes node pool")

The contract is for two parcels of land **(k8s [nodes](https://kubernetes.io/docs/concepts/architecture/nodes/))**, each one with the specified size **(k8s memory)** and power generator **(k8s CPU)**. Note that the contract is not for two particular parcels, but for any two parcels with those characteristics, it will be the landlord’s job to find them. With the modern means of passenger transportation, they don’t even need to be adjacent.

The landlord also takes care of securing the access to the parcel, by installing barbed wired around each parcel.

You also tick the free disasters insurance **(k8s [auto repair](https://cloud.google.com/kubernetes-engine/docs/concepts/node-auto-repair))** box: if a parcel becomes unusable, the landlord will replace it for another one with exactly the same characteristics. It will be the landlord’s sole responsibility to find out and decide if the parcel is unusable, and to replace it.

Lastly, any parcel provided by the contract will be tagged **(k8s [labels again](https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/))** as plains with Mediterranean weather. We will see later how we use this information.

##Building KubePark

You already worked hard enough, so you delegate the details of the park’s construction to your control crew. The crew will make sure that the exact number and type of attractions that you specified in your plans are always working. 

In a gesture of unexpected generosity, your landlord offers an air traffic control tower **(k8s [cluster master](https://cloud.google.com/kubernetes-engine/docs/concepts/cluster-architecture#master))** to accommodate the control crew, and to take care of any maintenance and improvements work that the tower may need. One less thing to care about!

From the tower’s privileged position and with your fun ride plans in hand, your crew will decide on which parcels to build each attraction, making sure that the parcel’s available room and spare power can accommodate those required **(k8s [resource quality of service](http://callmeradical.com/post/k8s-resource-limits-requests-qos/))** by an attraction.

An attraction will always get the minimum power **(k8s CPU)** required, will never get more than the maximum power (as it will short circuit and burn otherwise), and will just get additional power (over the minimum) if there is spare in the parcel. If there is none spare, the attraction will just move more sluggishly.

The Conga Dancing Party Line has a minimum and maximum size **(k8s memory)**. It will always get the minimum size specified, but if gets longer than the maximum size, it will be shutdown. Everybody knows that a too long Conga always ends up in wild riots! It will get additional space (over the minimum) if there is spare in the parcel, but if there is none, an attraction that is over its minimum space will be shutdown. It is up to the traffic control tower to decide which one, which could be the Conga Dancing Party Line itself or another.

As there is plenty of room and power, the team has no problem creating all the attractions that you planned. The park is almost ready!

## KubePark opening

To help visitors reach their attraction you decide that the easiest for them is to use a coloured path wayfinder **(k8s [nodePort service](https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport))** like:

![kubernetes nodeport service](https://danlebrero.com/images/blog/kubernetes-explained/kubernetes-nodeport-service.jpg "Kubernetes node port service")

<span style="background-color: #ecf0f1"><small>Image attribution: [London Victoria station floor lines](https://commons.wikimedia.org/wiki/File:Cmglee_London_Victoria_station_floor_lines.jpg "London Victoria station floor lines") by [Cmglee](https://commons.wikimedia.org/wiki/User:Cmglee).</small></span>

Here you have decided to create a blue lane that will take visitors to the attractions that you tagged as “classic” and a green lane that will take them to the attractions that you tagged as “roller coaster”. You can be as specific or generic as you need, and can combine multiple tags if necessary.

This wayfinder is not just for visitors, your internal crew could also use it, and you could even create paths visible to just your crew **(k8s [clusterIP service](https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types))**, for example to find the crew’s canteen.

As the parcels are completely surrounded by barbed wire, you need to somehow let the visitors to come into the park. One option would be to take one of the coloured paths all the way to the barbed wire and make a hole in it **(k8s [loadBalancer service](https://kubernetes.io/docs/concepts/services-networking/service/#type-loadbalancer))**, but this would mean that you will need to somehow secure each and every coloured path. 

So instead you opt to have some admission gates **(k8s [ingress](https://kubernetes.io/docs/concepts/services-networking/ingress/))**. Your landlord provides some standard gates, so that your crew do not need to maintain them, neither they require space or power from your parcels. The landlord will also take care of building an overpass from the gates to the parcels. Maybe in the future you will opt for more specialized admision gates **(k8s like [Traefik](https://docs.traefik.io/user-guide/kubernetes/))**.

You give the admission gates’ crew some simple instructions: 

1. Visitors with kids younger than six, should use the red lane.
1. Visitors with just teenagers, should use the green lane.
1. ...

## Up and running!!!

And with this, your park is ready to roll:

![kubernetes as a picture](https://danlebrero.com/images/blog/kubernetes-explained/kubernetes-explained-in-pictures.jpg "Kubernetes explained in pictures")

## Is that all?

You wish! 

You can read more about Kubernetes [scaling, taints and affinities](https://dev.to/danlebrero/kubernetes-explained-the-theme-park-analogy-auto-scaling-taints-and-affinities-2ced) and [StatefulSets, Persistent Volumes and Headless Services](https://dev.to/danlebrero/kubernetes-explained-in-pictures-statefulsets-persistent-volumes-and-headless-services-5do9)!