Skip to content

Commit 70a56ae

Browse files
committed
Updates to the image registry doc
Signed-off-by: Martin Hickey <[email protected]>
1 parent 2e3bebb commit 70a56ae

1 file changed

Lines changed: 47 additions & 26 deletions

File tree

docs/registry.md

Lines changed: 47 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
# Configure Image Registry
2+
23
This document describes the method to configure the image registry for `containerd` for use with the `cri` plugin.
34

45
NOTE: The configuration syntax used in this doc is in version 2 which is the
56
recommended since `containerd` 1.3. If your configuration is still in version 1,
67
you can replace `"io.containerd.grpc.v1.cri"` with `cri`.
78

89
## Configure Registry Endpoint
10+
911
With containerd, `docker.io` is the default image registry. You can also set up other image registries similar to docker.
1012

1113
To configure image registries create/modify the `/etc/containerd/config.toml` as follows:
14+
1215
```toml
1316
# Config file is parsed as version 1 by default.
1417
# To use the long form of plugin names set "version = 2"
@@ -35,6 +38,7 @@ that if the default registry endpoint is not already specified in the endpoint l
3538
tried at the end with scheme `https` and path `v2`, e.g. `https://gcr.io/v2` for `gcr.io`.
3639

3740
As an example, for the image `gcr.io/library/busybox:latest`, the endpoints are:
41+
3842
* `gcr.io` is configured: endpoints for `gcr.io` + default endpoint `https://gcr.io/v2`.
3943
* `*` is configured, and `gcr.io` is not: endpoints for `*` + default
4044
endpoint `https://gcr.io/v2`.
@@ -43,9 +47,11 @@ As an example, for the image `gcr.io/library/busybox:latest`, the endpoints are:
4347
After modify this config, you need restart the `containerd` service.
4448

4549
## Configure Registry TLS Communication
50+
4651
`cri` plugin also supports configuring TLS settings when communicating with a registry.
4752

4853
To configure the TLS settings for a specific registry, create/modify the `/etc/containerd/config.toml` as follows:
54+
4955
```toml
5056
# explicitly use v2 config format
5157
version = 2
@@ -58,7 +64,7 @@ version = 2
5864
key_file = "key.pem"
5965
```
6066

61-
In the config example shown above, TLS mutual authentication will be used for communications with the registry endpoint located at https://my.custom.registry.
67+
In the config example shown above, TLS mutual authentication will be used for communications with the registry endpoint located at <https://my.custom.registry>.
6268
`ca_file` is file name of the certificate authority (CA) certificate used to authenticate the x509 certificate/key pair specified by the files respectively pointed to by `cert_file` and `key_file`.
6369

6470
`cert_file` and `key_file` are not needed when TLS mutual authentication is unused.
@@ -86,6 +92,7 @@ version = 2
8692

8793
To configure a credential for a specific registry, create/modify the
8894
`/etc/containerd/config.toml` as follows:
95+
8996
```toml
9097
# explicitly use v2 config format
9198
version = 2
@@ -98,40 +105,51 @@ version = 2
98105
auth = ""
99106
identitytoken = ""
100107
```
108+
101109
The meaning of each field is the same with the corresponding field in `.docker/config.json`.
102110

103111
Please note that auth config passed by CRI takes precedence over this config.
104112
The registry credential in this config will only be used when auth config is
105113
not specified by Kubernetes via CRI.
106114

107-
After modify this config, you need restart the `containerd` service.
115+
After modifying this config, you need to restart the `containerd` service.
108116

109-
### Configure Registry Credentials Example - GCR with _json_key Authentication
117+
### Configure Registry Credentials Example - GCR with service account key authentication
110118

111-
Create a gcp account with gcr, do all the steps to enable receiving a
112-
pushed image for a gcr instance, including the generation and download of a
113-
new _json_key (for a new service account user.) To make sure your
114-
gcr registry is working with _json_key authentication let's login and
115-
push an image to your gcr instance: *This step is not necessary if you have
116-
already pushed an image to your gcr instance.*
119+
If you don't already have Google Container Registry (GCR) set-up then you need to do the following steps:
117120

118-
```bash
119-
$ docker login -u _json_key -p "$(cat key.json)" gcr.io
120-
$ docker push gcr.io/your-gcr-instance-id/busybox
121-
$ docker logout gcr.io
122-
```
121+
* Create a Google Cloud Platform (GCP) account and project if not already created (see [GCP getting started](https://cloud.google.com/gcp/getting-started))
122+
* Enable GCR for your project (see [Quickstart for Container Registry](https://cloud.google.com/container-registry/docs/quickstart))
123+
* For authentication to GCR: Create [service account and JSON key](https://cloud.google.com/container-registry/docs/advanced-authentication#json-key)
124+
* The JSON key file needs to be downloaded to your system from the GCP console
125+
* For access to the GCR storage: Add service account to the GCR storage bucket with storage admin access rights (see [Granting permissions](https://cloud.google.com/container-registry/docs/access-control#grant-bucket))
126+
127+
Refer to [Pushing and pulling images](https://cloud.google.com/container-registry/docs/pushing-and-pulling) for detailed information on the above steps.
123128

124-
Generate a single line for the _json_key file that you downloaded:
129+
> Note: The JSON key file is a multi-line file and can be cumbersome to use its contents as a key outside of file. It is worthwhile generating a single line format output of the file. One way of doing this is using the `jq` tool as follows: `jq -c . key.json`
125130
126-
```bash
127-
jq -c . key.json
131+
It is beneficial to first confirm that from your terminal you can authenticate with your GCR and have access to the storage before hooking it into containerd. This can be verified by performing a login to your GCR and
132+
pushing an image to it as follows:
133+
134+
```console
135+
docker login -u _json_key -p "$(cat key.json)" gcr.io
136+
137+
docker pull busybox
138+
139+
docker tag busybox gcr.io/your-gcp-project-id/busybox
140+
141+
docker push gcr.io/your-gcp-project-id/busybox
142+
143+
docker logout gcr.io
128144
```
129145

130-
Edit the containerd config (default location is at /etc/containerd/config.toml)
131-
to add your _json_key authentication for gcr.io domain image pull
146+
Now that you know you can access your GCR from your terminal, it is now time to try out containerd.
147+
148+
Edit the containerd config (default location is at `/etc/containerd/config.toml`)
149+
to add your JSON key for `gcr.io` domain image pull
132150
requests:
133151

134-
```
152+
```toml
135153
version = 2
136154

137155
[plugins."io.containerd.grpc.v1.cri".registry]
@@ -146,16 +164,19 @@ version = 2
146164
password = 'paste output from jq'
147165
```
148166

149-
Restart containerd
167+
> Note: `username` of `_json_key` signifies that JSON key authentication will be used.
150168
151-
```bash
152-
$ service containerd restart
169+
Restart containerd:
170+
171+
```console
172+
service containerd restart
153173
```
154174

155-
Pull an image from your gcr instance with crictl:
175+
Pull an image from your GCR with `crictl`:
176+
177+
```console
178+
$ sudo crictl pull gcr.io/your-gcp-project-id/busybox
156179

157-
```bash
158-
$ sudo crictl pull gcr.io/your-gcr-instance-id/busybox
159180
DEBU[0000] get image connection
160181
DEBU[0000] connect using endpoint 'unix:///run/containerd/containerd.sock' with '3s' timeout
161182
DEBU[0000] connected successfully using endpoint: unix:///run/containerd/containerd.sock

0 commit comments

Comments
 (0)