背景
查阅资料
虚拟机配置
集群
172.28.128.10 master1
172.28.128.21 node1
172.28.128.22 node2
启动虚拟机
-
下载镜像
-
启动虚拟机
-
安装系统
-
配置虚拟机信息
- 先根据宿主机 Ethernet adapter VirtualBox Host-Only Network 网卡找到对应网段,如下图所示,我的网段是172.28.128.0,所以我的三个虚拟机也设置对应ip。
-
确定网段,规划好虚拟机的ip后。在虚拟机中编辑文件 /etc/network/interfaces,配置上对应ip。
auto enp0s8 iface enp0s8 inet static address 172.28.128.10 netmask 255.255.255.0
-
网卡名称判断
-
设置虚拟机hostname
-
/etc/hosts 文件添加
172.28.128.10 master1 172.28.128.21 node1 172.28.128.22 node2
系统配置
-
安装工具
apt update apt install ntpdate git vim curl wget jq psmisc net-tools telnet lvm2 apt install ipvsadm ipset sysstat conntrack
-
系统参数
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
echo 'Asia/Shanghai' > /etc/timezone
ntpdate -u ntp1.aliyun.com
# 加入到crontab
sed -i "/ntp.myhuaweicloud.comd" /etc/crontab
echo "*/5 * * * * root /usr/sbin/ntpdate -u ntp1.aliyun.com" >> /etc/crontab
systemctl restart cron
# 关闭防火墙
systemctl stop firewalld 2> /dev/null|| echo ok > /dev/null
systemctl disable firewalld 2> /dev/null|| echo ok > /dev/null
# 关闭swap
swapoff -a && sysctl -w vm.swappiness=0
sed -ri '/^[^#]*swap/s@^@#@' /etc/fstab
#系统优化
cat << EOF > /etc/security/limits.conf
* soft nofile 655360
* hard nofile 131072
* soft nproc 655350
* hard nproc 655350
* soft memlock unlimited
* hard memlock unlimited
root soft nofile 655360
root hard nofile 655360
root soft nproc 655350
root hard nproc 655350
root soft memlock unlimited
root hard memlock unlimited
EOF
cat << EOF >> /etc/sysctl.d/k8s.conf
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
fs.may_detach_mounts = 1
vm.overcommit_memory=1
vm.panic_on_oom=0
fs.inotify.max_user_watches=89100
fs.file-max=52706963
fs.nr_open=52706963
net.netfilter.nf_conntrack_max=2310720
net.ipv4.tcp_keepalive_time = 600
net.ipv4.tcp_keepalive_probes = 3
net.ipv4.tcp_keepalive_intvl =15
net.ipv4.tcp_max_tw_buckets = 36000
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_max_orphans = 327680
net.ipv4.tcp_orphan_retries = 3
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_max_syn_backlog = 16384
net.ipv4.ip_conntrack_max = 65536
net.ipv4.tcp_max_syn_backlog = 16384
net.ipv4.tcp_timestamps = 0
net.core.somaxconn = 16384
EOF
cat << EOF > /etc/modules-load.d/ipvs.conf
ip_vs
ip_vs_lc
ip_vs_wlc
ip_vs_rr
ip_vs_wrr
ip_vs_lblc
ip_vs_lblcr
ip_vs_dh
ip_vs_sh
ip_vs_fo
ip_vs_nq
ip_vs_sed
ip_vs_ftp
ip_vs_sh
nf_conntrack
ip_tables
ip_set
xt_set
ipt_set
ipt_rpfilter
ipt_REJECT
ipip
EOF
复制机器
- 复制出另外两台机器
- 为另外两台虚拟机配置ip及hostname
转载声明:转载请注明来源:https://www.huanghg.com/operation/k8s/setup-k8s-from-scratch-1-virtualbox/,谢谢!-