By Andrew Chen and Dominik Tornow

Kubernetes is a Container Orchestration Engine designed to host containerized applications on a set of nodes, commonly referred to as a cluster. Using a systems modeling approach this series aims to advance the understanding of Kubernetes and its underlying concepts.

For this blog post, an advanced understanding of Kubernetes, Kubernetes Objects, and Kubernetes Controllers is recommended.

Kubernetes is characterized as a declarative Container Orchestration Engine: In a declarative system, the user supplies a representation of the desired state of the system to the system. Then, the system considers the current state and the desired state to determine the sequence of commands to transition from current state to desired state.

Therefore, the term “declarative system” sparks the notion of a calculated, coordinated effort with the explicit purpose to transition from the current state to the desired state.

However, this is not how Kubernetes actually works!

Kubernetes does not determine a calculated, coordinated sequence of commands to execute based on the current state and the desired state.

Instead, Kubernetes iteratively determines the next command to execute based on the current state only. If and when no next command can be determined, Kubernetes reached a steady state.

State Transition Mechanics

This paragraph outlines an abstract model of Kubernetes’ state transition semantics. The next paragraphs outline a concrete example based on Deployment Objects and the Deployment Controller.

Listing 1. State Transition Mechanics of Kubernetes

Listing 1. specifies the state transition semantics of Kubernetes: Given a Next Command Function, the system will determine the next command based on the current state, k8s, that transitions the system from its current state, k8s, to its next state, k8s’.

Listing 2. Next Command Function

Conceptually, the Next Command Function is the composition of the Next Command Functions of every Kubernetes Controller.

Listing 3. Steady State Predicate

The sequence of states is terminated by a state k8s.last for which the Next Command function does not yield a next command, a state commonly referred to as Steady State.

Enter Kubernetes Objects

The Kubernetes Object Store is a set of Kubernetes Objects. Kubernetes Objects are data records that come in different flavors, called kinds.

Listing 4. Deployment Object — Record-Of-Fact or Record-Of-Intent?

Listing 4. illustrates a Deployment Object: The Listing states the fact that there exists a Kubernetes Object, so that the object’s

.kind equals Deployment

equals .spec.replicas equals 3

equals .spec.template.spec.containers[0].image equals BusyBox

Enter Kubernetes Controllers

Every Kubernetes Controller contributes to the Next Command function: A Controller is implemented as a continuous process that yields commands based on Kubernetes’ current state.

Listing 5. (Simplified) Deployment Controller

Listing 5. illustrates the the Deployment Controller: The Controller monitors Deployment Objects and for each Object performs a set of conditional statements:

Condition

If there is less than 1 matching ReplicaSet Object

Command

then the Deployment Controller will yield a Create ReplicaSet Command

If there is less than 1 matching ReplicaSet Object then the Deployment Controller will yield a Create ReplicaSet Command Condition

If there is more than 1 matching ReplicaSet Object

Command

then the Deployment Controller will issue a Delete ReplicaSet Command

From the point of view of a Controller, Kubernetes is in steady state if none of the Controller’s conditions are enabled, that is, the Controller will not yield any command.

Cascading Commands

Controllers (may) cascadingly enable each other: