Skip to content

Commit ee11573

Browse files
authored
Merge pull request #32961 from mengjiao-liu/sync_create_hostprocess_pod_zh
[zh]Sync pull-image-private-registry.md
2 parents e6ad243 + d82f6d4 commit ee11573

File tree

1 file changed

+89
-11
lines changed

1 file changed

+89
-11
lines changed

content/zh/docs/tasks/configure-pod-container/pull-image-private-registry.md

Lines changed: 89 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@ weight: 100
1414

1515
<!--
1616
This page shows how to create a Pod that uses a
17-
{{< glossary_tooltip text="Secret" term_id="secret" >}} to pull an image from a
18-
private container image registry or repository.
17+
{{< glossary_tooltip text="Secret" term_id="secret" >}} to pull an image
18+
from a private container image registry or repository. There are many private
19+
registries in use. This task uses [Docker Hub](https://www.docker.com/products/docker-hub)
1920
-->
2021
本文介绍如何使用 {{< glossary_tooltip text="Secret" term_id="secret" >}}
2122
从私有的镜像仓库或代码仓库拉取镜像来创建 Pod。
23+
有很多私有镜像仓库正在使用中。这个任务使用的镜像仓库是
24+
[Docker Hub](https://www.docker.com/products/docker-hub)
2225

2326
{{% thirdparty-content single="true" %}}
2427

@@ -29,10 +32,13 @@ private container image registry or repository.
2932
<!--
3033
* To do this exercise, you need the `docker` command line tool, and a
3134
[Docker ID](https://docs.docker.com/docker-id/) for which you know the password.
35+
* If you are using a different private container registry, you need the command
36+
line tool for that registry and any login information for the registry.
3237
-->
3338

34-
要进行此练习,你需要 `docker` 命令行工具和一个知道密码的
39+
* 要进行此练习,你需要 `docker` 命令行工具和一个知道密码的
3540
[Docker ID](https://docs.docker.com/docker-id/)
41+
* 如果你要使用不同的私有的镜像仓库,你需要有对应镜像仓库的命令行工具和登录信息。
3642

3743
<!-- steps -->
3844

@@ -41,7 +47,7 @@ private container image registry or repository.
4147
4248
On your laptop, you must authenticate with a registry in order to pull a private image:
4349
-->
44-
## 登录 Docker 镜像仓库
50+
## 登录 Docker 镜像仓库 {#log-in-to-docker}
4551

4652
在个人电脑上,要想拉取私有镜像必须在镜像仓库上进行身份验证。
4753

@@ -92,15 +98,77 @@ If you use a Docker credentials store, you won't see that `auth` entry but a `cr
9298
{{< /note >}}
9399

94100
<!--
95-
## Create a Secret in the cluster that holds your authorization token
101+
## Create a Secret based on existing credentials {#registry-secret-existing-credentials}
96102
97-
A Kubernetes cluster uses the Secret of `docker-registry` type to authenticate with a container registry to pull a private image.
103+
A Kubernetes cluster uses the Secret of `kubernetes.io/dockerconfigjson` type to authenticate with
104+
a container registry to pull a private image.
98105
99-
Create this Secret, naming it `regcred`:
106+
If you already ran `docker login`, you can copy
107+
that credential into Kubernetes:
100108
-->
101-
## 在集群中创建保存授权令牌的 Secret
109+
## 创建一个基于现有凭证的 Secret {#registry-secret-existing-credentials}
110+
111+
Kubernetes 集群使用 `kubernetes.io/dockerconfigjson` 类型的
112+
Secret 来通过镜像仓库的身份验证,进而提取私有镜像。
113+
114+
如果你已经运行了 `docker login` 命令,你可以复制该镜像仓库的凭证到 Kubernetes:
102115

103-
Kubernetes 集群使用 `docker-registry` 类型的 Secret 来通过容器仓库的身份验证,进而提取私有映像。
116+
```shell
117+
kubectl create secret generic regcred \
118+
--from-file=.dockerconfigjson=<path/to/.docker/config.json> \
119+
--type=kubernetes.io/dockerconfigjson
120+
```
121+
122+
<!--
123+
If you need more control (for example, to set a namespace or a label on the new
124+
secret) then you can customise the Secret before storing it.
125+
Be sure to:
126+
127+
- set the name of the data item to `.dockerconfigjson`
128+
- base64 encode the Docker configuration file and then paste that string, unbroken
129+
as the value for field `data[".dockerconfigjson"]`
130+
- set `type` to `kubernetes.io/dockerconfigjson`
131+
132+
Example:
133+
-->
134+
如果你需要更多的设置(例如,为新 Secret 设置名字空间或标签),
135+
则可以在存储 Secret 之前对它进行自定义。
136+
请务必:
137+
138+
- 将 data 项中的名称设置为 `.dockerconfigjson`
139+
- 使用 base64 编码方法对 Docker 配置文件进行编码,然后粘贴该字符串的内容,作为字段
140+
`data[".dockerconfigjson"]` 的值
141+
-`type` 设置为 `kubernetes.io/dockerconfigjson`
142+
143+
示例:
144+
145+
```yaml
146+
apiVersion: v1
147+
kind: Secret
148+
metadata:
149+
name: myregistrykey
150+
namespace: awesomeapps
151+
data:
152+
.dockerconfigjson: UmVhbGx5IHJlYWxseSByZWVlZWVlZWVlZWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGxsbGx5eXl5eXl5eXl5eXl5eXl5eXl5eSBsbGxsbGxsbGxsbGxsbG9vb29vb29vb29vb29vb29vb29vb29vb29vb25ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubmdnZ2dnZ2dnZ2dnZ2dnZ2dnZ2cgYXV0aCBrZXlzCg==
153+
type: kubernetes.io/dockerconfigjson
154+
```
155+
156+
<!--
157+
If you get the error message `error: no objects passed to create`, it may mean the base64 encoded string is invalid.
158+
If you get an error message like `Secret "myregistrykey" is invalid: data[.dockerconfigjson]: invalid value ...`, it means
159+
the base64 encoded string in the data was successfully decoded, but could not be parsed as a `.docker/config.json` file.
160+
-->
161+
如果你收到错误消息:`error: no objects passed to create`,
162+
这可能意味着 base64 编码的字符串是无效的。 如果你收到类似
163+
`Secret "myregistrykey" is invalid: data[.dockerconfigjson]: invalid value ...`
164+
的错误消息,则表示数据中的 base64 编码字符串已成功解码,但无法解析为 `.docker/config.json` 文件。
165+
166+
<!--
167+
## Create a Secret by providing credentials on the command line
168+
169+
Create this Secret, naming it `regcred`:
170+
-->
171+
## 在命令行上提供凭证来创建 Secret {#create-a-secret-by-providing-credentials-on-the-command-line}
104172

105173
创建 Secret,命名为 `regcred`:
106174

@@ -136,12 +204,22 @@ You have successfully set your Docker credentials in the cluster as a Secret cal
136204

137205
这样你就成功地将集群中的 Docker 凭证设置为名为 `regcred` 的 Secret。
138206

207+
<!--
208+
Typing secrets on the command line may store them in your shell history unprotected, and
209+
those secrets might also be visible to other users on your PC during the time that
210+
`kubectl` is running.
211+
-->
212+
{{< note >}}
213+
在命令行上键入 Secret 可能会将它们存储在你的 shell 历史记录中而不受保护,
214+
并且这些 Secret 信息也可能在 `kubectl` 运行期间对你 PC 上的其他用户可见。
215+
{{< /note >}}
216+
139217
<!--
140218
## Inspecting the Secret `regcred`
141219

142220
To understand the contents of the `regcred` Secret you created, start by viewing the Secret in YAML format:
143221
-->
144-
## 检查 Secret `regcred`
222+
## 检查 Secret `regcred` {#inspecting-the-secret-regcred}
145223

146224
要了解你创建的 `regcred` Secret 的内容,可以用 YAML 格式进行查看:
147225

@@ -217,7 +295,7 @@ You have successfully set your Docker credentials as a Secret called `regcred` i
217295

218296
Here is a manifest for an example Pod that needs access to your Docker credentials in `regcred`:
219297
-->
220-
## 创建一个使用你的 Secret 的 Pod
298+
## 创建一个使用你的 Secret 的 Pod {#create-a-pod-that-uses-your-secret}
221299

222300
下面是一个 Pod 配置清单示例,该示例中 Pod 需要访问你的 Docker 凭证 `regcred`:
223301

0 commit comments

Comments
 (0)