Simple Overview of Objects in Kubernetes

Shubham Patil
4 min readNov 3, 2023

--

What are objects in Kubernetes?
Whatever we write in .yml and manifest files is treated as an object in Kubernetes. Kubernetes uses objects to represent the state of our cluster. Objects represent:
1. What containerized applications are running and on which node
2. The policies around how the applications behave, such as restart policies, Upgrades, and fault tolerance

Once we have created Objects, the Kubernetes system will constantly work to ensure the object exists and maintains the cluster’s desired state. Every Kubernetes Object includes 2 nested fields
1. Object Spec: It represents the characteristics we want to have in our object
2. Object Status: It represents the actual state of an object

Basic Kubernetes Objects

  1. POD
    The smallest deployable unit in Kubernetes, representing a single instance of a running process. It can contain one or more containers and shares the same network namespace.
  2. Service
    An abstraction that defines a set of Pods and provides a stable network endpoint for accessing them. Services are used to load balance traffic to Pods.
  3. Volume
    A directory that can be mounted into a container in a Pod. Volumes allow data to persist or be shared between containers in the same Pod.
  4. Namespace
    A logical, virtual cluster within a Kubernetes cluster. Namespaces provide a way to isolate and manage resources, such as Pods and Services, in a multi-tenant environment.
  5. ReplicaSet
    Ensures that a specified number of replicas (Pods) are running at all times. It is part of the desired state management of Pods.
  6. Secrets
    A way to store sensitive information, such as passwords or API keys, securely. Secrets can be mounted as files or environment variables in Pods.
  7. Configmaps
    A mechanism to store configuration data in key-value pairs. ConfigMaps can be used to configure applications running in Pods.
  8. Deployments
    A higher-level abstraction for managing ReplicaSets and Pods. Deployments allow declarative updates to applications and facilitate rolling updates and rollbacks.
  9. Jobs
    A resource for running one or more Pods to perform a task, such as batch processing or running a script to completion. Jobs create Pods until the task succeeds.
  10. Daemonsets
    Ensures that a copy of a Pod runs on all or a subset of nodes in a cluster. It is typically used for running system-level agents, such as log collectors, on every node.

The following features are used to represent the state of an Object:

  • Name
    The “Name” of a Kubernetes object is a unique identifier within its namespace. It is a user-defined string that allows you to refer to and manage the object. For example, the name of a Pod is specified in its metadata and is used to distinguish it from other Pods within the same namespace.
  • Replicas
    “Replicas” are used to specify the desired number of instances or copies of a specific object. It is commonly associated with objects like ReplicaSets, Deployments, and StatefulSets. These controllers ensure that the specified number of replicas is running and maintain that desired state.
  • Image
    “Image” refers to the container image used by a Pod or a container within a Pod. It is defined within the container specification and points to a specific Docker image hosted in a container registry. The image contains the application code, dependencies, and runtime environment.
  • Port
    “Port” is used to define the network port on which a container within a Pod should listen for incoming traffic. For example, in a Pod or Deployment, you can specify the containerPort to determine which port incoming traffic should be directed to. This is crucial for networking and accessing the services hosted in containers.
  • Startup commands
    “Startup commands” are the initial commands or scripts that run when a container starts. These commands are often defined as the command or args in the container specification. They set the initial behavior of the container and can be used to initialize the application or configure the runtime environment. For example, a web server container might specify a startup command to start the web server when the container is launched.

Object Management in Kubernetes
With the help of kubectl, we can create and manage Kubernetes Objects. There are 2 ways to object management:

  1. Imperative commands: These are the commands given via command prompts to modify or create the objects. Here we exactly specify how to accomplish our task.
  2. Declarative Objects: These are commands given inside the .yml or manifest. Here we describe what we want to achieve without describing how to do it

You can get started on understanding one of the Kubernetes Objects: PODs

Hope this was helpful. Please Do share your feedback…..

You can also connect with me via linkedin: https://www.linkedin.com/in/shubhamdpatil/

Happy Learning

--

--

Shubham Patil

M.Tech CSE IIIT Delhi. Ex - Infosys. Love to code. I just try and document here all my learnings