Docker provides a way to run the container using docker run
Or just pull the container image using docker pull
Found a doc showing mapping between docker commands and kubectl.
Can't find docker pull
equivalent in this doc.
If there is no any such equivalent to docker pull
, then is there any way to just pull an image using kubectl
cli.
There is no need to pull by kubernetes in cli.
Why?
Becuase when you run kubectl create -f template.yml
it containe an image and it cjecked that the image is exist or not. If it does not exist it pull image automatically.
It could be a bit tricky, but it is possible to achieve similar to docker pull
results using kubectl
. You just need to know how to exit the containers with zero exit code.
The idea is to pull several images on all nodes in the Kubernetes cluster. For doing this you could create a DaemonSet which will try to create Pods on every applicable node in the cluster. To pull several images at once, just add several initContainers to the DaemonSet template. ImagePullPolicy
set to IfNotPresent
, restartPolicy
set to Never
. Set command
individually to each initContainer to make it exit successfully. You need something like sh -c "exit 0"
, just ensure that container has sh
binary inside, or use another possible command that usually gives you zero exit code: <appname_binary> version
or <appname_binary> --help
.
After applying that DaemonSet to the cluster, Kubernetes creates Pods from DaemonSet templates on each node and runs each initContainer in the Pod in order of presence. Before starting each container kubelet pulls the image required to run that container.
When you see that all DaemonSet Pods completed successfuly - you can be sure that on every node you have all images, required for running those containers.
You can play with nodeAffinity or taints/tolerations if you want to run the DaemonSet only on specific nodes.
You will not find equivalent of docker pull
in Kubernetes because this command is related to images management. Explanation below.
One of Docker
features is abbility to create Images
. You can create your own image using Dockerfile
(docker build .
) or pull from Docker Hub which contains many pre-built images.
If you use pull
command it will just download image, it will not deploy any container.
$ docker pull hello-world
Using default tag: latest
latest: Pulling from library/hello-world
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest fce289e99eb9 5 months ago 1.84kB
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
As you see, $ docker pull
will only display download image. As Docker is also responsible for image management you can pull
or push
images to repository (DockerHub).
To create container in Docker
you have to use $ docker run
. This command will automatically download image and run container.
$ docker run --name mynginx -p 80:80 -d nginx
Unable to find image 'nginx:latest' locally
latest: Pulling from library/nginx
...
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4abf804611a8 nginx "nginx -g 'daemon of…" 4 minutes ago Up 4 minutes 0.0.0.0:80->80/tcp mynginx
In short:
Create
adds a writeable container on top of your image and sets it up for running whatever command you specified in your CMD. The container ID is reported back but it’s not started.
Start
will start any stopped containers. This includes freshly created containers.
Run
is a combination of create and start. It creates the container and starts it.
Kubernetes is container-orchestration system so it is not responsible for creating or edit images. That is why you will not find equivalent of docker pull
(download only image).
Commands like kubectl apply -f <deployment>
with image inside YAML file or kubectl run nginx --image=nginx
are based on images from DockerHub (more like docker create
).
Hope it helped.
In short - no, there is not.
And why would there be? Kubernetes is an orchestration tool for Docker, it will automatically pull pods for you if it needs them, so there's really no need to have a command to pull containers manually.
I think there isn't a kubectl ...
equivalent and some of the reasons might be:
docker pull
an image, you are planning to use it afterwards on your docker host. When you kubectl ...
a deployment, you want the platform to schedule everything. For example if you have many worker nodes and the replicas are going to be scheduled to only two of them, then the other nodes don't have to pull the image.kubectl
is a tool that talks to the API server to control the cluster. It would be wrong to make it also responsible for container images (see, Leaky Abstractions) since you have available a lower level tool that talks to the Container Runtime Interface for that: crictl
.
k8s-master:~$ crictl --help
NAME:
crictl - client for CRI
USAGE:
crictl [global options] command [command options] [arguments...]
VERSION:
v1.12.0
COMMANDS:
attach Attach to a running container
create Create a new container
exec Run a command in a running container
version Display runtime version information
images List images
inspect Display the status of one or more containers
inspecti Return the status of one or more images
inspectp Display the status of one or more pods
logs Fetch the logs of a container
port-forward Forward local port to a pod
ps List containers
pull Pull an image from a registry
...
pic from: www.aquasec.com/wiki/display/containers/Kubernetes+Architecture+101
what takes place with container run-times under the hood is complicated and keeps evolving. Think about this, people started creating Kubernetes clusters and the container engine used was Docker. Then Docker adopted containerd
so we had Kubernetes on top of Docker on top of containerd
, which caused problems like this:
Users won't see Kubernetes pulled images with the
docker images
command... And vice versa, Kubernetes won't see images created bydocker pull
,docker load
ordocker build
commands...source / more details: Kubernetes Containerd Integration Goes GA