在http_proxy背后的Ubuntu 16.04 安装microk8s

手头刚好有台Ubuntu, 决定装个microk8s玩玩, 没想到还挺曲折,记录下来以备后查。

因为这台Ubuntu没有接到Internate上,所以得使用http_proxy,因为涉及到的软件众多,proxy的设置也很麻烦:

  • 为command line设置代理:

       export http_proxy = http://${ip}:3128
       export https_proxy = http://${ip}:3128

       测试下wget www.google.com 可以工作

  • 为apt-get设置代理

在/etc/apt/apt.conf加入proxy的配置信息

Acquire::http::Proxy "http://9.21.60.170:3128";
Acquire::https::Proxy "http://9.21.60.170:3128";

记住每行的末尾一定要有”;“否则报错。

  • 因为microk8s在Ubuntu上用snap安装最为简便,所以要为snap设置proxy

$ sudo mkdir -p /etc/systemd/system/snapd.service.d/
$ echo -e '[Service]\nEnvironment="http_proxy=http://${ip}:3128/"' \
      | sudo tee /etc/systemd/system/snapd.service.d/http-proxy.conf
$ echo -e '[Service]\nEnvironment="https_proxy=http://${ip}:3128/"' \
      | sudo tee /etc/systemd/system/snapd.service.d/https-proxy.conf
$ sudo systemctl daemon-reload
$ sudo systemctl restart snapd
  • 为docker 设置proxy

mkdir /etc/systemd/system/docker.service.d
touch /etc/systemd/system/docker.service.d/http-proxy.conf

在该文件添加配置

[Service]
Environment="HTTP_PROXY=http://${ip}:3128/“
Environment="HTTPS_PROXY=http://${ip}:3128/“

然后运行:

$ sudo systemctl daemon-reload
$ sudo systemctl show --property Environment docker
$ sudo systemctl restart docker
  • 为microk8s配置proxy

修改${SNAP_DATA}/args/dockerd-env,一般来讲${SNAP_DATA} = /var/snap/microk8s/current

sudo systemctl restart snap.microk8s.daemon-docker.service

到这儿,所有proxy的配置就结束了,注意有两个坑:

  1. 在Ubuntu 16.04上,请安装:microk8s --classic --channel 1.12/stable,比1.12更高的版本,在create pod时都会出现错误:OCI runtime exec failures
  2. Ubuntu 16.04默认安装居然不能支持nfs的mount,这在pod mount一些nfs的volume时会发生错误,记得:sudo apt-get install nfs-common

参考网页:

https://askubuntu.com/questions/89437/how-to-install-packages-with-apt-get-on-a-system-connected-via-proxy

https://askubuntu.com/questions/764610/how-to-install-snap-packages-behind-web-proxy-on-ubuntu-16-04

https://stackoverflow.com/questions/23111631/cannot-download-docker-images-behind-a-proxy

https://github.com/ubuntu/microk8s/issues/344

https://github.com/ubuntu/microk8s/issues/359

你可能感兴趣的:(Cloud)