环境准备(所有节点都需要操作)
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-keygen -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 user@host '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了
>
[root@k8s01 ~]# free -m
. total used free shared buff/cache available
Mem: 29443 181 28985 8 276 28865
Swap: 0 0 0
8.配置 ipvs 支持
9.安装 docker
------详细教程请查看:
>
docker安装完成后,配置为阿里云的源
>
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
10.配置 kubernetes 的 yum 源
[root@k8s01 ~]# 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 设置
[root@k8s01 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启动不了
>
[root@k8s01 kubernetes]# cat /etc/sysconfig/kubelet
KUBELET_EXTRA_ARGS="--pod-infra-container-image=registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1"
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于