Kubectl Create
“Kubectl create” erases the resources before creating them from the given file. “Create” uses an entire file. “Create” works based on each resource’s property. Because of the missing metadata, if you are using the file with the replace instruction, the instruction will abort. The imperative approach includes the choice of creation. This implies we will have to advise the Kubernetes client to conduct the necessary tasks. As a result, it’s similar to a user-guided approach. We refer to kubectl create as essential management. You inform the Kubernetes API of whatever you want to build using this method. kubectl create is the instruction that you are using to create a Kubernetes resource from the command prompt. This is a necessary application. You will, though, receive an exception if the resource previously exists. Let’s look into the specifics of both kubectl commands. Let’s start with kubectl apply.
Practical Implementation of kubectl apply
We will use the Ubuntu 20.04 Linux system for the practical implementation of the Kubectl apply command. We have installed minikube to get the services of Kubernetes in the Ubuntu 20.04 Linux system. So firstly, we have to start minikube in our Ubuntu 20.04 Linux system.
The process will take some time. As quickly as it gets started, you can proceed further. To understand the concept of the kubectl applies command, we are going to create the deployment. Deployments are a collection of many identical Pods with no distinguishing characteristics. Deployments assist in ensuring that one or even more copies of your application are accessible to serve user’s requests in this manner. To create a file having. yaml extension, execute the affixed command.
The file will be created in the home directory; its name may vary as per user preference. A manifest file for a Kubernetes deployment with three copies of an Nginx container image is shown. We have named it” mydeployment” as you can check in line 4 of the attached image.
If you execute the command beneath, the information of this manifest file will be used to establish a deployment.
The output depicts that the deployment has been formed effectively. You will get the following output if you execute the following listed instruction:
You can check the newly created deployment in the above-attached image. We have labeled this deployment “mydeployment”, and it is now operating three pods.
Practical Implementation of kubectl Create
For the practical implementation of the kubectl create command, let’s start to create a deployment with kubectl create. You will receive the following appended result if you run the command shown in the attached image.
From the above-displayed output, understand that you will get an exception if you attempt to use kubectl create on a resource that already occurs. Let’s try using kubectl create to start creating a resource that doesn’t occur. In this scenario, we will use the name “yourdeployment” to name our Kubernetes deployment. We will use the following command to make the deployment:
If everything goes well, you will have the output shown in the attached image.
Let’s make some changes to the initial deployment we made: “mydeployment”. The image shows how to do this by modifying the manifest file, “deployment.YAML”. As seen in the attached image(Line#8), replicas have been raised from 3 to 4.
To change the deployment from 3 to 4 replicas, run kubectl apply command as follows:
The deployment has been completed, according to the output. This indicates that a modification has been made to an existing deployment. To validate that the deployment is truly operating four pods, use the following set kubectl get deployment. You will get something like this as a result:
Conclusion
In this article, the dissimilarity between kubectl apply, and kubectl create been explained in detail along with practical examples. kubectl create can only be cast-off to make a new resource declaratively. On the other side, you can use kubectl apply to state a new Kubernetes resource to use a manifest file using kubectl apply. By updating the configuration in the provided manifest file, you can use kubectl apply to modify an existing resource. I hope you will not have any concerns regarding this guide.