在原有虚拟机的基础上克隆一台虚拟机,取名Kubernetes,打开进行如下配置
1、关闭交换空间
swapoff -a2、避免开机启动交换空间
# 注释 swap 开头的行 vi /etc/fstab3、关闭防火墙
ufw disable4、配置DNS
# 取消 DNS 行注释,并增加 DNS 配置:114.114.114.114 vi /etc/systemd/resolved.conf5、安装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-ce6、配置 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://hub-mirror.c.163.com", "https://dockerhub.azk8s.cn", "https://registry.docker-cn.com" ], "storage-driver": "overlay2" }7、安装 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=1.15.4-00 kubeadm=1.15.4-00 kubectl=1.15.4-008、同步时间
设置时区 dpkg-reconfigure tzdata依次选择Asia、Shanghai
时间同步 # 安装 ntpdate apt-get install ntpdate # 设置系统时间与网络时间同步(cn.pool.ntp.org 位于中国的公共 NTP 服务器) ntpdate cn.pool.ntp.org # 将系统时间写入硬件时间 hwclock --systohc 确认时间 date # 输出如下(自行对照与系统时间是否一致) Sun Jun 2 22:02:35 CST 20199、修改 cloud.cfg 主要作用是防止重启后主机名还原
vi /etc/cloud/cloud.cfg # 该配置默认为 false,修改为 true 即可 preserve_hostname: true在Kubernetes基础上克隆三台虚拟机,分别命名为 kubernetes-master、kubernetes-node-01、kubernetes-node-02, 并根据下面表格分别进行配置 1、配置ip 编辑 vi /etc/netplan/50-cloud-init.yaml 配置文件,修改内容如下
network: ethernets: ens33: addresses: [192.168.141.110/24] gateway4: 192.168.141.2 nameservers: addresses: [192.168.141.2] version: 2141处修改成你自己的网段
2、配置主机名
# 修改主机名 hostnamectl set-hostname kubernetes-master # 配置 hosts cat >> /etc/hosts << EOF 192.168.141.110 kubernetes-master EOF3、重启生效
rebootKubernetes(v1.15)安装【2】集 群 安 装(基于Ubuntu18.04)
