欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

kubeadm安装k8s v1.13.1 HA详细教程之一:环境准备

程序员文章站 2022-03-07 13:22:36
...

本文首发自个人博客:https://blog.smile13.com/articles/2019/01/13/1547376380025.html

环境准备(所有节点都需要操作)

1.服务器信息

server count: 7
server version: Centos7.4

2.节点规划

192.168.158.131 k8s01 etcd、Master、Node、keepalived
192.168.158.132 k8s02 etcd、Master、Node、keepalived
192.168.158.133 k8s03 etcd、Master、Node、keepalived
192.168.158.134 k8s04 node
192.168.158.135 k8s05 node
192.168.158.136 k8s06 node
192.168.158.137 k8s07 node
192.168.158.138 k8s08 k8s-cluster.smile13.com (VIP)

3.关闭防火墙

sudo systemctl stop firewalld && sudo systemctl disable firewalld

4.关闭Sexlinux

sed -i ‘/SELINUX=enforcing/d’ /etc/selinux/config
sed -i ‘/SELINUX=disabled/d’ /etc/selinux/config
echo “SELINUX=disabled” >> /etc/selinux/config
重启后生效。

5.安装ntp同步时间

# yum -y install ntp

修改配置文件/etc/ntp.conf
注释掉原有的server指向把时间服务器的域名地址指向一个靠谱可连的时间服务器,我选择的是ntp1.aliyun.com.

# vi /etc/ntp.conf
……
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst 

server ntp1.aliyun.com iburst
......

启动ntp并加入开机启动
# systemctl start ntpd
# systemctl enable ntpd
Created symlink from /etc/systemd/system/multi-user.target.wants/ntpd.service to /usr/lib/systemd/system/ntpd.service.

注意:在启动之前,先使用ntpdate手动同步一下时间,免得本机与对时中心时间差距太大,使得ntpd不能正常同步。这里选用ntp1.aliyun.com作为对时中心:sudo ntpdate -u ntp1.aliyun.com

6.配置ssh,实现节点见的无秘密登录

6.1生成**

ssh-****** -t rsa   #输入之后一直选择enter即可。生成的秘钥位于 ~/.ssh文件夹下。可用cd 命令进入查看。

6.2 导入authorized_keys

cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

6.3 远程无密码登录(把各个主机上的authorized_keys拷贝到其他主机的相应目录下)

cat ~/.ssh/id_rsa.pub | ssh -p 22 [email protected] 'cat >> ~/.ssh/authorized_keys'

6.4 修改authorized_keys文件的权限(必须为600,否则不能免密码登陆)

chmod 600 ~/.ssh/authorized_keys

7.关闭swap

swapoff -a

然后再打开文件/etc/fstab,找到swap有关的一行,如下图红框所示,在这一行的最左边加上"#",将该行注释掉:
#
# /etc/fstab
# Created by anaconda on Fri Jul 20 23:01:49 2018
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=f5f7670b-9aaf-414c-8e5e-50cb33e81d48 /                       xfs     defaults        0 0
UUID=8ef45b9a-a906-40a9-a51c-af05d3d13766 /boot                   xfs     defaults        0 0
#UUID=26981930-f538-4a6f-a055-6ca7a5a51112 swap                    swap    defaults        0 0

执行free -m命令检查,swap值应该都为0了

[[email protected] ~]# free -m
.              total        used        free      shared  buff/cache   available
Mem:          29443         181       28985           8         276       28865
Swap:             0           0           0

8.配置ipvs支持

[[email protected] ~]# cat /etc/sysconfig/modules/ipvs.modules
#!/bin/bash
modprobe -- ip_vs
modprobe -- ip_vs_rr
modprobe -- ip_vs_wrr
modprobe -- ip_vs_sh
modprobe -- nf_conntrack_ipv4

上面脚本创建了的/etc/sysconfig/modules/ipvs.modules文件,保证在节点重启后能自动加载所需模块。

查看是否已经正确加载所需的内核模块:

[[email protected] ~]# lsmod | grep -e ip_vs -e nf_conntrack_ipv4
nf_conntrack_ipv4      16384  2 
nf_defrag_ipv4         16384  1 nf_conntrack_ipv4
ip_vs_sh               16384  0 
ip_vs_wrr              16384  0 
ip_vs_rr               16384  0 
ip_vs                 151552  6 ip_vs_rr,ip_vs_sh,ip_vs_wrr
nf_conntrack          135168  8 xt_conntrack,nf_nat_masquerade_ipv4,nf_conntrack_ipv4,nf_nat,ipt_MASQUERADE,nf_nat_ipv4,nf_conntrack_netlink,ip_vs
libcrc32c              16384  4 nf_conntrack,nf_nat,xfs,ip_vs

接下来还需要确保各个节点上已经安装了ipset软件包yum install ipset。 为了便于查看ipvs的代理规则,最好安装一下管理工具ipvsadm yum install ipvsadm。

如果以上前提条件如果不满足,则即使kube-proxy的配置开启了ipvs模式,也会退回到iptables模式。

9.安装docker

------详细教程请查看:

docker安装完成后,配置为阿里云的源

yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

10.配置kubernetes的yum源

[[email protected] ~]# cat /etc/yum.repos.d/kubernetes.repo 
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg

11.iptable设置

[[email protected] sysctl.d]# cat /etc/sysctl.d/k8s.conf 
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
net.ipv4.ip_nonlocal_bind = 1

12.kubeadm、kubectl、kubelet安装

yum install -y kubelet-1.13.1 kubeadm-1.13.1 kubectl-1.13.1
systemctl enable kubelet.service

# 配置kubelet使用国内阿里pause镜像,官方的镜像被墙,kubelet启动不了

[[email protected] kubernetes]# cat /etc/sysconfig/kubelet
KUBELET_EXTRA_ARGS="--pod-infra-container-image=registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1"

 

版权声明:本文为博主原创文章,转载请注明出处!

相关标签: kubernetes