Kubernetes 之 二进制安装(一)搭建环境说明与前期准备
更新:HHH   时间:2023-1-7


环境说明

系统:

Centos 7.5

集群:

master1         192.168.214.88

master2         192.168.214.89

master3         192.168.214.90

etcd1             192.168.214.200

etcd2             192.168.214.201

etcd3             192.168.214.202

node1            192.168.214.203

node2            192.168.214.204

node3            192.168.214.205

各节点组件

Master:二进制安装kube-apiserver,kube-scheduler,kube-config-manager(master上的三个重要组件)、kubectl(命令行工具)

说明:kube-scheduler、kube-controller-manager 和 kube-apiserver 三者的功能紧密相关; 同时只能有一个 kube-scheduler、kube-controller-manager 进程处于工作状态,如果运行多个,则需要通过选举产生一个 leader

Etcd:源码二进制安装,选举leader

Node:安装flannel,kubelet,kube-proxy,docker-ce

haproxy:配置tcp代理haroxy组件

软件版本信息

kubernetes:1.12.2

etcd:3.2.22

docker-ce:18.06

flannel:0.9.1

haproxy:1.5.18

准备工作

所有节点关闭防火墙

systemctl stop firewalld && systemctl disable firewalld

所有节点关闭selinux

sed -i "s/SELINUX=.*/SELINUX=disabled/g" /etc/selinux/config && setenforce 0

配置yum源,方便kubernetes组件安装

yum install -y epel-release
vim /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg  http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg

host定向,打通集群主机名通信

vim /etc/hosts
master1         192.168.214.88        master1
master2         192.168.214.89        master2
etcd1             192.168.214.200      etcd1
etcd2             192.168.214.201      etcd2
etcd3             192.168.214.202      etcd3
node1            192.168.214.203      node1
node2            192.168.214.204      node2

master1生成秘钥,设置免密登录集群其他节点

ssh-keygen   
ssh-copy-id   -i  /root/.ssh/id_rsa.pub  master2
ssh-copy-id   -i  /root/.ssh/id_rsa.pub  master3
ssh-copy-id   -i  /root/.ssh/id_rsa.pub  etcd1
ssh-copy-id   -i  /root/.ssh/id_rsa.pub  etcd2
ssh-copy-id   -i  /root/.ssh/id_rsa.pub  etcd3
ssh-copy-id   -i  /root/.ssh/id_rsa.pub  node1
ssh-copy-id   -i  /root/.ssh/id_rsa.pub  node2
ssh-copy-id   -i  /root/.ssh/id_rsa.pub  node3
ssh-copy-id    -i /root/.ssh/id_rsa.pub  mastercluster

配置ntpdate时间服务器

yum install  ntpdate  -y
systemctl enable ntpdate.service
systemctl start  ntpdate.service
临时同步:ntpdate   time7.aliyun.com
设置任务计划crontab -e:
*/30 * * * * /usr/sbin/ntpdate time7.aliyun.com >/dev/null 2>&1

关闭swap,否则会导致kubelet启动失败

## 临时关闭:swapoff -a
## 永久关闭:sed -i 's/.*swap.*/#&/' /etc/fstab


返回云计算教程...