Kubernetes Objects Tutorial – The Easy Way

Kubernetes Objects Tutorial – Let’s understand it in an easy way. In this blog post, I will help you to understand kubernetes objects and how we can express those in the .yaml file. Let’s enjoy our post.

Kubernetes Objects

Kubernetes Objects are persistent entities in the Kubernetes system. Kubernetes uses these entities to represent the state of your cluster. Specifically, they can describe:

  • What containerized applications are running (and on which nodes)
  • The resources available to those applications
  • The policies around how those applications behave, such as restart policies, upgrades, and fault-tolerance

Once the kubernetes object is created, the Kubernetes system will check it constantly to make sure that object exists.

Kubernetes Objects Spec and Status

Every Kubernetes object includes 2 nested object fields that describe the object’s configuration:

  • Object spec: describe the characteristics of the object
  • Object status: describe the actual state of the object

For example, a Kubernetes Deployment is an object that can represent an application running on your cluster.

  • Object spec: 3 replicas of the application
  • Object status: 3 replicas are running or 2 replications are running….

Kubernetes Objects Example

Here’s an example .yaml file that shows the required fields and objects spec for a Kubernetes Deployment:

Download: nginx-deployment.yaml

 

The output is similar to this:

Required Fields To Create Kubernetes Objects

  • apiVersion – Which version of the Kubernetes API you’re using to create this object
  • kind – What kind of object you want to create
  • metadata – Data that helps uniquely identify the object, including a name string, UID, and optional namespace

You’ll also need to provide the object spec field. The precise format of the object spec is different for every Kubernetes object, and contains nested fields specific to that object.

Leave a Reply

avatar
  Subscribe  
Notify of