k8s - docker/containerd拉取私有仓库镜像

背景:
公司内部搭建Harbor作为镜像仓库,k8s底层为containerd运行时,此时需要拉取私有仓库镜像有两种方案:

  • 第一种,在containerd的配置文件内配上harbor的admin管理员账号的认证信息,那么不管仓库是否是私有,管理员都可以拉取该仓库下的镜像。但是有个弊端,就是如果不同用户的话,只要知道别人的仓库名称和镜像名称等信息,那么底层实际上是可以用别人仓库下的镜像的,这就无法做到用户隔离了。
  • 第二种,每个用户都对应一个namespace,在namespace下创建secret用于记录该用户的harbor账号及密码,用于拉取镜像时通过验证。这里大家可以参考一下官网的文档
    • https://kubernetes.io/zh-cn/docs/tasks/configure-pod-container/pull-image-private-registry/
    • https://kubernetes.io/zh-cn/docs/concepts/configuration/secret/#secret-types

我这边的需求是第二种才满足,但是看官方文档上的,是对docker运行时的应用,这就导致在containerd运行时的时候,需要踩一些坑。

问题点1:harbor走的是http,而不是https,所以需要解决tls验证的问题
解决方法:
k8s - docker/containerd拉取私有仓库镜像_第1张图片

特别注意!!!:这里的配置文件,你的k8s集群上每个节点都要改,不要漏了

vi /etc/containerd/config.toml
修改配置文件


这里我把配置文件直接贴进来

disabled_plugins = []
imports = []
oom_score = 0
plugin_dir = ""
required_plugins = []
root = "/var/lib/containerd"
state = "/run/containerd"
temp = ""
version = 2

[cgroup]
  path = ""

[debug]
  address = ""
  format = ""
  gid = 0
  level = ""
  uid = 0

[grpc]
  address = "/run/containerd/containerd.sock"
  gid = 0
  max_recv_message_size = 16777216
  max_send_message_size = 16777216
  tcp_address = ""
  tcp_tls_ca = ""
  tcp_tls_cert = ""
  tcp_tls_key = ""
  uid = 0

[metrics]
  address = ""
  grpc_histogram = false

[plugins]

  [plugins."io.containerd.gc.v1.scheduler"]
    deletion_threshold = 0
    mutation_threshold = 100
    pause_threshold = 0.02
    schedule_delay = "0s"
    startup_delay = "100ms"

  [plugins."io.containerd.grpc.v1.cri"]
    device_ownership_from_security_context = false
    disable_apparmor = false
    disable_cgroup = false
    disable_hugetlb_controller = true
    disable_proc_mount = false
    disable_tcp_service = true
    enable_selinux = false
    enable_tls_streaming = false
    enable_unprivileged_icmp = false
    enable_unprivileged_ports = false
    ignore_image_defined_volumes = false
    max_concurrent_downloads = 3
    max_container_log_line_size = 16384
    netns_mounts_under_state_dir = false
    restrict_oom_score_adj = false
    sandbox_image = 

你可能感兴趣的:(kubernetes,docker,容器)