码迷,mamicode.com
首页 > 其他好文 > 详细

安装k8s集群

时间:2020-04-01 19:26:43      阅读:71      评论:0      收藏:0      [点我收藏+]

标签:centos   导致   address   reg   abc   forward   ystemd   sock   repos   

一、 环境说明

技术图片

二、 初始化系统(master、node1、node2)

  1. cat /etc/hosts

    192.168.1.136 k8s-master01
    192.168.1.134 k8s-node1
    192.168.1.137 k8s-node2
    192.168.1.25 hub.testwang.com

 

  2. 安装基础依赖包

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

  3. 设置防火墙为 Iptables 并设置空规则

    systemctl stop firewalld && systemctl disable firewalld

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

  4. 关闭selinux

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

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

 

   5.  优化内核参数

     modprobe br_netfilter 

    

    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

  6. 调整系统时区

    

  # 设置系统时区为 中国/上海
  timedatectl set-timezone Asia/Shanghai
  # 将当前的 UTC 时间写入硬件时钟
  timedatectl set-local-rtc 0
  # 重启依赖于系统时间的服务
  systemctl restart rsyslog
  systemctl restart crond

  关闭不需要的服务
    systemctl stop postfix.service && systemctl disable postfix.service

  7. 设置 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

  8. 升级系统内核为 4.44

  CentOS 7.x 系统自带的 3.10.x 内核存在一些 Bugs,导致运行的 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

三、 安装docker 和 k8s

  1. 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 
  2. 安装 docker 

    

  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 update -y && yum install -y docker-ce
  ## 创建 /etc/docker 目录
  mkdir /etc/docker
  # 配置 daemon.
  cat > /etc/docker/daemon.json <<EOF
  {
  "exec-opts": ["native.cgroupdriver=systemd"],
  "log-driver": "json-file",
  "log-opts": {
  "max-size": "100m"
  }
  }
  EOF
  mkdir -p /etc/systemd/system/docker.service.d
  # 重启docker服务
  systemctl daemon-reload && systemctl restart docker && systemctl enable docker

  3.  安装 Kubeadm (主从配置) 

  cat <<EOF > /etc/yum.repos.d/kubernetes.repo
    [kubernetes]
    name=Kubernetes
    baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
    enabled=1
    gpgcheck=0
    repo_gpgcheck=0
    gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
    http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
    EOF
  yum -y install kubeadm-1.15.1 kubectl-1.15.1 kubelet-1.15.1
  systemctl enable kubelet.service

  4 配置初始化配置文件

  cat kubeadm-config.yaml  

apiVersion: kubeadm.k8s.io/v1beta2
bootstrapTokens:
- groups:
  - system:bootstrappers:kubeadm:default-node-token
  token: abcdef.0123456789abcdef
  ttl: 24h0m0s
  usages:
  - signing
  - authentication
kind: InitConfiguration
localAPIEndpoint:
  advertiseAddress: 192.168.1.136
  bindPort: 6443
nodeRegistration:
  criSocket: /var/run/dockershim.sock
  name: k8s-master01
  taints:
  - effect: NoSchedule
    key: node-role.kubernetes.io/master
---
apiServer:
  timeoutForControlPlane: 4m0s
apiVersion: kubeadm.k8s.io/v1beta2
certificatesDir: /etc/kubernetes/pki
clusterName: kubernetes
controllerManager: {}
dns:
  type: CoreDNS
etcd:
  local:
    dataDir: /var/lib/etcd
imageRepository: k8s.gcr.io
kind: ClusterConfiguration
kubernetesVersion: v1.15.3
networking:
  dnsDomain: cluster.local
  podSubnet: "10.244.0.0/16"
  serviceSubnet: 10.96.0.0/12
scheduler: {}
---
apiVersion: kubeproxy.config.k8s.io/v1alpha1
kind: KubeProxyConfiguration
featureGates:
  SupportIPVSProxyMode: true
mode: ipvs

安装k8s集群

标签:centos   导致   address   reg   abc   forward   ystemd   sock   repos   

原文地址:https://www.cnblogs.com/Robi-9662/p/12614566.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!