momo's Blog.

Kubernetes 1.17.4 二进制安装

字数统计: 614阅读时长: 3 min
2020/03/20 Share

1、前言

2、环境准备

IP Hostname System OS Application Docker
192.168.1.20 k001 Centos 7.6 etcd1,k8s master 2
192.168.1.23 k002 Centos 7.6 etcd2,k8s master 2
192.168.1.27 k003 Centos 7.6 etcd3,k8s master 2
192.168.1.28 k004 Centos 7.6 k8s node1 2
  • 关闭内核安全机制以及防火墙
    1
    systemctl disable firewalld && systemctl stop firewalld && sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config

所有机器

  • 启用IPVS相关内核module

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    > /etc/modules-load.d/ipvs.conf
    module=(
    ip_vs
    ip_vs_rr
    ip_vs_wrr
    ip_vs_sh
    nf_conntrack
    br_netfilter
    )
    for kernel_module in ${module[@]};do
    /sbin/modinfo -F filename $kernel_module |& grep -qv ERROR && echo $kernel_module >> /etc/modules-load.d/ipvs.conf
    done

    systemctl enable --now systemd-modules-load.service
  • 内核参数配置

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    cat <<EOF > /etc/sysctl.d/k8s.conf
    # https://github.com/moby/moby/issues/31208
    # ipvsadm -l --timout
    # 修复ipvs模式下长连接timeout问题 小于900即可
    net.ipv4.tcp_keepalive_time = 600
    net.ipv4.tcp_keepalive_intvl = 30
    net.ipv4.tcp_keepalive_probes = 10
    net.ipv6.conf.all.disable_ipv6 = 1
    net.ipv6.conf.default.disable_ipv6 = 1
    net.ipv6.conf.lo.disable_ipv6 = 1
    net.ipv4.neigh.default.gc_stale_time = 120
    net.ipv4.conf.all.rp_filter = 0
    net.ipv4.conf.default.rp_filter = 0
    net.ipv4.conf.default.arp_announce = 2
    net.ipv4.conf.lo.arp_announce = 2
    net.ipv4.conf.all.arp_announce = 2
    net.ipv4.ip_forward = 1
    net.ipv4.tcp_max_tw_buckets = 5000
    net.ipv4.tcp_syncookies = 1
    net.ipv4.tcp_max_syn_backlog = 1024
    net.ipv4.tcp_synack_retries = 2
    # 要求iptables不对bridge的数据进行处理
    net.bridge.bridge-nf-call-ip6tables = 1
    net.bridge.bridge-nf-call-iptables = 1
    net.bridge.bridge-nf-call-arptables = 1
    net.netfilter.nf_conntrack_max = 2310720
    fs.inotify.max_user_watches=89100
    fs.may_detach_mounts = 1
    fs.file-max = 52706963
    fs.nr_open = 52706963
    vm.swappiness = 0
    vm.overcommit_memory=1
    vm.panic_on_oom=0
    EOF

    sysctl --system
  • 安装docker
    kubernetes支持的docker版本请查阅changelog
    搜索Update the latest validated version of Docker to
    目前1.17版本已经支持到docker版本为:19.03

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    yum install -y yum-utils device-mapper-persistent-data lvm2
    yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
    yum makecache fast

    # 安装指定版本的Docker-CE:
    # Step 1: 查找Docker-CE的版本:
    # yum list docker-ce.x86_64 --showduplicates | sort -r
    yum -y install docker-ce-19.03.8-3.el7


    systemctl enable docker
    systemctl restart docker
    tee /etc/docker/daemon.json <<-'EOF'
    {
    "exec-opts": ["native.cgroupdriver=systemd"],
    "registry-mirrors": ["https://w8f5u59w.mirror.aliyuncs.com"],
    "storage-driver": "overlay2",
    "storage-opts": [
    "overlay2.override_kernel_check=true"
    ],
    "log-driver": "json-file",
    "log-opts": {
    "max-size": "100m",
    "max-file": "3"
    }
    }
    EOF
    clear
    systemctl restart docker
    docker version

3、 证书配置

3.1、 生成证书

  • k8s-ca-config.json 证书生成配置

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    {
    "signing": {
    "default": {
    "expiry": "87600h"
    },
    "profiles": {
    "kubernetes": {
    "usages": [
    "signing",
    "key encipherment",
    "server auth",
    "client auth"
    ],
    "expiry": "87600h"
    }
    }
    }
    }
  • k8s-root-ca-csr.json 集群CA根证书

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    {
    "CN": "kubernetes",
    "key": {
    "algo": "rsa",
    "size": 4096
    },
    "names": [
    {
    "C": "CN",
    "ST": "Shanghai",
    "L": "Shanghai",
    "O": "kubernetes",
    "OU": "System"
    }
    ],
    "ca": {
    "expiry": "87600h"
    }
    }
  • kube-apiserver-csr.json apiserver TLS 认证端口需要的证书

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    {
    "CN": "kubernetes",
    "hosts": [
    "127.0.0.1",
    "10.254.0.1",
    "localhost",
    "*.master.kubernetes.node",
    "kubernetes",
    "kubernetes.default",
    "kubernetes.default.svc",
    "kubernetes.default.svc.cluster",
    "kubernetes.default.svc.cluster.local"
    ],
    "key": {
    "algo": "rsa",
    "size": 2048
    },
    "names": [
    {
    "C": "CN",
    "ST": "BeiJing",
    "L": "BeiJing",
    "O": "kubernetes",
    "OU": "System"
    }
    ]
    }
CATALOG
  1. 1. 1、前言
  2. 2. 2、环境准备
  3. 3. 3、 证书配置
    1. 3.1. 3.1、 生成证书