How to run docker image in AKS without using docker repository - docker

I am using Azure Kubernetes Service(AKS) and I am no allowed to use Docker Hub repository for pushing and pulling Images, so please tell me, is there a way to create kubernetes deployments or pods by using tar of image or by pulling image using ssh connection from other server in which I am having Docker engine running.

I am assuming that the reason why you are not allowed to use Docker Hub is because of the company policy that wants to keep everything private and contained within Azure.
In that case, I suggest using the Azure's own container registry service named Azure Container Registry which have the following benefit:
It works similar to DockerHub in the sense that you can just sign in with username and password, update the image name and you are good to go.
It is the solution from Azure which should fit nicely in your Infrastructure design. Please refer to this link for details instructions on how to connect your AKS and ACR.
The traffic flow from AKS and ACR is private and not exposed to the Internet.

Related

How can I pull a docker image in a Kubernetes cluster from a private registry behind a ssh connection

I’m trying to deploy a docker image on a kubernetes cluster. This cluster is on a server accessible via a ssh connection.
Here is the part of the .yaml I use to pull the image :
spec :
containers :
- name : my_image_name
image : my_private_registry/my_image
my_image is stored in a private registry in another server accessible via a ssh connection (with a proxyjump).
I know how to pull an image from a private registry that is on the same server that the kubernetes cluster. But when it is on another server, I don’t. I'm sure that it is possible to configure kubernetes to make it use the ssh connection, but I didn't find ressources helping me to do that. The others private registry are accessible just by a "docker login" command ?
I’ve found a beginning of solution sending the image using a package named « docker_over_ssh », but it was not really appropriate. I’ve found a solution by pushing the image on dockerhub, but I’m sure that we can do better …
Thank you for your help. I’m sure that it is not complicated, but I’m quite new in kubernetes and docker.
It is quite important to understand, that the docker daemon does not run inside kubernetes. So whatever you provide through kubernetes objects (pods, services...) is usually not accessible from outside.
You could provide a mirror registry for your cluster, so that it is accessible in the usual way.
Another option would be to use ssh port forwarding, if the ssh proxy allows that and use the forwarding host as registry.

Using Docker Registry Serivce Connection in Azure Pipelines

I've followed this docs manual to create a self-signed private registry on some VM. It works fine when I pull images from another host.
I now try to understand how I configure a Service Connection in Azure DevOps of type Docker Registry to use this registry.
This is my current setup:
And this is the log:
We could go to the Docker's Settings > Network and change DNS Server radio button to Fixed
In addition, I found a sample issue, you could also check this.

how to pull docker images from localhost docker private registry to GKE?

I have my own docker private registry created in my host machine[localhost] and I intend to make use of localhost private registry to pull images in google Kubernetes engine.
How do I make it happen?
You won't be able to use either your locally built docker images (which can be listed by running docker images on your local machine) or your locally set up docker private registry (unless you make it available under some public IP which doesn't make much sense if it's your home computer). Those images can be used by your local kubernetes cluster but not by GKE.
In GKE we generally use GCR (Google Container Registry) for storing images that are used by our Kubernetes Engine. We can build them directly from code (e.g. pulled from our github account) on a cloudshell vm (simply click Cloud Shell icon in your GCP Console). You can build them directly on this machine and you can push them to your GCR directly from there.
Alternatively, if you build your images locally, but by "locally" I mean this time the nodes where kubernetes is installed (so in case of GKE they need to be present on every worker node), you can also use them without a need of pulling them from any external registry. The only requirement is that they are available on all kubernetes worker nodes. You can force kubernetes to always use your local images, present on your nodes, instead of trying to pull them from a registry by specifying:
imagePullPolicy: Never
in your Pod or Deployment specification. More details on that you can find in this answer.

Google Cloud Kubernetes accessing private Docker Hub hosted images

Is it possible, to pull private images from Docker Hub to a Google Cloud Kubernetes cluster?
Is this recommended, or do I need to push my private images also to Google Cloud?
I read the documentation, but I found nothing that could explain me this clearly. It seems that it is possible, but I don´t know if it's recommended.
There is no restriction to use any registry you want. If you just use the image name, (e.g., image: nginx) in pod specification, the image will be pulled from public docker hub registry with tag assumed as :latest
As mentioned in the Kubernetes documentation:
The image property of a container supports the same syntax as the
docker command does, including private registries and tags. Private
registries may require keys to read images from them.
Using Google Container Registry
Kubernetes has native support for the Google Container Registry (GCR), when running on Google
Compute Engine (GCE). If you are running your cluster on GCE or Google
Kubernetes Engine, simply use the full image name (e.g.
gcr.io/my_project/image:tag). All pods in a cluster will have read
access to images in this registry.
Using AWS EC2 Container Registry
Kubernetes has native support for the AWS EC2 Container Registry, when nodes are AWS EC2 instances.
Simply use the full image name (e.g.
ACCOUNT.dkr.ecr.REGION.amazonaws.com/imagename:tag) in the Pod
definition. All users of the cluster who can create pods will be able
to run pods that use any of the images in the ECR registry.
Using Azure Container Registry (ACR)
When using Azure Container Registry you can authenticate using either an admin user or a
service principal. In either case, authentication is done via standard
Docker authentication. These instructions assume the azure-cli command
line tool.
You first need to create a registry and generate credentials, complete
documentation for this can be found in the Azure container registry
documentation.
Configuring Nodes to Authenticate to a Private Repository
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.
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 IPs: nodes=$(kubectl get nodes -o jsonpath='{range
.items[*].status.addresses[?(#.type=="ExternalIP")]}{.address}
{end}')
Copy your local .docker/config.json to the home directory of root on each node.
for example: for n in $nodes; do scp ~/.docker/config.json root#$n:/root/.docker/config.json; done
Use cases:
There are a number of solutions for configuring private registries.
Here are some common use cases and suggested solutions.
Cluster running only non-proprietary (e.g. open-source) images. No need to hide images.
Use public images on the Docker hub.
No configuration required.
On GCE/Google Kubernetes Engine, a local mirror is automatically used for improved speed and availability.
Cluster running some proprietary images which should be hidden to those outside the company, but visible to all cluster users.
Use a hosted private Docker registry.
It may be hosted on the Docker Hub, or elsewhere.
Manually configure .docker/config.json on each node as described above.
Or, run an internal private registry behind your firewall with open read access.
No Kubernetes configuration is required.
Or, when on GCE/Google Kubernetes Engine, use the project’s Google Container Registry.
It will work better with cluster autoscaling than manual node configuration.
Or, on a cluster where changing the node configuration is inconvenient, use imagePullSecrets.
Cluster with a proprietary images, a few of which require stricter access control.
Ensure AlwaysPullImages admission controller is active. Otherwise, all Pods potentially have access to all images.
Move sensitive data into a “Secret” resource, instead of packaging it in an image.
A multi-tenant cluster where each tenant needs own private registry.
Ensure AlwaysPullImages admission controller is active. Otherwise, all Pods of all tenants potentially have access to all
images.
Run a private registry with authorization required.
Generate registry credential for each tenant, put into secret, and populate secret to each tenant namespace.
The tenant adds that secret to imagePullSecrets of each namespace.
Consider reading the Pull an Image from a Private Registry document if you decide to use a private registry.
There are 3 types of registries:
Public (Docker Hub, Docker Cloud, Quay, etc.)
Private: This would be a registry running on your local network. An example would be to run a docker container with a registry image.
Restricted: That is one registry that needs some credentials to validate. Google Container Registry (GCR) in an example.
As you are well saying, in a public registry, such as Docker Hub, you can have private images.
Private and Restricted registries are more secure obviously, as one of them is not even exposed to internet (ideally), and the other one needs credentials.
I guess you can achieve an acceptable security level with any of them. So, it is matter of choice. If you feel your application is critical, and you don't want to run any risk, you should have it in GCR, or in a private registry.
If you feel like it is important, but not critical, you could have it in any public repository, making it private. This will give a layer of security.

Replicating a docker registry from azure to aws

I'm searching for a replication solution for a private docker registry from azure to aws (managed container service aws ecr, or my own private hosted docker registry if needed, hopefully not). is there a builtin docker registry option to do that? or other known solution? or perhaps another registry provider that is hosted in AWS - east? my google foo failed me this time.
Please note: This is a question about replication, not about one time migration. Our main registry would still be in azure container registry
There is no native replication options across ACR and ECR. You might be able to integrate with the webhooks and replicate delete/push using the digest and tag to ECR. This might require a custom job (jenkins/VSTS/VM) etc.

Resources