统一环境配置
关闭交换空间
swapoff -a
避免开机启动交换空间
# 注释 swap 开头的行
vi /etc/fstab
关闭防火墙
ufw disable
配置 DNS
# 取消 DNS 行注释,并增加 DNS 配置如:114.114.114.114,修改后重启下计算机
vi /etc/systemd/resolved.conf
安装 Docker
# 更新软件源
sudo apt-get update
# 安装所需依赖
sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common
# 安装 GPG 证书
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
# 新增软件源信息
sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
# 再次更新软件源
sudo apt-get -y update
# 安装 Docker CE 版
sudo apt-get -y install docker-ce
配置 Docker 加速器
在 /etc/docker/daemon.json 中写入如下内容(以下配置修改 cgroup 驱动为 systemd,满足 K8S 建议)
{
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"registry-mirrors": [
"https://rp9zscnl.mirror.aliyuncs.com/",
"https://dockerhub.azk8s.cn",
"https://registry.docker-cn.com"
],
"storage-driver": "overlay2",
"insecure-registries":["192.168.1.152"]
}
安装 Kubernetes 必备工具
# 安装系统工具
apt-get update && apt-get install -y apt-transport-https
# 安装 GPG 证书
curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add -
# 写入软件源;注意:我们用系统代号为 bionic,但目前阿里云不支持,所以沿用 16.04 的 xenial
cat << EOF >/etc/apt/sources.list.d/kubernetes.list
deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
EOF
# 安装
apt-get update && apt-get install -y kubelet kubeadm kubectl
同步时间
设置时区
dpkg-reconfigure tzdata
时间同步
# 安装 ntpdate
apt-get install ntpdate
# 设置系统时间与网络时间同步(cn.pool.ntp.org 位于中国的公共 NTP 服务器)
ntpdate cn.pool.ntp.org
# 将系统时间写入硬件时间
hwclock --systohc
确认时间
date
# 输出如下(自行对照与系统时间是否一致)
Sun Sep 1 14:05:34 CST 2019
修改 cloud.cfg
vi /etc/cloud/cloud.cfg
# 该配置默认为 false,修改为 true 即可
preserve_hostname: true
单独节点配置
配置 IP
network:
ethernets:
eth0:
addresses:
- 192.168.1.212/24
gateway4: 192.168.1.1
nameservers:
addresses:
- 192.168.1.1
version: 2
配置主机名
hostnamectl set-hostname kubernetes-volumes
cat >> /etc/hosts << EOF
192.168.1.220 kubernetes-volumes
EOF
