Kubernetes overview
Kubernetes overview and main concepts

Horizontal scaling of containerized apps happen in the context of a K8s cluster :
- K8s is a "container cluster manager" : a dynamic system that reacts to conditions and inputs in real time.
- As a result, "orchestrator" is improper terminology because it suggests predefined planning and predictable execution.
- Additionally, based on experience, a container cluster should include a management layer.
- K8s streamlines coordination by allowing developers to :
- Package a specific workload in a container image.
- Declaratively specify how and where it should run.
- Once it is done, K8s will assume all the placement and communication features of the cluster (see below).
- A set of containers placed and scheduled together as a unit on a single cluster node.
- When a workload scales horizontally across multiple nodes, it becomes a set of pods sharing the same configuration.
- K8s uses two additional concepts to that effect: labels and replication controllers.
- A set of key/value pairs associated with a pod.
- Unopinionated : labels can flag a pod as part of frontend / backend, or as part of controller / domain / data tier etc.
- Sets of pods can be selected by constructing queries based on these labels.
- The pattern K8s uses to handle the horizontal scaling of pods across nodes.
class replication_controller {
// points to cluster
private cluster: k8s_cluster;
// simplified algorithm of the replication controller
runReplicationController(num_desired_pods: number, template: k8s_pod_template, label_selector: k8s_pods_query_by_label): void {
// loop forever
while (true) {
// return the number of running pods matching the query
const num_pods = this.cluster.query(label_selector).length;
// if current cluster state === pods in excess
if (num_pods > num_desired_pods) {
// kill pods to match num_desired_pods
this.cluster.kill_pods(num_pods - num_desired_pods)
// if current cluster state === too few pods
} else if (num_pods < num_desired_pods) {
// create pods from template to match num_desired_pods
this.cluster.create_pods(num_desired_pods - num_pods, template)
}
}
}
}
- Here,
num_desired_pods
andtemplate
are the cluster desired state, whilelabel_selector
is a query that will return its current state. - This example is for illustration purposes only. The actual
ReplicationController
object has been deprecated in favor ofDeployment
. - Labels are usually associated with pods, but it should be noted that many different
kind
of objects support labels as well.
-
A container cluster is a dynamic system that :
- Places and manages containers.
- Grouped together in pods.
- Running on nodes.
- Along with all the interconnections and communication channels.
-
The three key components of a cluster management system fit together :
- Dynamic container placement.
- Thinking in sets of containers.
- Connecting within a cluster.