我们在腾讯云上有3台主机,准备搭建K8S,为了省钱,只有一台主机有外网,于是,把外网机做k8s-master, 两台内网机做node1,node2。这需要在另外两台主机上做如下设置,才能保证内网机可以下载docker镜像。
- 在外网机上安装squid
- 在内网机上设置:
vi /etc/systemd/system/docker.service.d/http-proxy.conf
[Service]
Environment="HTTP_PROXY=http://10.206.16.3:3128/" "HTTPS_PROXY=http://10.206.16.3:3128/" "NO_PROXY=localhost,127.0.0.1,10.*.*.*"
- 设置环境变量:
export http_proxy="http://10.206.16.3:3128/"
export https_proxy="http://10.206.16.3:3128/"
export no_proxy="localhost,10.0.0.0/8"
另外,由于国内无法访问google, K8S需要的安装包可以用如下阿里镜像,直接上命令:
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.23.3
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.23.3
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.23.3
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.23.3
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.6
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.5.1-0
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:v1.8.6
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.23.3 k8s.gcr.io/kube-apiserver:v1.23.3
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.23.3 k8s.gcr.io/kube-controller-manager:v1.23.3
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.23.3 k8s.gcr.io/kube-scheduler:v1.23.3
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.23.3 k8s.gcr.io/kube-proxy:v1.23.3
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.6 k8s.gcr.io/pause:3.6
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.5.1-0 k8s.gcr.io/etcd:3.5.1-0
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:v1.8.6 k8s.gcr.io/coredns/coredns:v1.8.6
docker rmi registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.23.3
docker rmi registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.23.3
docker rmi registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.23.3
docker rmi registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.23.3
docker rmi registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.6
docker rmi registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.5.1-0
docker rmi registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:v1.8.6