我一直在尝试使用私有 init 容器映像运行部署,但收效甚微,我总是收到此错误:
Failed to pull image "private/app": Error: image private/app:latest not found
Error syncing pod, skipping: failed to "StartContainer" for "app" with ErrImagePull: "Error: image private/app:latest not found"
Run Code Online (Sandbox Code Playgroud)
这是我的部署:
"kind": "Deployment"
"apiVersion": "extensions/v1beta1"
"metadata":
"name": "tomcat"
"creationTimestamp": null
"spec":
"replicas": 1
"template":
"metadata":
"creationTimestamp": null
"labels":
"service": "tomcat"
"annotations":
"pod.beta.kubernetes.io/init-containers": '[
{
"name": "app",
"image": "private/app",
"imagePullPolicy": "IfNotPresent"
}
]'
"spec":
"containers":
- "name": "tomcat"
"image": "private/tomcat"
"ports":
- "containerPort": 8080
"protocol": "TCP"
"imagePullSecrets":
- "name": "my-secret"
"restartPolicy": "Always"
"strategy": {}
"status": {}
Run Code Online (Sandbox Code Playgroud)
我还尝试了使用私有 repo在这里kubernetes init 容器建议的更改:
"pod.beta.kubernetes.io/init-containers": '[
{
"name": "app",
"image": "private/app",
"imagePullPolicy": "IfNotPresent",
"imagePullSecrets": [
{
"name": "my-secret"
}
]
}
]'
Run Code Online (Sandbox Code Playgroud)
但是还是没有...
请注意,我已经在没有 init 容器的情况下测试了此部署,并且图像拉取成功。
另请注意,这是我实际配置的简化版本,在实际配置中,容器和一些 env 变量都有卷安装。
如何为初始化容器配置“imagePullSecrets”?
编辑: 我在 kubernetes slack 频道中四处询问,似乎我忘记授予集群 docker 用户(CI docker 用户,如果你愿意的话)对这个集线器存储库的权限,一旦我这样做了 init 容器上的“imagePullPolicy”是多余的,“模板”>“规格”上的那个就足够了。
谢谢@koki,无论您身在何处。
你应该使用secret对象。
像这样的东西:
kubectl create secret docker-registry myregistry \
--docker-server=https://example.io \
--docker-username=foo \
--docker-password=boosecret \
--docker-email=example@boo.com
Run Code Online (Sandbox Code Playgroud)
并在另一个对象中使用它,如下所示:
imagePullSecrets:
- name: myregistry
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2272 次 |
| 最近记录: |