Centos7 参考:https://www.cnblogs.com/fb010001/p/11516959.htmlhtml
本次安装采用 Ubuntu Server X64 18.04 LTS 版本安装 kubernetes 集群环境,集群节点为 1 主 2 从模式,这次对虚拟机会有些基本要求,以下:node
主机 | IP | 角色 | 系统 | CPU/内存 | 磁盘 |
k8s-master | 192.168.100.120 | master | Ubuntu Server 18.04 | 2核2GB | 20GB |
k8s-node-01 | 192.168.100.121 | node | Ubuntu Server 18.04 | 2核4GB | 20GB |
k8s-node-02 | 192.168.100.122 | node | Ubuntu Server 18.04 | 2核4GB | 20GB |
关闭交换空间 swapoff -a
# 注释 swap 开头的行 vi /etc/fstab
ufw disable
# 取消 DNS 行注释,并增长 DNS 配置如:114.114.114.114,修改后重启下计算机 vi /etc/systemd/resolved.conf
# 更新软件源 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 apt-cache madison docker-ce 若是要安装kebernetes 1.15 请不要安装docker 19.0以上版本 # 安装 Docker CE 版 sudo apt-get -y install docker-ce=18.03.1~ce~3-0~ubuntu
注意: 国内镜像加速可能会很卡,请替换成你本身阿里云镜像加速,地址如:https://yourself.mirror.aliyuncs.com
,在阿里云控制台的 容器镜像服务 -> 镜像加速 菜单中能够找到linux
在 /etc/docker/daemon.json
中写入以下内容(如下配置修改 cgroup
驱动为 systemd
,知足 K8S 建议)docker
{ "exec-opts": ["native.cgroupdriver=systemd"], "log-driver": "json-file", "log-opts": { "max-size": "100m" }, "registry-mirrors": [ "https://k7da99jp.mirror.aliyuncs.com/", "https://dockerhub.azk8s.cn", "https://registry.docker-cn.com" ], "storage-driver": "overlay2" }
安装三个 Kubernetes 必备工具,分别为 kubeadm,kubelet,kubectljson
# 安装系统工具 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-cache madison kubelet # 安装 apt-get update && apt-get update && apt-get install -y kubelet=1.15.5-00 kubeadm=1.15.5-00 kubectl=1.15.5-00
dpkg-reconfigure tzdata
选中亚洲 上海便可ubuntu
# 安装 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 2019
主要做用是防止重启后主机名还原服务器
vi /etc/cloud/cloud.cfg # 该配置默认为 false,修改成 true 便可 preserve_hostname: true
编辑 vi /etc/netplan/50-cloud-init.yaml
配置文件,修改内容以下网络
network: ethernets: ens33: addresses: [192.168.100.110/24] gateway4: 192.168.100.2 nameservers: addresses: [192.168.100.2] version: 2
使用 netplan apply
命令让配置生效app
# 修改主机名 hostnamectl set-hostname k8s-master # 配置 hosts cat >> /etc/hosts << EOF 192.168.100.120 k8s-master EOF