K8s安装以及开发环境(一:k8s安装)

  1. 环境准备

    主要是网络打通

    操作系统:centos7

    环境需要:docker

    配置:2核,2G,20G

    ip:

    k8s-master: 192.168.99.60

    k8s-node1: 192.168.99.61

    k8s-node2: 192.168.99.62

    1.2 安装ifconfig

    用于查看ip,可选

    yum -y install net-tools
    

    image.png

    1.2 修改ip

    vi /etc/sysconfig/network-scripts/ifcfg-ens33
    

    image.png

    BOOTPROTO = static

    IP修改为指定的ip

    # 重启网络服务
    systemctl restart network
    

    1.3 关闭防火墙

    systemctl stop firewalld && systemctl disable firewalld && iptables -F
    

    1.4 关闭selinux

    这个是用来加强安全性的一个组件,但非常容易出错且难以定位,一般上来装完系统就先给禁用了

    # 查看状态
    getenforce
  2. 永久关闭 sed -i s#SELINUX=enforcing#SELINUX=disabled# /etc/selinux/config

1.5 关闭swap分区

这个当内存不足时,linux会自动使用swap,将部分内存数据存放到磁盘中,这个这样会使性能下降,为了性能考虑推荐关掉。Prior to Kubernetes 1.22, nodes did not support the use of swap memory, and a kubelet would by default fail to start if swap was detected on a node. In 1.22 onwards, swap memory support can be enabled on a per-node basis.

  关闭swap分区
vi /etc/fstab

注释掉 /dev/****/swap 行

1. 检查  下面swap 显示都是0
free -h

1.6 修改host文件,

修改主机名

# master 
hostnamectl set-hostname k8s-master

1. node1
hostnamectl set-hostname k8s-node1

1. node2
hostnamectl set-hostname k8s-node2

修改本地host 文件,联通网络

vi /etc/hosts

192.168.99.60 k8s-master
192.168.99.61 k8s-node1
192.168.99.62 k8s-node2

1.7 修改内核参数

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
> EOF

1.8 加载ip_vs内核模块

如果kube-proxy 模式为ip_vs则必须加载,本文采用iptables

modprobe ip_vs
modprobe ip_vs_rr
modprobe ip_vs_wrr
modprobe ip_vs_sh
modprobe nf_conntrack_ipv4

设置下次开机自动加载

cat > /etc/modules-load.d/ip_vs.conf  /etc/yum.repos.d/kubernetes.repo