K8S部署步骤:3-docker安装与卸载

kubernetes系统使用到的的大量组件的docker镜像均来自google,这也正是为什么kubernetes官网明明提供了很完善的部署文档,但是部署难度仍然很大的原因(原因你懂的)。这几章则会教大家安装docker及其私有仓库harbor,并且利用harbor存储用到的镜像。

安装docker ce

Install required packages. yum-utils provides the yum-config-manager utility, and device-mapper-persistent-data and lvm2 are required by the devicemapper storage driver.

$ sudo yum install -y yum-utils \
   device-mapper-persistent-data \
   lvm2

Use the following command to set up the stable repository. You always need the stable repository, even if you want to install builds from the edge or test repositories as well.

$ sudo yum-config-manager \
   --add-repo \
   https://download.docker.com/linux/centos/docker-ce.repo

如果超时了,换成

sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

Optional: Enable the edge and test repositories. These repositories are included in the docker.repo file above but are disabled by default. You can enable them alongside the stable repository.

$ sudo yum-config-manager --enable docker-ce-edge
$ sudo yum-config-manager --enable docker-ce-test

Install the latest version of Docker CE, or go to the next step to install a specific version.

$ sudo yum install docker-ce

注意:我在安装docker-ce的时候报错说少了pigz与另外一个东西,pigz是一个压缩工具,redhat默认源里没有,所以要手动下载

udo yum install -y https://mirrors.aliyun.com/centos/7/extras/x86_64/Packages/pigz-2.3.3-1.el7.centos.x86_64.rpm

同时还要启用redhat的extra仓库

Start Docker.

$ sudo systemctl enable docker
$ sudo systemctl start docker

Verify that docker is installed correctly by running the hello-world image.

$ sudo docker run hello-world

Uninstall Docker CE

Uninstall the Docker package:

$ sudo yum remove docker-ce

Images, containers, volumes, or customized configuration files on your host are not automatically removed. To delete all images, containers, and volumes:

$ sudo rm -rf /var/lib/docker

镜像加速

为了加快pull image的速度,可以使用国内的仓库镜像服务器,同时增加下载的并发数。如果dockerd已经运行,则需要重启dockerd生效。

$ cat > /etc/docker/daemon.json << EOF
{
  "registry-mirrors": ["https://sojq08wg.mirror.aliyuncs.com", "https://docker.mirrors.ustc.edu.cn"],
  "max-concurrent-downloads": 10
}
EOF

docker从1.13版本开始,可能将iptables FORWARD chain的默认策略设置为DROP,从而导致ping其它Node上的Pod IP失败,遇到这种情况时,需要手动设置策略为ACCEPT:

$ sudo iptables -P FORWARD ACCEPT

并且把以下命令写入/etc/rc.local文件中,防止节点重启iptables FORWARD chain的默认策略又还原为DROP

sleep 60 && /sbin/iptables -P FORWARD ACCEPT

你可能感兴趣的:(k8s,kubernetes)