Run a container using “run” command in Kubernetes cluster

To deploy an application in a Kubernetes cluster, the first thing you need to know is how to run a container in it. There are many ways to do this, I will guide you to use the first way is to use the “run” command with kubectl tools!

The basic syntax of the “run” command is as follows:

Inside:

  • <image_name> is the image name that you will use to run the container. Kubernetes supports Docker Hub and some Private Registries such as Google Container Registry, AWS EC2 Container Registry, …
  • <name> is the name of the Deployment after we initialize the container with the image above.

For example, I would now run a container using the image node-hello from the Google Container Registry at https://console.cloud.google.com/gcr/images/google-samples/GLOBAL/node-hello as follows:

Result:

Run a container using "run" command in Kubernetes cluster

As you can see, after running the above statement, a message printed tells us that a Deployment was created “deployment.apps “node-hello” created”. This means that when we run a container in the Kubernetes cluster, the Deployment component is also initialized. This also means, since Deployment manages Pods and Pod replicas, the Pod component is also created.

You can check what I just said by running the following commands:

Check Pod:

Run a container using "run" command in Kubernetes cluster

STATUS “ContainerCreating” means that our command is still running and our container has not been created yet! Please wait a while and check back:

Run a container using "run" command in Kubernetes cluster

Check Deployment:

Run a container using "run" command in Kubernetes cluster

By default, when you run the run command, our container is created and runs underground inside the cluster. To access this container, you can use the following statement:

Inside, container_name is the name of the container in the Pod that we need to access, you can use the command:

to retrieve information of all containers in Pod.

Run a container using "run" command in Kubernetes cluster

If Pod has only one container, we can also use the Pod name to access that container.

My example is as follows:

Run a container using "run" command in Kubernetes cluster

To remove the Deployment as well as Pod that we just created above, you can use the following command:

My example:

Run a container using "run" command in Kubernetes cluster

Chia sẽ bài viết này ...Share on Facebook
Facebook
0Tweet about this on Twitter
Twitter
Share on LinkedIn
Linkedin

Add Comment