mmdbcn 发表于 2018-9-15 11:49:56

centos7使用kubeadm安装kubernetes 1.11版本多主高可用

centos7使用kubeadm安装kubernetes 1.11版本多主高可用
  
  kubernetes介绍
  要学习一个新的东西,先了解它是什么,熟悉基本概念会有很大帮助。以下是我学习时看过的一篇核心概念介绍。
  http://dockone.io/article/932
  搭建Kubernetes集群环境有以下3种方式:
  minikube
  Minikube是一个工具,可以在本地快速运行一个单点的Kubernetes,尝试Kubernetes或日常开发的用户使用。不能用于生产环境。
  官方地址:https://kubernetes.io/docs/setup/minikube/

  以下是符合企业生产环境标准的Kubernetes集群环境方式:

  kubeadm
  Kubeadm也是一个工具,提供kubeadm init和kubeadm join,用于快速部署Kubernetes集群。
  官方地址:https://kubernetes.io/docs/reference/setup-tools/kubeadm/kubeadm/
  二进制包
  从官方下载发行版的二进制包,手动部署每个组件,组成Kubernetes集群。
  官方也提供了一个互动测试环境供大家玩耍:https://kubernetes.io/cn/docs/tutorials/kubernetes-basics/cluster-interactive/

1. 实验环境说明
  

lab1: etcd master haproxy keepalived 192.168.105.92  
lab2: etcd master haproxy keepalived 192.168.105.93
  
lab3: etcd master haproxy keepalived 192.168.105.94
  
lab4: node192.168.105.95
  
lab4: node192.168.105.96
  

  
vip(loadblancer ip): 192.168.105.99
  

  virtualbox实验使用的Vagrantfile:
  

# -*- mode: ruby -*-  
# vi: set ft=ruby :
  

  
ENV["LC_ALL"] = "en_US.UTF-8"
  

  
Vagrant.configure("2") do |config|
  (2..6).each do |i|
  config.vm.define "lab#{i}" do |node|
  node.vm.box = "centos-7.4-docker-17"
  node.ssh.insert_key = false
  node.vm.hostname = "lab#{i}"
  node.vm.network "private_network", ip: "192.168.105.9#{i}"
  node.vm.provision "shell",
  inline: "echo hello from node #{i}"
  node.vm.provider "virtualbox" do |v|
  v.cpus = 2
  v.customize ["modifyvm", :id, "--name", "lab#{i}", "--memory", "2048"]
  end
  end
  end
  
end
  

2. 准备yum源
  使用阿里yum源,并将默认yum源文件都移走。
  

cd /etc/yum.repos.d  
mkdir bak
  
mv *.repo bak/
  

  vim CentOS-Base.repo
  

# CentOS-Base.repo  
#
  
# The mirror system uses the connecting IP address of the client and the
  
# update status of each mirror to pick mirrors that are updated to and
  
# geographically close to the client.You should use this for CentOS updates
  
# unless you are manually picking other mirrors.
  
#
  
# If the mirrorlist= does not work for you, as a fall back you can try the
  
# remarked out baseurl= line instead.
  
#
  
#
  

  

  
name=CentOS-$releasever - Base - mirrors.aliyun.com
  
failovermethod=priority
  
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
  http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
  http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
  
gpgcheck=1
  
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
  

  
#released updates
  

  
name=CentOS-$releasever - Updates - mirrors.aliyun.com
  
failovermethod=priority
  
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
  http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/
  http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/
  
gpgcheck=1
  
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
  

  
#additional packages that may be useful
  

  
name=CentOS-$releasever - Extras - mirrors.aliyun.com
  
failovermethod=priority
  
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
  http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/
  http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/
  
gpgcheck=1
  
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
  

  
#additional packages that extend functionality of existing packages
  

  
name=CentOS-$releasever - Plus - mirrors.aliyun.com
  
failovermethod=priority
  
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
  http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/
  http://mirrors.cloud.aliyuncs.com/centos/$releasever/centosplus/$basearch/
  
gpgcheck=1
  
enabled=0
  
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
  

  
#contrib - packages by Centos Users
  

  
name=CentOS-$releasever - Contrib - mirrors.aliyun.com
  
failovermethod=priority
  
baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/
  http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/
  http://mirrors.cloud.aliyuncs.com/centos/$releasever/contrib/$basearch/
  
gpgcheck=1
  
enabled=0
  
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
  

  vim epel-7.repo
  

  
name=Extra Packages for Enterprise Linux 7 - $basearch
  
baseurl=http://mirrors.aliyun.com/epel/7/$basearch
  
failovermethod=priority
  
enabled=1
  
gpgcheck=0
  
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
  

  

  
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
  
baseurl=http://mirrors.aliyun.com/epel/7/$basearch/debug
  
failovermethod=priority
  
enabled=0
  
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
  
gpgcheck=0
  

  

  
name=Extra Packages for Enterprise Linux 7 - $basearch - Source
  
baseurl=http://mirrors.aliyun.com/epel/7/SRPMS
  
failovermethod=priority
  
enabled=0
  
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
  
gpgcheck=0
  

  vim docker-ce.repo
  

  
name=Docker CE Stable - $basearch
  
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/$basearch/stable
  
enabled=1
  
gpgcheck=1
  
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
  

  

  
name=Docker CE Stable - Debuginfo $basearch
  
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/debug-$basearch/stable
  
enabled=0
  
gpgcheck=1
  
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
  

  

  
name=Docker CE Stable - Sources
  
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/source/stable
  
enabled=0
  
gpgcheck=1
  
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
  

  

  
name=Docker CE Edge - $basearch
  
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/$basearch/edge
  
enabled=1
  
gpgcheck=1
  
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
  

  

  
name=Docker CE Edge - Debuginfo $basearch
  
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/debug-$basearch/edge
  
enabled=0
  
gpgcheck=1
  
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
  

  

  
name=Docker CE Edge - Sources
  
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/source/edge
  
enabled=0
  
gpgcheck=1
  
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
  

  

  
name=Docker CE Test - $basearch
  
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/$basearch/test
  
enabled=0
  
gpgcheck=1
  
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
  

  

  
name=Docker CE Test - Debuginfo $basearch
  
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/debug-$basearch/test
  
enabled=0
  
gpgcheck=1
  
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
  

  

  
name=Docker CE Test - Sources
  
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/source/test
  
enabled=0
  
gpgcheck=1
  
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
  

  

  
name=Docker CE Nightly - $basearch
  
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/$basearch/nightly
  
enabled=0
  
gpgcheck=1
  
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
  

  

  
name=Docker CE Nightly - Debuginfo $basearch
  
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/debug-$basearch/nightly
  
enabled=0
  
gpgcheck=1
  
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
  

  

  
name=Docker CE Nightly - Sources
  
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/7/source/nightly
  
enabled=0
  
gpgcheck=1
  
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
  

  vim kubernetes.repo
  

  
name=Kubernetes
  
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
  
enabled=1
  
gpgcheck=1
  
repo_gpgcheck=1
  
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
  

2. 安装配置docker
  v1.11.1版本推荐使用docker v17.03,v1.11,v1.12,v1.13, 也可以使用,再高版本的docker可能无法正常使用。
  这里安装v1.13版本。
  

yum -y install docker  
systemctl enable docker && systemctl restart docker
  

  docker启动错误解决:
  

Error starting daemon: SELinux is not supported with the overlay2 graph driver on this kernel. Either boot into a newer kernel or disable selinux in docke...-enabled=false)  

  修改/etc/sysconfig/docker中的--selinux-enabled=false

3. 安装 kubeadm, kubelet 和 kubectl

  如下操作在所有节点操作

  

yum install -y kubelet kubeadm kubectl ipvsadm  
systemctl enable kubelet && systemctl start kubelet
  

4. 配置系统相关参数

  如下操作在所有节点操作

  

# 设置时区  
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
  

  
# 临时禁用selinux
  
# 永久关闭 修改/etc/sysconfig/selinux文件设置
  
sed -i 's/SELINUX=.*/SELINUX=disabled/' /etc/sysconfig/selinux
  
setenforce 0# 需要重启生效
  

  
# 开启forward
  
# Docker从1.13版本开始调整了默认的防火墙规则
  
# 禁用了iptables filter表中FOWARD链
  
# 这样会引起Kubernetes集群中跨Node的Pod无法通信
  
iptables -P FORWARD ACCEPT
  

  
# 临时关闭swap
  
# 永久关闭 注释/etc/fstab文件里swap相关的行
  
swapoff -a
  

  
# 开启防火墙允许集群机器间通信(为了方便测试或者直接关闭防火墙)
  
firewall-cmd --add-rich-rule 'rule family=ipv4 source address=192.168.105.0/24 accept' # # 指定源IP(段),即时生效
  
firewall-cmd --add-rich-rule 'rule family=ipv4 source address=192.168.105.0/24 accept' --permanent # 指定源IP(段),永久生效
  

  
# 配置转发相关参数,否则可能会出错
  
cat >/etc/hosts
页: [1]
查看完整版本: centos7使用kubeadm安装kubernetes 1.11版本多主高可用