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