...

/

Accessing a Host’s Resources through hostPath Volumes

Accessing a Host’s Resources through hostPath Volumes

Learn about the hostPath volume type and how to access the host's resources through it.

Building docker images

Sooner or later, we’ll have to build our images. A simple solution would be to execute the docker image build command directly from a server. However, that might cause problems. Building images on a single host means that there is uneven resource utilization and that there is a single point of failure. Wouldn’t it be better if we could build images anywhere inside a Kubernetes cluster?

Instead of executing the docker image build command, we could create a Pod based on the docker image. Kubernetes will make sure that the Pod is scheduled somewhere inside the cluster and so distribute resource usage much better.

Creating a pod with a Docker image

Let’s start with an elementary example. If we can list the images, we’ll prove that running docker commands inside containers works. Since, from Kubernetes’ point of view, Pods are the smallest entity, that’s what we’ll run.

Press + to interact
kubectl run docker \
--image=docker:17.11 --restart=Never \
docker image ls
kubectl get pods

We create a Pod named docker and based it on the official docker image. Since we want to execute a one-shot command, we specify that it should Never restart. Finally, the container command is docker image ls. The second ...