Saiyam Pathak avatar
By Saiyam Pathak
Director of Technical Evangelism

Description

What are Kubernetes objects and why are they important? Learn how to create a new object, understand the deployment process, and how to access and manage the API resources.


Transcription

Introduction

We'll try to understand what a Kubernetes object means with this video. In Kubernetes, everything happens by the Kubernetes objects. So whatever we want to create, we are creating a Kubernetes object. Now to start, there are two ways. One is the imperative way, and another way is the declarative way via the YAML files. You can also use JSON to create the objects directly or the curl commands, or the CLI SDKs if you are into programming or want to make the resources via the codes.

Creating an object

So, with this particular command, kubectl create deploy nginx --image=nginx --port=80 --dry-run=client -oyaml > deploy.yaml will create an object called deployment in the Kubernetes, and then Kubernetes will manage that. So first, let's look at the contents of the deployment of this particular command to understand the common fields across the Kubernetes objects. The first one is the API version, to which the Kubernetes objects belong. The second one is the kind, which is the object you want to deploy and want the Kubernetes to manage. The third is the metadata section, where you can define the labels and the name of the object. Then comes the spec section, where you define the desired state of this particular object.

In this case, we can see that it's a deployment with replica one and container image Nginx with other fields like Container Port 80. So it will create a deployment, and then the Kubernetes API server will make sure the one replica of the Nginx pod is always running. So to create, the command is simple where we have to remove the dry run. Hence, the command becomes kubectl create deploy nginx --image=nginx --port=80.

Creating a deployment in the YAML file

We will now delete the deployment using the command kubectl delete deploy nginx, and we'll apply the YAML file. So if we want to create the deployments in the YAML file, use the command, kubectl create -f deploy.yaml. So the same deployment gets created by the yaml file. You can check by using the command kubectl get deploy. All the interactions with the Kubernetes objects happen via a kubectl command such as kubectl get, kubectl create, kubectl delete, etc. When we apply this YAML file, it converts the YAML to the JSON and provides that to the API server. Then it is deployed and persisted in the ETCD. So that's how the overall process works.

API resources

Also, if you want to see the API resources, use the command kubectl api-resources. You will see all the API resources that we can create and some of the short names that we can use. For namespaces, you can use the command kubectl get namespace or kubectl get ns. So you can see the short names. All the API versions of different objects have a listing on the resource list. If you're unsure which object belongs to which API version, you can see them from using kubectl api-resources.

In conclusion

So that's pretty much it about Kubernetes objects. Thank you for watching. See you in the next lecture.

Don't stop now, check out your next lesson