Reputation: 143
On an on-premise Kubernetes Cluster, how to use locally build images in the Kubernetes deployment manifest without having it uploaded to a Docker Registry (like Docker Hub)?
Upvotes: 4
Views: 4859
Reputation: 1721
You already have an on-prem machine. All you need to do is just do a docker build from your dockerfile, do a suitable docker tag and create the manifest.
Kubernetes doesn't directly pull from the registry. First it searches for the image on local storage and then docker registry.
Pull latest nginx image
docker pull nginx
docker tag nginx:latest test:test8970
Create a deployment
kubectl run test --image=test:test8970
It won't go to docker registry to pull the image. It will bring up the pod instantly.
And if image is not present on local machine it will try to pull from docker registry and fail with ErrImagePull error.
Also if you change the imagePullPolicy: Never. It will never look for the registry to pull the image and will fail if image is not found with error ErrImageNeverPull.
kind: Deployment
metadata:
labels:
run: test
name: test
spec:
replicas: 1
selector:
matchLabels:
run: test
template:
metadata:
creationTimestamp: null
labels:
run: test
spec:
containers:
- image: test:test8070
name: test
imagePullPolicy: Never
Upvotes: 3
Reputation: 159790
Except for some very limited developer-oriented setups (like Minikube or Kind), a Docker registry of some form is basically required to run applications on Kubernetes.
The only two ways to get a Docker image on to a system are by running a registry, or to docker load
it. The docker load
path involves transferring a (possibly large) image tar file to every node in the cluster, and running the load
command there. When you update the application image, you'll have to repeat this step; and you generally want to avoid the latest
image tag and similar fixed strings so that the Kubernetes deployment mechanism can correctly update things, so you'll have to repeat this for each version anything in the cluster might still be using. The mechanics of setting up some place to store the image, copying it to every node in the cluster, running docker load
everywhere, etc. aren't actually any easier than just running a Docker registry server yourself.
Upvotes: 3