Snowcrash, you are correct. This is basically the same as docker run command. So using kubectl run NAME --image=image
will exactly run a pod named NAME
from docker image called image
.
You can check what exactly is happening by using kubectl describe pod NAME
Here is an example of kubectl run nginx --image=nginx
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning FailedScheduling 89s (x2 over 89s) default-scheduler 0/2 nodes are available: 2 node(s) had taints that the pod didn't tolerate.
Normal Scheduled 19s default-scheduler Successfully assigned default/nginx-7cdbd8cdc9-glkxq to centos-master
Normal Pulling 18s kubelet, centos-master pulling image "nginx"
Normal Pulled 14s kubelet, centos-master Successfully pulled image "nginx"
Normal Created 14s kubelet, centos-master Created container
Normal Started 14s kubelet, centos-master Started container
So what happened after kubectl run
is:
Scheduler was trying to pick a node to launch the container (at first
it failed due to a taints, because my node is in NotReady state (not
important at the moment, but you can read more about it here)
Scheduler successfully assigned the pod to the node (centos-master).
The kubelet checks if the docker image is available and pulls it if
necessary.
Then the container is created and started.
*here you can find an interesting article which explains this in a little more detailed way.
The name is associated with pod, because Pod is the smallest unit of work in Kubernetes. Each pod can contain one or more containers. All the containers in the Pod have the same IP address and port space, can access shared storage on the Node hosting that pod.
Basically the kubectl
command-line tool supports several different ways to create and manage Kubernetes objects:
- Imperative commands
- Imperative object configuration
- Declarative object configuration
*you can find more about them in this StackOverflow answer or this Medium article.
run
command is an example of imperative approach. Is the simplest to start
[...] Because this technique operates directly on live objects, it
provides no history of previous configurations.