containerd代理¶
由于GFW影响,很多镜像下载都可能出现问题,导致部署非常麻烦。例如在 在Kubernetes部署Stable Diffusion 始终出现镜像下载错误。由于部署的 Kubernetes集群(z-k8s) 采用了 containerd
,虽然 nerdctl 可以通过环境变量配置代理,但是对于远程服务器上的 containerd
也需要通过以下方法配置代理:
containerd客户端代理¶
containerd
客户端代理用于向容器内部注入 proxy 配置,以便容器内部操作系统能够通过代理下载。对于Kubernetes的pod,可以通过 使用ConfigMap配置Pod 向容器内部注入环境变量
配置Docker使用代理 支持客户端代理配置,也就是 $DOCKER_CONFIG/config.json
或者 $DOCKER_CONFIG/config.json
配置代理,可以直接注入到容器内部作为代理配置环境变量。
备注
我还没有找到如何在 containerd 客户端(容器内部)注入代理的方法… 这方面还是 配置Docker使用代理 更为成熟
对于containerd客户端,也就是容器内部,由于都是配置Kubernetes使用,所以可以直接使用Kubernetes的环境变量注入来实现( How to Make the Most of Kubernetes Environment Variables ):
env:
设置secret
containerd服务端代理¶
containerd
服务端代理用于管理物理主机上 containerd
的镜像下载代理
可以直接修改
containerd
的 Systemd进程管理器 启动服务配置/usr/local/lib/systemd/system/containerd.service
:
...
[Service]
Environment="HTTP_PROXY=http://192.168.6.200:3128"
Environment="HTTPS_PROXY=http://192.168.6.200:3128"
ExecStartPre=-/sbin/modprobe overlay
ExecStart=/usr/local/bin/containerd
...
不过,更好的是为
containerd
添加一个独立的配置/etc/systemd/system/containerd.service.d/http-proxy.conf
:
if [ ! -d /etc/systemd/system/containerd.service.d ];then
mkdir -p /etc/systemd/system/containerd.service.d
fi
cat <<EOF >/etc/systemd/system/containerd.service.d/http-proxy.conf
[Service]
Environment="HTTP_PROXY=${HTTP_PROXY:-}"
Environment="HTTPS_PROXY=${HTTPS_PROXY:-}"
Environment="NO_PROXY=${NO_PROXY:-localhost},${LOCAL_NETWORK}"
EOF
systemctl daemon-reload
systemctl restart containerd
那么环境变量该在哪里配置呢?按照约定俗成,应该在 /etc/environemt
设置:
HTTP_PROXY="http://192.168.6.200:3128"
HTTPS_PROXY="http://192.168.6.200:3128"
NO_PROXY="*.baidu.com,192.168.0.0/16,10.0.0.0/8"
重新登陆系统(确保
/etc/environment
环境变量生效)重启containerd
服务:systemctl daemon-reload systemctl restart containerd