CentOS7搭建kubernetes集群&配置&常见问题

在CentOS 7服务器上搭建Kubernetes

部署方式

  1. 各组件以守护进程(服务)方式运行
  2. 各组件以容器方式运行(使用kubeadm部署)√

节点服务分布

master nodes
kube-apiserver,kube-controller-manager,kube-scheduler , kube-proxy,etcd , pause,coredns scheduler分配

部署k8s集群

环境准备

  • 修改每个节点的静态IP、主机名、本地域名

    主节点1 hostnamectl set-hostname k8s-master01

    子节点1 hostnamectl set-hostname k8s-node01

    子节点2 hostnamectl set-hostname k8s-node02
    [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-67jHQIyj-1579223391948)(C:\Users\zz3\AppData\Roaming\Typora\typora-user-images\image-20200115170437579.png)]

  • 安装部分依赖包

    yum install -y conntrack ntpdate ntp ipvsadm ipset jq iptables curl sysstat libseccomp wget vim net-tools git

  • 关闭防火墙、swap、selinux

systemctl stop firewalld && systemctl disable firewalld


yum -y install iptables-services && systemctl start iptables && systemctl enable iptables&& iptables -F && service iptables save

swapoff -a && sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab

setenforce 0 && sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
  • 配置内核参数,将桥接的IPv4流量传递到iptables的链
cat > kubernetes.conf <<EOF
net.bridge.bridge-nf-call-iptables=1
net.bridge.bridge-nf-call-ip6tables=1
net.ipv4.ip_forward=1
net.ipv4.tcp_tw_recycle=0
vm.swappiness=0 # 禁止使用 swap 空间,只有当系统 OOM 时才允许使用它vm.overcommit_memory=1 # 不检查物理内存是否够用
vm.panic_on_oom=0 # 开启 OOM
fs.inotify.max_user_instances=8192
fs.inotify.max_user_watches=1048576
fs.file-max=52706963
fs.nr_open=52706963
net.ipv6.conf.all.disable_ipv6=1
net.netfilter.nf_conntrack_max=2310720
EOF

cp kubernetes.conf /etc/sysctl.d/kubernetes.conf

sysctl -p /etc/sysctl.d/kubernetes.conf
如果报错cannot stat ,执行modprobe br_netfilter然后再次上面的sysctl -p
  • 调整系统时区

    # 设置系统时区为中国/上海

    timedatectl set-timezone Asia/Shanghai

    # 将当前的 UTC 时间写入硬件时钟

    timedatectl set-local-rtc 0

    # 重启依赖于系统时间的服务

    systemctl restart rsyslog

    systemctl restart crond

    #关闭系统不需要的服务

    systemctl stop postfix && systemctl disable postfix

  • 设置rsyslogd和systemd journald

    mkdir /var/log/journal # 持久化保存日志的目录

    mkdir /etc/systemd/journald.conf.d

    cat > /etc/systemd/journald.conf.d/99-prophet.conf <<EOF

    [Journal]

    # 持久化保存到磁盘

    Storage=persistent

    # 压缩历史日志

    Compress=yes

    SyncIntervalSec=5m

    RateLimitInterval=30s

    RateLimitBurst=1000

    # 最大占用空间 10G

    SystemMaxUse=10G

    # 单日志文件最大 200M

    SystemMaxFileSize=200M

    # 日志保存时间 2 周

    MaxRetentionSec=2week

    # 不将日志转发到 syslog

    ForwardToSyslog=no

    EOF

    systemctl restart systemd-journald

  • 升级内核为4.44版本

    rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm

    # 安装完成后检查 /boot/grub2/grub.cfg 中对应内核 menuentry 中是否包含 initrd16 配置,如果没有,再安装一次!

    yum --enablerepo=el

  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值