Rke2配置了registries.yaml,配置的私库没有生效,certs.d未正常创建,不知是不是和安装时配置修改了data-dir有关

环境信息:
RKE2 版本:
rke2 version v1.33.6+rke2r1 (2c2298232b55a94bd16b059f893c76a950811489)
go version go1.24.9 X:boringcrypto

节点 CPU 架构,操作系统和版本:
Linux k8sqa16 6.8.0-41-generic #41-Ubuntu SMP PREEMPT_DYNAMIC Fri Aug 2 20:41:06 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

集群配置:
3 servers, 3 agents

问题描述:
rke2安装时,配置了config.yaml中
system-default-registry: “repo.test.com:12343
private-registry: “repo.test.com:12343
配置了/etc/rancher/rke2/registries.yaml为
mirrors:
docker.io:
endpoint:
- “https://repo.test.com:12343
集群安装后,系统组件pod的镜像都是repo.test.com:12343,部署自己的应用,应用的镜像却还是从docker.io拉取,没有从私库拉取

重现步骤:

/etc/rancher/rke2/registries.yaml文件的内容如下:
mirrors:
docker.io:
endpoint:
- “https://repo.test.com:12343
安装命令:
INSTALL_RKE2_VERSION=“v1.33.6+rke2r1” INSTALL_RKE2_TYPE=“server” INSTALL_RKE2_METHOD=“tar” INSTALL_RKE2_ARTIFACT_PATH=/space/data/rkeairgap sh install.sh

agent节点的安装配置:
/etc/rancher/rke2/config.yaml的内容为:
server: “https://rancher.test.com:9345
token: “demo-cluster”
data-dir: “/space/lib/rancher/rke2”
system-default-registry: “repo.test.com:12343
private-registry: “repo.test.com:12343

/etc/rancher/rke2/registries.yaml内容为:
mirrors:
docker.io:
endpoint:
- “https://repo.test.com:12343
agent节点的安装命令为:
INSTALL_RKE2_VERSION=“v1.33.6+rke2r1” INSTALL_RKE2_TYPE=“agent” INSTALL_RKE2_METHOD=“tar” INSTALL_RKE2_ARTIFACT_PATH=/space/data/rkeairgap sh install.sh

预期结果:
安装成功的集群,在集群中部署应用:
kubectl create deployment hello-world-test --image=rancher/hello-world --replicas=1 -n test
该应用应该从镜像仓库repo.test.com:12343 拉取镜像
实际结果:
该应用从docker.io拉取镜像,拉取不下来

日志


Failed to pull image “rancher/hello-world”: rpc error: code = DeadlineExceeded desc = failed to pull and unpack image “docker.io/rancher/hello-world:latest”: failed to resolve reference “docker.io/rancher/hello-world:latest”: failed to do request: Head “https://registry-1.docker.io/v2/rancher/hello-world/manifests/latest”: dial tcp 50.17.213.32:443: i/o timeout

你的私有镜像仓库中有这个镜像么?可以直接 pull 下来么?

有私库的,可以直接pull下来。
私库没有问题,之前安装了一个rancher v2.11.3,通过rancher的ui直接创建的rke2,配置的registries也是可以使用的。

他的路径好像是data-dir: “/space/lib/rancher/rke2”,不是使用默认的

安装rke2时,更换了默认的安装目录,配置的私有镜像仓库不生效,是不是rke2配置私有镜像仓库存在bug?
要怎么操作,才能够使用配置的私有镜像仓库@ksd

export CRI_CONFIG_FILE=/var/lib/rancher/rke2/agent/etc/crictl.yaml
/var/lib/rancher/rke2/bin/crictl pull xxxxx

你使用这个命令,从你的私有镜像仓库中拉取镜像,我看看提示的日志是什么,也许是你操作错误导致

xxxx 替换为你要拉取的镜像。

针对你的 config.yaml 配置文件,有几个错误的地方需要你改正:

rke2 server:

  • rke2 server 节点不需要指定 server: https://rancher.test.com:9345,也没有这个参数,你需要去掉
  • private-registry 参数是为了指定 私有注册表配置文件 (默认:“/etc/rancher/rke2/registries.yaml”),所以你也不需要去设置这个参数

rke2 agent:

  • private-registry 参数是为了指定 私有注册表配置文件 (默认:“/etc/rancher/rke2/registries.yaml”),所以你也不需要去设置这个参数
  • system-default-registry 是 rke2 server 节点的参数,所以 agent 节点不需要指定,你得去掉。

理论上,重新调整你的配置,应该就可以拉取镜像了。另外,根据你的配置:

/etc/rancher/rke2/registries.yaml
mirrors:
  docker.io:
    endpoint:
      - "https://repo.test.com:12343"

当你从 docker.io 拉取镜像时,会先从 https://repo.test.com:12343 拉取镜像,如拉取不到才会到 docker.io 去拉取。

这个问题,和数据目录没啥关系,就是单纯的 rke2 配置错误的问题。

1.关于server: https://rancher.test.com:9345 ,rancher.test.com这个是master节点的负载均衡ip的域名,9345是节点注册端口,这个server参数是第二个、第三个master节点的配置,第一个server节点没有这项
2. rke2 server和 rke2 agent安装时,通过 config.yaml文件配置了private-registry参数指定私有仓库,然后安装的集群,当时没有配置 这个私库文件/etc/rancher/rke2/registries.yaml,集群安装成功后,私用helloworld应用测试启动一个demo,应用从docker.io拉取镜像,不是从私库拉取镜像。

之后才在所有的节点上又配置了/etc/rancher/rke2/registries.yaml ,然后重启rke2 server和rke2 agent服务,再次测试部署helloworld的应用,镜像依然是从docker.io拉取,不是从私有仓库拉取

你的 private-registry 配置的是 repo.test.com:12343,你配置错了,你得去掉

终于弄清楚了,private-registry 参数的文档说明为私有镜像仓库配置文件 (默认: “/etc/rancher/rke2/registries.yaml”)(来源于https://docs.rancher.cn/docs/rke2/install/install_options/server_config/),所以private-registry 参数应该配置一个具体的文件路径,配置时受system-default-registry参数的影响,system-default-registry是用于所有系统Docker镜像的私有镜像仓库,以为private-registry 参数也是直接配置私库的。
建议参数private-registry改为private-registry-configfile,避免看不仔细配置错误

感谢KSD的耐心解答