首先要说明一点,我对kubernetes的了解也不是特别的多,正在研究,用二进制包装了一下v1.18.4
版本的,这里记录一下,由于比较多,这里会分好几几次进行分享,本次主要是准备一个基础的操作系统模板,然后后面所有的节点都会基于这个模板进行安装,对了,昨天刚看到,这个6月是kubernetes的生日月,而且是kubernetes的6周岁,在这里祝福它吧,也祝自己能早日驾驭它
这次安装是在我本地的win10上面装了VMware,通过VMware创建的虚拟机,所有的虚拟机都是通过桥接方式连接网络,这里要注意桥接有个坑,有时候可能网络完全不同 可以检查下 在 编辑 -> 虚拟网络编辑器 -> 选择桥接模式 -> 已桥接到 -> 选择自己现在联网的网卡
这里默认的选择可能是自动,也就是他可能自动到一个不是我们希望的网卡上
操作系统选择了Ubuntu而不是CentOS,CentOS系列还是比较保守的,很多基础的软件版本都还是比较老的,避免踩一些不必要的坑,这里选择了Ubuntu 版本是18.40,这是一个LTS版本,操作系统的安装这里就不介绍了
硬件方面,目前的模板是1核2G,20G硬盘,会给boot分区分500MB其余的全部分给了根分区,这里要同步我安装系统是遇到的一个坑,第一次boot分了200MB,在更新系统时要在boot分区内解压内核文件,200MB不够用,所以分了500MB,这里也没有使用LVM,没有什么原因
下面就列出我的一些基础的配置项
设置root密码
由于Ubuntu默认是不能使用root用户的,这里先修改一下其密码
sudo passwd root
su - root
接下来我们就可以使用root用户操作,以下操作都是使用root用户登录
更改网卡名称为ethX格式
vim /etc/default/grub
GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0"
update-grub
reboot
配置IP地址
Ubuntu18.04使用了netplan这个命令进行管理了,对于netplan我也不是特别熟,下面给一个配置文件示例
vim /etc/netplan/01-netcfg.yaml
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: no
addresses: [192.168.1.30/24]
gateway4: 192.168.1.1
nameservers:
addresses: [223.5.5.5]
netplan apply # 使配置文件生效
优化sshd
vim /etc/ssh/sshd_config
PermitRootLogin yes # 允许root远程登录
UseDNS no # 不使用dns反解IP地址,让连接速度更快
X11Forwarding no # 关闭X11转发,这样就无法使用ssh远程操作图形界面了,可以关闭其监听的601x相关的端口
GSSAPIAuthentication no # 不使用GSSAPI进行验证,可以提到加速的作用,老的版本好像会先使用这种方式验证,现在好像也好了,不过我们完全不需要他,可以给他关了
systemctl restart sshd # 重启sshd 之后我们就可以使用root用户进行远程连接了
下面的操作都可以使用远程登录的方式进行操作了
设置PS1
echo 'export PS1="[\u@\[\e[1;32m\]\H\[\e[0m\] \W]\\$ "' >>/etc/profiled.d/env.sh
echo 'export PS1="[\u@\[\e[1;32m\]\H\[\e[0m\] \W]\\$ "' >>~/.bashrc
. ~/.bashrc
生成ssh秘钥
ssh-keygen
ssh-copy-id 192.168.1.10 # 讲秘钥拷贝到本机,方便之后主机之间可以相互免密登录
ssh 192.168.1.10
关闭防火墙
systemctl status ufw
iptables -nvL
systemctl stop ufw
systemctl disable ufw
配置mirror源
这里选择了阿里云提供的镜像源,这里把阿里云提供的配置贴在这里
cd /etc/apt
cp sources.list{,.bak}
vim sources.list
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
设置时区
timedatectl set-timezone Asia/Shanghai
配置自动更新时间
apt udpate
apt install chrony
systemctl status chronyd
systemctl enable chronyd
vim /etc/chrony/chrony.conf # 添加阿里云时间服务器
pool ntp.aliyun.com iburst maxsources 1
性能参数调整
以下这些参数有些我也还没彻底搞清楚,limits配置文件的修改可能需要重启服务器才能正常,对于limits想说一下,也许你的某个配置项配置之后不生效,那么有可能是这个配置项已经被systemd
接管了,可以到/etc/systemd/system.conf
配置文件或者服务的service文件中找到配置项进行修改
vim /etc/security/limits.conf
* soft nofile 65535
* hard nofile 65535
root soft nofile 65535
root hard nofile 65535
vim /etc/sysctl.conf
net.core.somaxconn = 20480
net.core.rmem_default = 262144
net.core.wmem_default = 262144
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_rmem = 4096 4096 16777216
net.ipv4.tcp_wmem = 4096 4096 16777216
net.ipv4.tcp_mem = 786432 2097152 314572
net.ipv4.tcp_max_syn_backlog = 16384
net.core.netdev_max_backlog = 20000
net.ipv4.tcp_fin_timeout = 15
net.ipv4.tcp_max_syn_backlog = 16384
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_max_orphans = 131072
net.ipv4.tcp_syncookies = 0
net.ipv4.ip_local_port_range = 10240 655
# 以下内容为必填加项
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
vm.swappiness=0
net.ipv4.ip_forward = 1
sysctl -p
卸载及安装常用软件
apt update
apt purge ufw lxd lxd-client lxcfs lxc-common
apt install iproute2 nfs-kernel-server nfs-common gcc openssh-server lrzsz tree openssl libssl-dev libpcre3 libpcre3-dev zlib1g-dev ntpdate tcpdump telnet traceroute iotop unzip zip
关闭无用端口
# 111端口
systemctl stop rpcbind.socket
systemctl disable rpcbind.socket
systemctl stop rpcbind
systemctl disable rpcbind
systemctl stop nfs-server
systemctl disable nfs-server
开启message日志
vim /etc/rsyslog.d/50-default.conf
# 取消以下内容的注释
*.=info;*.=notice;*.=warn;\
auth,authpriv.none;\
cron,daemon.none;\
mail,news.none -/var/log/messages
systemctl restart rsyslogd
编译安装OpenSSL,Python,iptables
操作系统提供的OpenSSL和Python都不是最新的,所以这里手动编译一个出来,当然这步是可选的
后面的操作我会使用ansible进行操作,所以这里编译一个Python,还会创建出一个虚拟环境方便我们操作,避免踩一些没必要的坑
对于OpenSSL主要是为了查看,验证证书
对于iptables的编译来说,之前装的时候kube-proxy需要最低1.6.2版本的iptables,而系统提供的恰巧不够,所以这里编译一个出来,不过,我们可能也不会用到它,因为kube-proxy我们使用的是ipvs
# 安装iptables,默认装到/usr/local/sbin中,这个环境变量在前面,所以可以直接使用
apt install gcc make libnftnl-dev libmnl-dev autoconf automake libtool bison flex libnetfilter-conntrack-dev libnetfilter-queue-dev libpcap-dev
wget https://www.netfilter.org/projects/iptables/files/iptables-1.6.2.tar.bz2
tar xf iptables-1.6.2.tar.bz2
cd iptables-1.6.2
./autogen
./configure
make && make install
# 安装OpenSSL
cd /usr/local/src
wget https://github.com/openssl/openssl/archive/OpenSSL_1_1_1g.tar.gz
tar xf OpenSSL_1_1_1g.tar.gz
cd openssl-OpenSSL_1_1_1g
./config shared --prefix=/usr/local/openssl
make && make install
echo /usr/local/openssl/lib >>/etc/ld.so.conf.d/env.conf
ldconfig
ln -sv /usr/local/openssl/include/openssl/ /usr/local/include
# 安装Python
apt install -y make build-essential zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev git libedit-dev
wget https://www.python.org/ftp/python/3.8.2/Python-3.8.2.tar.xz
tar xf Python-3.8.2.tar.xz
cd Python-3.8.2
./configure --prefix=/usr/local/python --enable-shared --enable-ipv6 --with-openssl=/usr/local/openssl --with-ssl-default-suites=openssl --enable-optimizations
make && make altinstall
echo /usr/local/python/lib >> /etc/ld.so.conf.d/env.conf
ldconfig
echo 'export PATH=/usr/local/openssl/bin/:/usr/local/python/bin:$PATH' >> /etc/profile.d/env.sh
. /etc/profile.d/env.sh
cd /usr/local/python/bin
ln -sv python3.8 python
python --version
openssl version -a
安装docker
apt -y install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
apt install docker-ce
docker info
systemctl enable docker
安装指定版本docker
有可能kubernetes的版本不支持最新的,所以有时候需要安装指定的版本
apt-cache madison docker-ce
apt -y install docker-ce=[VERSION]
创建kubernetes安装目录
mkdir /opt/kubernetes/{bin,cfg,ssl,log}
更新系统
apt update
apt dist-upgrade
apt autoclean
apt autoremove
基础模板就到这里了,关闭系统后我会做一个名称为init的快照,后面用到的服务器都会通过这个快照进行创建
下一次博客我会用我了解到的内容简单介绍一下kubernetes以及做一下我们这次安装集群的规划
文章评论(0)