I've set up single node kubernetes according to official tutorial.
In addition to official documentation I've set-up single node cluster:
kubectl taint nodes --all node-role.kubernetes.io/master-Disabled eviction limit:
cat << EOF >> /var/lib/kubelet/config.yaml
evictionHard:
imagefs.available: 1%
memory.available: 100Mi
nodefs.available: 1%
nodefs.inodesFree: 1%
EOF
systemctl daemon-reload
systemctl restart kubeletAnd set systemd driver for Docker:
cat << EOF > /etc/docker/daemon.json
{
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2"
}
EOF
systemctl daemon-reload
systemctl restart docker
I've tried following:
docker build -t localhost:5000/my-image .
kubectl run -it --rm --restart=Always --image=localhost:5000/my-image my-imageBut in pod logs I see ImagePullBackOff. If I setup local repository and I do docker push localhost:5000/my-image after I build image, then everything is working.
Is it is possible to use local images (which are already available after issuing docker images) without needing to setting up local repository, pushing to this repository and then pulling from it?
You simply need to set the imagePullPolicy in your Pod template in the container specification to Never. Otherwise the kubelet will try to pull the image. The example Pod definition may look like this:
apiVersion: v1
kind: Pod
metadata:
name: test
spec:
containers:
- name: uses-local-image
image: local-image-name
imagePullPolicy: NeverMore on that you can find here.
By default, the kubelet will try to pull each image from the specified registry. However, if the
imagePullPolicyproperty of the container is set toIfNotPresentorNever, then a local image is used (preferentially or exclusively, respectively).If you want to rely on pre-pulled images as a substitute for registry authentication, you must ensure all nodes in the cluster have the same pre-pulled images.
This can be used to preload certain images for speed or as an alternative to authenticating to a private registry.
All pods will have read access to any pre-pulled images.
mario's answer is correct. Would be complete with the command though. So, you want to create your deployment as follows:
kubectl run -it --rm --restart Always DEPLOYMENT_NAME --image my-image --image-pull-policy IfNotPresent COMMANDNote: if you'd have more then one node, you would need to ensure on all of them you have an image with that name, as a repo doesn't exist, and it will fail.