Featured image of post containerd快速切换代理模式

containerd快速切换代理模式

创建配置文件夹:

1
2
mkdir /etc/systemd/system/containerd.service.d/
mkdir /etc/ctr-proxy

创建两个配置文件:

1
2
3
4
5
6
7
touch /etc/ctr-proxy/no-http-proxy.conf
cat > /etc/ctr-proxy/http-proxy.conf <<EOF
[Service]
Environment="HTTP_PROXY=http://yjy-huhc.geostar.com.cn:7897"
Environment="HTTPS_PROXY=http://yjy-huhc.geostar.com.cn:7897"
Environment="NO_PROXY=127.0.0.1,localhost,127.0.0.0/8,.geostar.com.cn,.svc,.cluster.local,10.0.0.0/8,.geori.geo,172.16.0.0/12,192.168.0.0/16"
EOF

定义命令的别名:

1
2
3
4
cat >> ~/.bashrc<<EOF
alias setproxy='rm -f /etc/systemd/system/containerd.service.d/current.conf && ln -s /etc/ctr-proxy/http-proxy.conf /etc/systemd/system/containerd.service.d/current.conf && systemctl daemon-reload && systemctl restart containerd'
alias unsetproxy='rm -f /etc/systemd/system/containerd.service.d/current.conf && ln -s /etc/ctr-proxy/no-http-proxy.conf /etc/systemd/system/containerd.service.d/current.conf && systemctl daemon-reload && systemctl restart containerd'
EOF

source以后就可以用了:

1
2
3
source ~/.bashrc
setproxy
unsetproxy