2

microk8s 文档“使用私有注册表”让我不确定该怎么做。安全注册表部分说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 应用此文件并执行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
4

1 回答 1

1

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

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

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

更多阅读请查看如何从私有注册表中提取图像。

于 2020-11-23T08:15:22.653 回答