JucaPirama
JucaPirama

Reputation: 143

Run a locally made container on kubernetes

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

Answers (2)

redzack
redzack

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.

  1. Pull latest nginx image

    docker pull nginx

    docker tag nginx:latest test:test8970

  2. 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. enter image description here

  3. And if image is not present on local machine it will try to pull from docker registry and fail with ErrImagePull error. enter image description here

  4. 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. enter image description here

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

David Maze
David Maze

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

Related Questions