Kubernetes overview

Kubernetes overview and main concepts

view on github

The K8s cluster

Table of contents

  1. Definition
  2. Core K8s concepts
  3. Key takeaways

Definition

Horizontal scaling of containerized apps happen in the context of a K8s cluster :

  1. K8s is a "container cluster manager" : a dynamic system that reacts to conditions and inputs in real time.
  2. As a result, "orchestrator" is improper terminology because it suggests predefined planning and predictable execution.
  3. Additionally, based on experience, a container cluster should include a management layer.
  4. K8s streamlines coordination by allowing developers to :
    • Package a specific workload in a container image.
    • Declaratively specify how and where it should run.
  5. Once it is done, K8s will assume all the placement and communication features of the cluster (see below).

Pod

  • 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.

Labels

  • 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.

Replication controller

  • 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 and template are the cluster desired state, while label_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 of Deployment.
  • Labels are usually associated with pods, but it should be noted that many different kind of objects support labels as well.

Key takeaways

  • A container cluster is a dynamic system that :

    1. Places and manages containers.
    2. Grouped together in pods.
    3. Running on nodes.
    4. Along with all the interconnections and communication channels.
  • The three key components of a cluster management system fit together :

    1. Dynamic container placement.
    2. Thinking in sets of containers.
    3. Connecting within a cluster.