Kubernetes:1.初始化并安装 Docker CE

参考:https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/

环境

[20:27:27 root@centos-manager-01 ~ #]cat /etc/centos-release
CentOS Linux release 7.6.1810 (Core)

第零步:在开始之前

https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/

1.验证 MAC 地址和 product_uuid 在每个节点都是唯一的

## 获取 MAC 地址
ip link
ifconfig -a

## 获取 product_uuid
cat /sys/class/dmi/id/product_uuid

2.检查网络适配器

如果您有多个网络适配器,并且在默认路由上无法访问您的 Kubernetes 组件,我们建议您添加 IP 路由,以便通过适当的适配器访问 Kubernetes 集群地址

3.检查所需的端口

## Control-plane node(s)
协议    方向        端口范围        目的                        使用者
TCP     Inbound     6443*           Kubernetes API server       All
TCP     Inbound     2379-2380       etcd server client API      kube-apiserver, etcd
TCP     Inbound     10250           Kubelet API                 Self, Control plane
TCP     Inbound     10251           kube-scheduler              Self
TCP     Inbound     10252           kube-controller-manager     Self

## Worker node(s)
协议    方向        端口范围        目的                        使用者
TCP     Inbound     10250           Kubelet API                 Self, Control plane
TCP     Inbound     30000-32767 N   odePort Services**          All

4.Installing runtime

从 v1.6.0开始,Kubernetes默认启用了 CRI(Container Runtime Interface)
Since v1.14.0, kubeadm will try to automatically detect the container runtime on Linux nodes by scanning through a list of well known domain sockets. The detectable runtimes and the socket paths, that are used, can be found in the table below.
从v1.14.0开始,kubeadm将尝试通过扫描众所周知的套接字列表来自动检测Linux节点上的容器运行时。 可以在下表中找到所使用的可检测运行时和套接字路径。

Runtime         Domain Socket
Docker          /var/run/docker.sock
containerd      /run/containerd/containerd.sock
CRI-O           /var/run/crio/crio.sock

如果同时检测到 Docker 和 containerd,则 Docker 优先,因为 Docker 18.09 附带了containerd,两者都是可以检测到的
如果检测到两个或更多个 runtime  时,kubeadm 将退出并报错。
在非 Linux 节点上,默认情况下使用的是 Docker
如果选择的 runtime 是 Docker 则 kubelet 将使用内置的 dockershim CRI 实现它。

第一步.安装 Docker CE

## 在每台计算机上,安装Docker。建议使用版本18.06.2,但已知1.11,1.12,1.13,17.03和18.09也可以使用。
## https://docs.docker.com/install/linux/docker-ce/centos/

## 1.卸载老版本
yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine
## 2.安装依赖项
yum install -y yum-utils \
                device-mapper-persistent-data \
                lvm2
## 3.使用以下命令设置稳定存储库
yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

## 4.安装 Docker-CE
yum -y install docker-ce-18.06.2.ce

## 5.启动 Docker
systemctl enable docker
systemctl stop docker
systemctl start docker
systemctl status docker

## 6.运行以下命令,验证安装
## docker run hello-world

## 7.查看和安装特定版本
## yum list docker-ce --showduplicates | sort -r
## yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io

## 8.卸载 Docker CE
## yum remove docker-ce
## rm -rf /var/lib/docker

第二步:系统优化相关

################################################################################################
## 禁用 SELinux
################################################################################################
setenforce 0
sed -i -r "/^SELINUX=/c SELINUX=disabled" /etc/selinux/config

################################################################################################
## 禁用防火墙
################################################################################################
systemctl stop firewalld
systemctl disable firewalld
systemctl stop iptables || service iptables stop
systemctl disable iptables || chkconfig iptables off

################################################################################################
## 禁用IPV6
################################################################################################
echo 'net.ipv6.conf.all.disable_ipv6=1' >> /etc/sysctl.conf
echo 'net.ipv6.conf.default.disable_ipv6=1' >> /etc/sysctl.conf
sysctl -p

################################################################################################
## IPVS 相关
################################################################################################
yum install -y ipvsadm ipset
## 加载 IPVS 模块
## 设置脚本以保证在节点重启后能自动加载所需模块
cat <<\EOF > /etc/sysconfig/modules/ipvs.modules
#!/bin/bash
modprobe -- ip_vs
modprobe -- ip_vs_rr
modprobe -- ip_vs_wrr
modprobe -- ip_vs_sh
modprobe -- nf_conntrack_ipv4
EOF
chmod +x /etc/sysconfig/modules/ipvs.modules
/etc/sysconfig/modules/ipvs.modules

################################################################################################
## 修改系统参数
################################################################################################
ulimit -u 65535
ulimit -n 65535
sed -i '/nofile/d' /etc/security/limits.conf
cat <<\EOF >>/etc/security/limits.conf
* soft nofile 65535
* hard nofile 65535
* soft nproc 65535
* hard nproc 65535
EOF

## RHEL / CentOS 7上的一些用户报告了由于iptables被绕过而导致流量路由不正确的问题。
## 您应该确保 net.bridge.bridge-nf-call-iptables在sysctl配置中设置为1 ,例如
echo "net.bridge.bridge-nf-call-iptables = 1" >>/etc/sysctl.conf
echo "net.bridge.bridge-nf-call-ip6tables = 1" >>/etc/sysctl.conf
sysctl -p

################################################################################################
## 内核调优
## 参考:https://www.rancher.cn/docs/rancher/v2.x/cn/install-prepare/best-practices/os/
################################################################################################
cat <<\EOF >> /etc/sysctl.conf
net.ipv4.ip_forward=1
net.ipv4.conf.all.forwarding=1
net.ipv4.neigh.default.gc_thresh1=4096
net.ipv4.neigh.default.gc_thresh2=6144
net.ipv4.neigh.default.gc_thresh3=8192
net.ipv4.neigh.default.gc_interval=60
net.ipv4.neigh.default.gc_stale_time=120
EOF
sysctl -p

################################################################################################
## 禁用 SWAP
################################################################################################
swapoff -a
sed -i 's/.*swap.*/#&/' /etc/fstab

################################################################################################
## 调整 Docker cgroup driver
##  [WARNING IsDockerSystemdCheck]: detected "cgroupfs" as the Docker cgroup driver. The recommended driver is "systemd". 
## Please follow the guide at https://kubernetes.io/docs/setup/cri/
################################################################################################
cat > /etc/docker/daemon.json <<EOF
{
  "exec-opts": ["native.cgroupdriver=systemd"],
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "100m"
  },
  "storage-driver": "overlay2",
  "storage-opts": [
    "overlay2.override_kernel_check=true"
  ]
}
EOF

mkdir -p /etc/systemd/system/docker.service.d
systemctl daemon-reload
systemctl restart docker

################################################################################################
## 让docker命令支持子命令的自动补全
################################################################################################
yum install -y bash-completion
source /usr/share/bash-completion/completions/docker
bash /usr/share/bash-completion/bash_completion
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容