What are objects in Kubernetes?

An object in Kubernetes is a component that represents a particular aspect of the cluster's desired state. Pods, nodes, and services are just a few examples of the various components of Kubernetes clusters that are represented as objects.

A JSON or YAML file containing a set of key-value pairs that define the desired state of the object. For example, a pod object might include information about the container image to use, the number of replicas to run, and the resource limits for the containers.

Objects in Kubernetes are created, updated, and deleted using the Kubernetes API, which is a RESTfUL API that allows you to manipulate objects using HTTP requests. We can use the Kubernetes command-line tool kubectl to interact with the API and manage objects in the cluster.

Following are the different types of objects in Kubernetes:

  1. Pod: A pod is the basic unit of deployment in Kubernetes. It represents a group of one or more containers that should be run on the same node.

  2. Service: A service is a logical grouping of pods that provinces a stable network endpoint for accessing the pods.

  3. Deployment: A deployment is a resource that manages a set of replicas of a pod. It helps you declaratively specify the desired state of your application, and it will automatically roll out updates to the pods as needed.

  4. ReplicaSet: A ReplicaSet is a resource that ensures a certain number of replicas of a pod are running at any given time. It is used to ensure that the desired number of pods is always running, even if some pods fail or are deleted.

  5. StatefulSet: A StatefulSet is a resource that manages a set of replicas of a pod and provides guarantees about the ordering and uniqueness of the pods. It is used to manage stateful applications, such as databases, that require a specific ordering and naming of their pods.

  6. Job: A Job is a resource that runs a batch of work to completion. It is used to run short-lived, non-parallel tasks in a cluster.

  7. CronJob: A CronJob is a resource that runs a job on a schedule. It is used to run periodic tasks in a cluster.

There are more objects in Kubernetes like Secretes, ConfigMaps, Daemonsets, etc.

Relationship between these objects

  • Pod manages containers.

  • ReplicaSet manages Pods

  • Service exposes pod processes to the outside world.

  • ConfigMaps and Secretes help you configure pods.

Kubernetes Object Management

The kubectl command line tool supports several different ways to create and manage Kubernetes objects:

  1. Imperative Commands: Explicitly tells “how to accomplish it”. For example, using a command line tool with live objects to accomplish tasks.

  2. Declarative Commands: Describe “What you are trying to accomplish”, without instructing how to do it. For example, using a manifest file like YAML or JSON to describe the desired state.

Kubernetes Configuration

Kubernetes can be installed in many ways:

  1. All-in-one single-node installation: Both the master and worker components are installed in a single node. For testing, development, and learning, this is incredibly helpful. Production facilities shouldn't employ this kind of installation. One such example is MiniKube.

  2. Single Node etcd, Single-Master, and Multi Worker Installation: In this setup, we have a single master node, which also runs a single node etcd instance. Multiple worker nodes are connected to the master node.

  3. Single node etcd, Multi-Master, and Multi Worker installation: In this, we have multiple master nodes, which work in an HA mode, but we have a single node etcd instance. Multiple worker nodes are connected to the master node.