Deploy image to kubernetes without storing the image in a dockerhub - docker

I'm trying to migrate from docker-maven-plugin to kubernetes-maven-plugin for an test-setup for local development and jenkins-builds. The point of the setup is to eliminate differences between the local development and the jenkins-server. Since docker built the image, the image is stored in the local repository and doesn't have to be uploaded to a central server where the base-images are located. So we can basically verify our build without uploading anything to the server and the images is discarded after the task is done (running integrationstests).
Is there a similar way to trick kubernetes to store the image into the local repository without having to take the roundtrip to a central repository? Eg, behave as if the image is already downloaded? Note that I still need to fetch the base-image from the central repository.

If you don't want to use any docker repo (public or private), you can use what is called Pre-pulled-images.
This is a bit annoying as you need to make sure all the kubernetes nodes have the images there and also set the ImagePullPolicy to Never in every kubernetes manifest.
In your case, if what you call local repository is some private docker registry, you just need to store the credentials to the private registry in a kubernetes secret and either patch you default service account with ImagePullSecrets or your actual deployment/pod manifest. More details about that https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/

Related

Why Use a Private Docker Registry?

Why would someone use a private docker registry when they could just share their dockerfile's in source control and have docker image consumers build directly from the dockerfile with docker build?
To my untrained eye the private docker registry seems to serve the same purpose as source control except it adds complexity because it's been decoupled from the branch of code that you're in and so you (or your CI/CD server more to the point) has to reconstruct which tag to pull.
When you deploy on real machines (say you have a job that deploys on 10 machines), usually you don't really want to rebuild the image over and over again.
Instead you can build image once, store it somewhere (???) then maybe deploy on test environment, run some tests, make sure its a good image indeed (starts, tests pass, etc) and then deploy on production.
So this "somewhere" means that you should have some registry, and if you don't want to use docker hub - you can use private docker registry.
This makes sense from both security (don't publish on cloud if you don't need to)
and performance (moving images between servers in private network is faster).
If you're running kubernetes you can also configure it to pull the images from the docker registry and run pods based on these images as specified in the kubernetes deployment files.
If you're running on AWS you can use docker registry to run services like Fargate or ECS. They will take care of scaling out across machines (pretty much like k8s does) but they still need to take the images from somewhere, well, its a private registry (in this case in the cloud called ECS - Elasctic Container Registry).
Bottom line, in many (simple) cases you can live without it, but in some other cases it comes pretty handy

creating kubernetes pods without using any public/private docker registory

with a new release of our product, we want to move to new technologies(kubernetes) so that we can take advantage of it services. we have a local kubernetes application running in our infra. we have made our applicatons dockerize and now we want to use the images to integrate it with kubernetes to make cluster --pods,
but we are stuck with docker registry as our customer do not want to have any public/private docker repository(registry) where we can upload this images. we have try with (docker save and docker load) but no luck(error: portal-66d9f557bb-dc6kq 0/1 ImagePullBackOff) Is it at all possible to have some filesystem where from we can access this images or any other alternative is welcome if that solves our problems(no private/public repository/registry).
A Docker registry of some sort is all but a requirement to run Kubernetes. Paid Docker Hub supports private images; Google and Amazon both have hosted registry products (GCR and ECR respectively); there are third-party registries; or you can deploy the official registry image locally.
There's an alternative path where you docker save every private image you reference in any Kubernetes pod spec, then docker load it on every single node. This has obvious scale and maintenance problems (whenever anybody updates any image you need to redeploy it by hand to every node). But if you really need to try this, make sure your pod specs specify ImagePullPolicy: Never to avoid trying to fetch things from registries. (If something isn't present on a node the pod will just fail to start up.)
The registry is "just" an open-source (Go) HTTP REST service that implements the Docker registry API, if that helps your deployment story.

Feasibility of Docker image deploying without dockerhub.com and using in Jenkins

I am trying to use Kubernetes and Jenkins for my deployment of micro services developed using Spring Boot. When I am exploring many YouTube videos and other documentation tutorials are using dockerhub.com as keeping published image as repository.
Can I deploy docker image in Kubernetes by using Jenkins docker image build without using this dockerhub.com ? Means I don't want to share client code in a public place. So can I use Jenkins without dockerhub.com?
You do need to use some registry- kubernetes needs a registry URL to be able to pull and instantiate a particular image as a container in a pod. To avoid having the images themselves be publicly accessible you have 2 options:
use a business account at a public registry. You can get one of these from Docker, or from other services like Google or Quay. When you push images using a business account, you get a private space in the public registry and only your account credentials can push and pull those images. In this case your Kubernetes- and your Jenkins- has to be configured with credentials derived from your account to be able to pull those private images into your cluster.
run a private registry in your cluster or on your non-cluster infrastructure There are many flavors of private registries, including Docker's, Atlassian's, and many others. This keeps your images entirely on your infrastructure. The tradeoff is that you have to configure and run this as a production service, and most private registries suitable for production use have a lot of moving parts for scalable image storage, indexing, backup, and so forth.

What is the right way to securely deploy a private docker image on Google Cloud?

I have a docker image in a private docker hub repository. I have created a Google Cloud instance template for load balancing and on-demand instantiation of compute instances. What is the right way to automatically pull the repo on my newly created instances?
The only solution I can come up with is to put my docker login password in the startup script for the instance template. Is that the right approach?
GitHub has deploy keys, which allow me to put the private key in my instance for read only access, which seems like a better strategy, but I can't find anything like that for pulling a docker repo.

Docker CD workflow - making docker hosts pull new images and deploy them

I'm setting up a CI/CD workflow for my organization but I'm missing the final piece of the puzzle. Surely this is a solved problem, or do I have to write my own?
The full picture.
I'm running a few EC2 instances on AWS, each running docker in its native swarm mode. A few services are running here which I've started manually via docker service create ....
When a developer commits source code a trigger is sent to jenkins to pull the new code and build a new docker image which is then pushed to my private registry.
All is well and good up to here, but how do I get the new image onto my docker hosts and the running container automatically updated to the new version?
Docker documentation states (here) that the registry can send events to configurable endpoints when a new image gets pushed onto it. This is what I want to automatically react to by having my docker hosts then pull the new image and stop, destroy and restart the service using that new version (with the same env flags, labels, etc etc), but I'm not finding any solution to this that fits my use case.
I've found v2tec/watchtower but it's not swarm-aware nor can it pull from a private registry at the time of writing this question.
Preferably I want a docker image I can deploy on my docker manager which listens to registry events (after pointing the registry config at it) and does the magic I need.
Cost is an issue, but time is less so, so I'm more inclined writing my own solution than I am adopting a fee-based service for this.
One option you have is to SSH to swarm master from Jenkins using SSH plugin and pull the new image and update the service when new image is pushed to the registry.

Resources