Pulling images from private repository in kubernetes without using imagePullSecrets - docker

I am new to kubernetes deployments so I wanted to know is it possible to pull images from private repo without using imagePullSecrets in the deployment yaml files or is it mandatory to create a docker registry secret and pass that secret in imagePullSecrets.
I also looked at adding imagePullSecrets to a service account but that is not the requirement I woul love to know that if I setup creds in variables can kubernetes use them to pull those images.
Also wanted to know how can it be achieved and reference to a document would work
Thanks in advance.

As long as you're using Docker on your Kubernetes nodes (please note that Docker support has itself recently been deprecated in Kubernetes), you can authenticate the Docker engine on your nodes itself against your private registry.
Essentially, this boils down to running docker login on your machine and then copying the resulting credentials JSON file directly onto your nodes. This, of course, only works if you have direct control over your node configuration.
See the documentation for more information:
If you run Docker on your nodes, you can configure the Docker container runtime to authenticate to a private container registry.
This approach is suitable if you can control node configuration.
Docker stores keys for private registries in the $HOME/.dockercfg or $HOME/.docker/config.json file. If you put the same file in the search paths list below, kubelet uses it as the credential provider when pulling images.
{--root-dir:-/var/lib/kubelet}/config.json
{cwd of kubelet}/config.json
${HOME}/.docker/config.json
/.docker/config.json
{--root-dir:-/var/lib/kubelet}/.dockercfg
{cwd of kubelet}/.dockercfg
${HOME}/.dockercfg
/.dockercfg
Note: You may have to set HOME=/root explicitly in the environment of the kubelet process.
Here are the recommended steps to configuring your nodes to use a private registry. In this example, run these on your desktop/laptop:
Run docker login [server] for each set of credentials you want to use. This updates $HOME/.docker/config.json on your PC.
View $HOME/.docker/config.json in an editor to ensure it contains just the credentials you want to use.
Get a list of your nodes; for example:
if you want the names: nodes=$( kubectl get nodes -o jsonpath='{range.items[*].metadata}{.name} {end}' )
if you want to get the IP addresses: nodes=$( kubectl get nodes -o jsonpath='{range .items[*].status.addresses[?(#.type=="ExternalIP")]}{.address} {end}' )
Copy your local .docker/config.json to one of the search paths list above.
for example, to test this out: for n in $nodes; do scp ~/.docker/config.json root#"$n":/var/lib/kubelet/config.json; done
Note: For production clusters, use a configuration management tool so that you can apply this setting to all the nodes where you need it.

If the Kubernetes cluster is private, you can deploy your own, private (and free) JFrog Container Registry using its Helm Chart in the same cluster.
Once it's running, you should allow anonymous access to the registry to avoid the need for a login in order to pull images.
If you prevent external access, you can still access the internal k8s service created and use it as your "private registry".
Read through the documentation and see the various options.
Another benefit is that JCR (JFrog Container Registry) is also a Helm repository and a generic file repository, so it can be used for more than just Docker images.

Related

eclipse che docker desktop installation is unable to pull images from private docker registry

Aim is to have a default workspace created for each new user.
User will visit the link https://che-eclipse-che.192.168.0.1.nip.io/#https://github.com/test/eclipse-che
It has the devfile to create the workspace.
First user registration will happen via keycloak and then the workspace will be created. This means a new kubernetes namespace will also be created for the user.
The problem is that I need to use an image from a private docker registry but I'm unable to specify the authentication credentials in the devfile. Is there any way to achieve this?
Can not use kubernetes secret because secrets are confined to a namespace.
Withing Che, you can't configure your credentials to be used for every user.
Each is supposed to configure their credentials, if they need access private docker repos. Check https://www.eclipse.org/che/docs/che-7/end-user-guide/using-private-container-registries/
What I can propose to look into:
configure nodes to pull private image https://kubernetes.io/docs/concepts/containers/images/#configuring-nodes-to-authenticate-to-a-private-registry;
push your images to cluster internal docker registry;

What is the difference between GitHub Container Registry and Github Packages for Docker?

GitHub offers two options for storing container images as I understand it: Container Registry and Packages, but I think the difference is not clear.
In a blog post, they say "With GitHub Actions, publishing to GitHub Container Registry is easy." but the given example pushes images to Packages, not Container Registry.
So, can those two platforms be used interchangeably and does one have an advantage over the other?
As already stated by tgogos the GitHub docs guide on Key differences between GitHub Container Registry and the Docker package registry tells us:
The GitHub Container Registry supersedes the existing Packages Docker
registry and is optimized to support some of the unique needs of
containers.
TLDR; The GH Container Registry will replace the Packages Docker Registry. It also focusses more on the GitHub organization level then on a single repository. So you find your container images on the account level for example - and have to link them optionally later to a repository if needed.
Additionally it features anonymous access to Docker images (see the GHCR intro post here).
I guess the reason they are migrating is that they want to cut that name 'Docker' from the registry. The reason being 'Docker' is just another technology for creating images however you can use other CRI (Container Runtime Images) like cri-o, rkt, container-D. These are CNCF active projects. And down the line, container-D might replace the Docker completely as its popularity has increased a lot over the years. AWS ECS has started using the agent based on container-D in their ECS Instances, Kubernetes has stopped supporting Docker as default CRI from v1.22.
So GitHub wants their customer to use the term 'container' (which could be anything as it is generic) rather than just 'Docker' in the future.

How to use customise Ubuntu image for node when GKE cluster create?

I have GKE and I need to use customised Ubuntu image for GKE nodes. I am planning to enable autoscaling. So I require to install TLS certificates to trust the private docker registry in each nodes. It's possible for existing nodes manually. But when I enable auto scale the cluster, it will spin up the nodes. Then docker image pull request will fail, because of the docker cannot trust the private docker registry which hosted in my on premise.
I have created a customised Ubuntu image and uploaded to image in GCP. I was trying to create a GKE and tried to set the node's OS image as that image which I created.
Do you know how to create a GKE cluster with customised Ubuntu Image? Has anyone experienced with incidents like this?
Node pools in GKE are based off GCE instance templates and can't be modified. That means that you aren't allowed to set metadata such as startup-scripts or make them based on custom images.
However, an alternative approach might be deploying a privileged DaemonSet that manipulates the underlying OS settings and resources.
Is important to mention that giving privileges to resources in Kubernetes must be done carefully.
You can add a custom pool where the image is Ubuntu and be sure to add the special GCE instance metadata startup-script and then you can put your customization on it.
But my advice is to put the URL of a shell script stored in a bucket of the same project, GCE will download every time a new node is created and will execute it on the startup as a root.
https://cloud.google.com/compute/docs/startupscript#cloud-storage

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.

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.

Resources