Run a container using “create” command in Kubernetes cluster

I showed you how to run a container using the “run” command in Kubernetes. This tutorial, I introduce you another way is to use the “create” command with a configuration file!

The syntax of the “create” command is basically the following:

Where <path_to_configuration_file> is the path to the file defining the container information that we need to initialize.

The file defining the container information is a YAML file. The basic content that we need to create a container in this configuration file is as follows:

Inside:

  • <name> is the name of the Pod after running the command “create”
  • <container_name> is the name of the container in the Pod after initialization
  • <container_image> is the name of the image used to create the container.

Here, as you can see, there is a “kind” attribute that defines the component that the “create” command will create in the Kubernetes cluster. My definition is that Pod because the containers are attached to a certain Pod, running the container also means that we create the Pod in the Kubernetes cluster.

Command “create” can also create other components in the Kubernetes cluster according to the “kind” that we define in configuration file!

Now, for example, I have a configuration file with the following contents:

I will create a new container from the above configuration file with the “create” command!

I will run the following statement:

Result:Run a container using "create" command in Kubernetes cluster

Compared to the “run” command, as you can see with the “create” command, depending on the “kind” that we define, the message returned will be different. In my example, because I defined “kind” as Pod, after successfully creating the container, the message “pod “node-hello” created” was printed.

Now you can check the results:

Run a container using "create" command in Kubernetes cluster

There will be no Deployment components created.

Run a container using "create" command in Kubernetes cluster

Pod information:

Run a container using "create" command in Kubernetes cluster

Add Comment