k8s学习

时间:2019-11-25 16:39:45   收藏:0   阅读:81

一、介绍

  A、特点:

    1. 轻量级

    2. 开源

    3. 弹性伸缩

    4. 负载均衡

二、组件说明

  A、master

    1、Apiserver:所有服务访问统一入口

    2、ControllerManager:维持副本期望数目

    3、Scheduler:负责介绍任务,选择合适的节点进行分配任务。

    4、Etcd:键值对数据库,存储k8s集群所有重要信息(持久化)

  B、node

    1. Kubelet:直接跟容器引擎交互实现容器的生命周期管理

    2. Kube-proxy:负责写入规则至iptables、ipvs实现服务映射访问的

    3. CoreDNS:可以为集群中的SVC创建一个域名ip的对应关系解析

    4. Dashboard:给k8s

三、集群安装

  A、安装k8s-master01、k8s-node01、k8s-node02节点,安装centos7系统

    1.设置系统主机名以及hosts文件的相互解析

      a. hostnamectl set-hostname k8s-master01

      b. 192.168.66.10 k8s-master01

        192.168.66.20 k8s-node01

        192.168.66.30 k8s-node02

  B、安装依赖包

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

  C、 设置防火墙为iptables并设置空规则

    systemctl stop firewalld && systemctl disable firewalld

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

  D、关闭selinux

    1. 关闭交换分区,关闭虚拟内存(k8s启动时会检测是否关闭了虚拟内存,为防止容器运行在虚拟内存,强制关闭)

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

    2. 关闭SELINUX

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

  E、调整内核参数,对于k8s

    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空间,只有当系统00M时才使用它

    vm.overcommit_memory=1 #不检查物理内存是否够用

    vm.panic_on_oom=0 #开启oom

    fs.inotify.max_user_instance=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

  F、调整系统时区

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

      timedatectl set-timezone Asia/Shanghai

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

      timedatectl set-local-rtc 0

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

      systemctl restart rsyslog

      systemctl restart crond

  G、关闭系统不需要服务

    1. systemctl stop postfix && systemctl disable postfix

  H、设置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

 

    # 压缩历史日志

    Conpress=yes

    

    SyncIntervalSec=5m

    RateLimitInterval=30s

    RateLimitBurst=1000

    

    # 最大占用空间 10G

    SystemMaxUse=10G

 

    # 单日志文件最大 200M

    SystemMaxFileSize=200M

 

    # 日志保存时间2周

    MaxRetentionSec=2week

 

    # 不将日志转发到syslog

    ForwardToSyslog=no

    EOF

    systemctl restart system-journald

  I、升级内核为4.44版本

    1. Centos 7.x系统自带的3.10.x内核存在一些bug,导致运行的Docker、Kubernetes不稳定,例如rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm

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

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

      yum --enablerepo=elrepo-kernel install -y kernel-lt

      # 设置开机从新内核启动

      grub2-set-default "CentOS Linux (4.4.182-1.el7.elrepo.x86_64) 7 (Core)" 

  J、kube-proxy开启ipvs的前置条件

    modprobe br_netfilter

    cat > /etc/sysconfig/modules/ipvs.modules <<EOF

    #!/bin/bash

    modprobe -- ip_vs

    modprobe -- ip_vs_rr

    modprobe -- ip_vs_wrr

    modprobe -- ip_vs_sh

    modprobe -- nf_conntrack_ipv4

    EOF

    chmod 755 /etc/sysconfig/modules/ipvs.modules && bash /etc/sysconfig/modules/ipvs.modules && lsmod | grep -e ip_vs -e nf_conntrack_ipv4

原文:https://www.cnblogs.com/DjanFey/p/11928391.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!