k8s--基础--05--环境搭建--准备工作

k8s–基础–05–环境搭建–准备工作


前提

使用root用户

1、修改yum源

1.1、备份原来的yum源

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

1.2、下载阿里的yum源

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

1.3、生成新的yum缓存

yum makecache fast

1.4、配置安装k8s需要的yum源

vim /etc/yum.repos.d/kubernetes.repo

内容

[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0

1.5、清理yum缓存

yum clean all

1.6、生成新的yum缓存

yum makecache fast

1.7、更新yum源

yum -y update

1.8、安装软件包

yum -y install yum-utils device-mapper-persistent-data  lvm2

1.9、添加docker软件源

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

1.10、清理yum缓存

yum clean all

1.11、生成新的yum缓存

yum makecache fast

2、安装基础软件包

yum -y install wget net-tools nfs-utils lrzsz gcc gcc-c++ make cmake libxml2-devel openssl-devel curl curl-devel unzip sudo ntp libaio-devel wget vim ncurses-devel autoconf automake zlib-devel  python-devel epel-release openssh-server socat  ipvsadm conntrack ntpdate

3、关闭firewalld防火墙

centos7系统默认使用的是firewalld防火墙,停止firewalld防火墙,并禁用这个服务.

# 停止防火墙
systemctl stop firewalld  
# 禁用防火墙
systemctl  disable  firewalld

4、安装iptables(可以不安装)

如果你用firewalld不是很习惯,可以安装iptables

4.1、安装iptables

yum install iptables-services -y

4.2、禁用iptables

# 停止
service iptables stop  
# 禁用
systemctl disable iptables

5、时间同步

5.1、时间同步

ntpdate cn.pool.ntp.org

5.2、编辑计划任务,每小时做一次同步(可以不用做)

[root@zhoufei ~]# crontab -e

内容

* */1 * * * /usr/sbin/ntpdate   cn.pool.ntp.org

5.3、重启crond服务

service crond restart

6、关闭selinux

关闭selinux,设置永久关闭,这样重启机器selinux也处于关闭状态

6.1、修改配置文件

# 将 selinux 文件中的 SELINUX=enforcing 替换为 SELINUX=disabled
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/sysconfig/selinux

# 将 config 文件中的 SELINUX=enforcing 替换为 SELINUX=disabled
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
 

6.2、 强制重启

reboot -f

7、关闭交换分区

# 临时禁用
swapoff  -a


# 永久禁用,/etc/fstab中注释掉swap那一行。 
sed -i 's/.*swap.*/#&/' /etc/fstab

在这里插入图片描述

8、修改内核参数

打开文件

vim /etc/sysctl.d/k8s.conf

内容

# 开启 iptables 对bridge的数据进行处理 
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1

让配置文件生效

sysctl --system

9、修改主机名

hostnamectl set-hostname k8s01

10、配置hosts文件

vim  /etc/hosts 

新增

# 本机IP
192.168.187.154   k8s01

11、安装docker

11.1、查看支持的docker版本

sudo yum list docker-ce --showduplicates |sort -r

在这里插入图片描述

11.2、安装

# 安装
yum -y install docker-ce-19.03.7-3.el7
# 开启docker服务
systemctl enable docker  
systemctl start docker

11.3、查看docker状态

如果状态是active(running),说明docker是正常运行状态

systemctl status docker

在这里插入图片描述

11.4、修改docker配置文件

cat > /etc/docker/daemon.json <<EOF
{
 "exec-opts": ["native.cgroupdriver=systemd"],
 "log-driver": "json-file",
 "log-opts": {
   "max-size": "100m"
  },
 "storage-driver": "overlay2",
  "registry-mirrors": [
    "http://hub-mirror.c.163.com",
    "https://fsqbo5wy.mirror.aliyuncs.com",
    "https://registry.docker-cn.com"
  ],
 "storage-opts": [
   "overlay2.override_kernel_check=true"
  ]
}
EOF

在这里插入图片描述

配置说明
# 镜像仓库
registry-mirrors:

#存储方式
storage-driver": "overlay2"

11.5、重启docker使配置生效

systemctl daemon-reload 
systemctl restart docker

12、设置网桥包经IPTables,core文件生成路径,配置永久生效

echo 1 > /proc/sys/net/bridge/bridge-nf-call-iptables
echo 1 >/proc/sys/net/bridge/bridge-nf-call-ip6tables

echo """
vm.swappiness = 0
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-ip6tables = 1
""" > /etc/sysctl.conf

# 让配置文件失效
sysctl -p

在这里插入图片描述

13、开启ipvs

不开启ipvs将会使用iptables,但是效率低,所以官网推荐需要开通ipvs内核

13.1、设置脚本

cat > /etc/sysconfig/modules/ipvs.modules <<EOF
#!/bin/bash
ipvs_modules="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 nf_conntrack"
for kernel_module in \${ipvs_modules}; do
 /sbin/modinfo -F filename \${kernel_module} > /dev/null 2>&1
 if [ $? -eq 0 ]; then
 /sbin/modprobe \${kernel_module}
 fi
done
EOF

13.2、设置权限

chmod 755 /etc/sysconfig/modules/ipvs.modules 

13.3、执行脚本并查看

bash /etc/sysconfig/modules/ipvs.modules && lsmod | grep ip_vs

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值