k8s安装挺复杂,我尝试过用二进制安装,比着各种帖子的教程,折腾了半个多月都没成功,于是就放弃了。主要是开始时k8s架构没搞明白,其中涉及的工具及配置太多,对初学者难度极大,所以回过头来先用官网推荐的安装 工具kubeadm把其搞明白,再去尝试使用二进制安装微妙。不过k8s最大的优势是服务容器化,而二进制安装相当于裸机部署,其效用发挥比起使用官网推荐工具kubeadm安装还差些事,对于分析架构是有益的,真正部署我还是选择使用kubeadm。
安装前的准备
0、选择>=5台机器,安装ubuntu、配置网络
(没有raid卡的可以做软raid5+lvm)
apt-get install lvm2 //查看lvm工具
apt-get install install net-tools //网络工具,ubuntu默认不带
# 查看主机名
$ hostname
# 修改主机名
$ hostnamectl set-hostname <your_hostname>
# 配置host,使主节点之间可以通过hostname互相访问
$ vi /etc/hosts
# <node-ip> <node-hostname>
//更换apt软件源为阿里源
vim /etc/apt/sources.list
:%s/archive.ubuntu.com/mirrors.aliyun.com/g
wq
sudo apt-get update
//设置时间同步
sudo apt-get install -y ntpdate
sudo ntpdate times.aliyun.com
sudo timedatectl //查看时区
sudo dpkg-reconfigure tzdata //配置时区,选择shanghai
//关闭防火墙
ufw disable
1、安装docker
//删除旧版本docker(新机器可省略)
apt-get remove docker docker-engine docker.io containerd runc
//安装apt依赖包
sudo apt-get update && sudo apt-get install -y apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
//添加 Docker 的官方 GPG 密钥
curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
sudo apt-key fingerprint 0EBFCD88 //验证您现在是否拥有带有指纹的密钥
//更新仓库镜像地址
sudo add-apt-repository \
“deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/ \
$(lsb_release -cs) \
stable”
sudo apt-get update
//如果上面的证书失效或仓库地址失效,可以试用一下aliyun或清华的源
//阿里源
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
//清华源
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - #安装GPG证书
sudo add-apt-repository "deb [arch=amd64] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
//安装docker
sudo apt-get install docker-ce docker-ce-cli containerd.io
2、放开防火墙
vim /lib/systemd/system/docker.service
//找到ExecStart=XXX,在其下添加
ExecStartPost=/sbin/iptables -I FORWARD -s 0.0.0.0/0 -j ACCEPT
systemctl daemon-reload
systemctl enable docker
service docker start //开启docker
3、修改配置
//将docker下载文件配置到制定目录
mkdir /home/docker
//修改docker.service 文件
ExecStart=/usr/bin/dockerd --graph /home/docker
systemctl daemon-reload
service docker start
docker info //查看配置信息
//支持docker内存限制/配额
//修改/etc/default/grub
GRUB_CMDLINE_LINUX="cgroup_enable=memory swapaccount=1"
sudo update-grub
reboot
//查看是否成功
cat /proc/cmdcline
//关闭swap
sudo swapoff -a //临时
//永久
sudo sed -i 's\.*swap.*\#&\' /etc/fstab