Using Basic Kubernetes Objects
Kubernetes is an object-oriented framework for orchestration of Docker containers. The Kubernetes API supports several different types of objects and provides schemas for all the objects it supports. An object may be defined using a configuration file in the YAML or JSON format, with YAML being preferred.
Let’s look at some of the main Kubernetes objects and their uses.
A pod is an abstraction that defines a set of containers that run as a single unit, as illustrated in figure 1.
A pod is defined in a configuration file with a specification for the desired behavior of the pod. The spec includes the containers to run in the pod, including the Docker image to use and the commands to run in the containers.
You could provision a standalone pod, but the preferred method of running a pod is to use a controller. Several different controllers are available, the most common being a replication controller, replica set, deployment, and stateful set. Controllers use selectors to identify the pods they manage. A deployment has additional configuration settings and is recommended over a replica set or a replication controller.
A replication controller is the simplest of the controllers to create a pod at a specified level of replication. A replication controller was also the first of the controllers to be used widely.
A single command can be used to scale up or down the number of pods in a cluster. If the number of pods exceeds the configured desired level, the extra pods are removed.
If some of the pods were to fail, a replication controller can start replacement pods of the same specification. For example, if one pod in a three-pod application fails, the replication controller will create a replacement pod, as illustrated in figure 2.
You can use a replication controller for development and testing of less complex applications.
A service is an abstraction that runs an application’s interface for a user to interact with the application. A user or a proxy client does not directly send a request to a pod or even a controller, but instead to a named service that is configured to listen on a specific port. A service is mapped to pods via selectors that match which pods to route service requests to.
While running pods and services are essential to all Kubernetes applications, the type of controller to use should be based on several factors, such as the type of application (stateless or stateful), scale of the application, whether a daemon pod is to be run on each node, and the preferred approach (imperative or declarative).
In addition to the basic replication controller, there are more controller options that provide additional features. But the objects described here are the basic essentials needed for working with Kubernetes.