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
相關文章
相關標籤/搜索