01八、Kubernetes安装前的准备

Centos7 参考:https://www.cnblogs.com/fb010001/p/11516959.htmlhtml

本次安装采用 Ubuntu Server X64 18.04 LTS 版本安装 kubernetes 集群环境,集群节点为 1 主 2 从模式,这次对虚拟机会有些基本要求,以下:node

  • OS:Ubuntu Server X64 18.04 LTS(16.04 版本步骤相同,再以前则不一样)
  • CPU:最低要求,1 CPU 2 核
  • 内存:最低要求,2 GB
  • 磁盘:最低要求,20 GB

kubernetes节点配置

主机 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 行注释,并增长 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
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

配置 Docker 加速

注意: 国内镜像加速可能会很卡,请替换成你本身阿里云镜像加速,地址如: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 必备工具

安装三个 Kubernetes 必备工具,分别为 kubeadmkubeletkubectljson

# 安装系统工具
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

修改 cloud.cfg

主要做用是防止重启后主机名还原服务器

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
相关文章
相关标签/搜索