【问题标题】:How to configure microk8s kubernetes to use private container's in https://hub.docker.com/?如何在 https://hub.docker.com/ 中配置 microk8s kubernetes 以使用私有容器?
【发布时间】:2021-03-04 05:19:22
【问题描述】:

microk8s document "Working with a private registry" 让我不知道该怎么办。 Secure registry 部分说 Kubernetes 以一种方式(没有说明 Kubernetes 的方式是否适用于 microk8),而 microk8s 使用 containerd 在其实现中。

我的 YAML 文件包含对 dockerhub 上私有容器的引用。

apiVersion: apps/v1 
kind: Deployment
metadata:
  name: blaw
spec:
  replicas: 1
  selector:
    matchLabels:
      app: blaw
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: blaw
    spec:
      containers:
        - image: johngrabner/py_blaw_service:v0.3.10
          name: py-transcribe-service

当我 microk8s kubectl apply 这个文件并执行 microk8s kubectl describe 时,我得到:

Warning  Failed     16m (x4 over 18m)     kubelet            Failed to pull image "johngrabner/py_blaw_service:v0.3.10": rpc error: code = Unknown desc = failed to pull and unpack image "docker.io/johngrabner/py_blaw_service:v0.3.10": failed to resolve reference "docker.io/johngrabner/py_blaw_service:v0.3.10": pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed

我已验证我可以从控制台执行 docker pull 命令下载此 repo。

使用公共容器的 Pod 在 microk8s 中运行良好。

文件 /var/snap/microk8s/current/args/containerd-template.toml 已经包含使 dockerhub 工作的内容,因为公共容器可以工作。在这个文件中,我发现了

  # 'plugins."io.containerd.grpc.v1.cri".registry' contains config related to the registry
  [plugins."io.containerd.grpc.v1.cri".registry]

    # 'plugins."io.containerd.grpc.v1.cri".registry.mirrors' are namespace to mirror mapping for all namespaces.
    [plugins."io.containerd.grpc.v1.cri".registry.mirrors]
      [plugins."io.containerd.grpc.v1.cri".registry.mirrors."docker.io"]
        endpoint = ["https://registry-1.docker.io", ]
      [plugins."io.containerd.grpc.v1.cri".registry.mirrors."localhost:32000"]
        endpoint = ["http://localhost:32000"]

以上似乎与身份验证无关。

在互联网上,我找到了创建用于存储凭据的秘密的说明,但这也不起作用。

microk8s kubectl create secret generic regcred --from-file=.dockerconfigjson=/home/john/.docker/config.json --type=kubernetes.io/dockerconfigjson

【问题讨论】:

    标签: kubernetes microk8s containerd


    【解决方案1】:

    创建密钥后,您必须设置部署/pod 以使用该密钥来下载映像。这可以通过 imagePullSecrets 来实现,如您提到的 microk8s 文档中所述。

    由于您已经创建了您的秘密,您只需在部署中引用它:

    ...
        spec:
          containers:
            - image: johngrabner/py_blaw_service:v0.3.10
              name: py-transcribe-service
            imagePullSecrets:
            - name: regcred
    ...
    

    更多阅读请查看Pull an Image from a Private Registry.

    【讨论】:

    • 谢谢!这正是我想要的!
    猜你喜欢
    • 2019-08-28
    • 1970-01-01
    • 1970-01-01
    • 2021-07-29
    • 2023-01-12
    • 2020-12-27
    • 2019-09-09
    • 2019-10-08
    • 2020-07-18
    相关资源
    最近更新 更多