In another blog post, I explained how we can use a connected registry to bring containers onboard vessels.
In this article, I’ll dive a bit deeper and show you how you can deploy a connected Azure Container Registry, and how it must be configured so that images can be pulled. Scripting is great, as it allows you to automate your deployments.
Let’s dive right into this!
Installing a connected registry
Before we can pull images from a connected registry, we need to install one. This consists of 2 parts:
- Create a connected registry instance in Azure.
- Deploy the required connected registry components on the machine that will actually host the connected registry.
Define a connected registry instance in Azure
When you want to make use of an on-prem connected registry, you first need to define a ‘connected registry’ resource in Azure.
Specify the repositories that must be synced
Create the Connected Registry Azure resource
$repositoriesToSyncString
.ReadOnly
.Deploy the connected registry on-prem components
Get the connection-string of the connected registry
$credentials
object contains a connection-string that we’ll use in the next step.Deploying connected registry service
Create the Connected Registry Azure resource
$repositoriesToSyncString
.ReadOnly
.Deploy the connected registry on-prem components
Get the connection-string of the connected registry
$credentials
object contains a connection-string that we’ll use in the next step.Deploying connected registry service
Getting the Helm chart that is provided by Microsoft is done by executing these commands:
Verify if everything is running correctly by executing kubectl get pods -n connected-registry
.
As you can see, with the above command we specify the connection-string to the connected-registry resource that is defined in Azure.
We also specify that we want to be able to pull images from a private registry using http instead of being required to pull images using https (httpEnabled=true
).
With the sync.chunkSizeInMb
parameter you can specify the size of the chunks in which container layers must be downloaded. If you’re running on a slow or unstable connection, it is advised to set this parameter quite low.
The pvc.storageClassName
specifies that we want to store the container images on local storage of the node. The values that you can specify for this parameter vary per Kubernetes flavor. The local-path
value is a setting that is specific for Rancher’s K3s.
Configure pulling from a private registry
/etc/rancher/k3s/registries.yaml
file. More information on this can be found here.Modify the /etc/rancher/k3s/registries.yaml
file so that it looks like the sample below. Of course, you need to use the IP address that you’ve acquired ($connectedRegistryIp
) instead of the sample address 10.1.1.1
Modifying this file can also be automated using your favorite scripting language. Using Powershell, you can for instance use the powershell-yaml
module to do that. You can find this module here.
Here is the code to do that:
After the registries.yaml
file has been modified, K3s must be restarted for the changes to have effect:
The connected registry is now in place and will start pulling container images from its’ parent Azure Container Registry.
Pulling images from a connected registry
Now that the connected registry components are up and running, we need to configure it so that images can be pulled from the connected registry.
Configure Client Token
$existingRepositories
that we have declared and initialized earlier for this. We can extract the repositories that the client is allowed to pull. Again, let us specify that images can be pulled if they belong to a repository that is in a certain namespace:As can be read from the documentation of the az acr scope-map create
command, each repository must be prefixed with --repository
and must be suffixed with the actions that are allowed for that repository.
The following command does that:
Invoke-Expression
command to avoid problems with the quotes in the $allowedRepositoriesString
variable:Now, we can use the scope map to generate a client access token and add that token to our connected registry:
Create a Pull Secret for the Connected Registry
$token
that we have just generated can be used to create a pull secret for the connected registry:Now you can use this pull secret in your Kubernetes deployments to pull container images from your Connected Registry! Just don’t forget to specify the pull secret in your Kubernetes deployment.yaml manifest.
I hope this article helps you in setting up an Azure Connected Registry!
Frederik