Centos7.6使用kubeadm快速部署kubernetes集群
为什么要使用kubeadm来部署kubernetes?因为kubeadm是kubernetes原生的部署工具,简单快捷方便,便于新手快速搭建学习,通过kubeadm配合kubernetes相关组件的docker镜像部署出来的集群环境和二进制文件搭建起来的集群环境基本上没什么区别。但是需要注意这种方式不建议用于生产环境!主要用于研究学习kubernetes! 关于kubeadm: Easily bootstrap a secure Kubernetes cluster
1.1.服务器规划
主机名 | 内网ip地址 | 角色 | 系统版本 |
---|---|---|---|
kubernetes01 | 10.5.0.206 | Master | CentOS Linux release 7.6.1810 (Core) |
kubernetes02 | 10.5.0.207 | Worker | CentOS Linux release 7.6.1810 (Core) |
kubernetes03 | 10.5.0.208 | Worker | CentOS Linux release 7.6.1810 (Core) |
kubernetes04 | 10.5.0.209 | Worker | CentOS Linux release 7.6.1810 (Core) |
kubernetes05 | 10.5.0.210 | Worker | CentOS Linux release 7.6.1810 (Core) |
kubernetes06 | 10.5.0.213 | Worker | CentOS Linux release 7.6.1810 (Core) |
kubernetes07 | 10.5.0.214 | Worker | CentOS Linux release 7.6.1810 (Core) |
kubernetes08 | 10.5.0.218 | Worker | CentOS Linux release 7.6.1810 (Core) |
kubernetes09 | 10.5.0.219 | Worker | CentOS Linux release 7.6.1810 (Core) |
1.2.Master节点
Master 节点主要包含了三个Kubernetes项目中最最最重要的组件:apiserver,scheduler,controller-manager!
apiserver:提供了管理集群的API接口
scheduler:负责分配调度Pod到集群内的node节点
controller-manager:由一系列的控制器组成,通过apiserver监控整个集群的状态
1.2.1.确认系统版本,修改主机名
1.查看系统版本
[root@iZ2ze7ftggknd1fplnxygqZ ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
2.修改主机名
hostnamectl set-hostname kubernetes01
3.别忘了修改/etc/hosts文件
[root@kubernetes01 ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
# kubernetes-cluster
10.5.0.206 kubernetes01
...
1.2.2.关闭防火墙
systemctl stop firewalld && systemctl disable firewalld
1.2.3.检查selinux是否关闭
[root@kubernetes01 ~]# setenforce 0
setenforce: SELinux is disabled
1.2.4.提前处理路由问题
cat > /etc/sysctl.d/k8s.conf << EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
vm.swappiness=0
EOF
之后
sysctl --system
1.2.5.安装docker-ce, 注意docker-ce的版本和kubernetes版本的兼容性!
使用yum安装docekr-ce,版本v18.06.1
[root@kubernetes01 ~]# yum -y install yum-utils device-mapper-persistent-data lvm2
[root@kubernetes01 ~]# yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
[root@kubernetes01 ~]# yum -y install docker-ce-18.06.1.ce
[root@kubernetes01 ~]# /bin/systemctl start docker.service
[root@kubernetes01 ~]# docker --version
Docker version 18.06.1-ce, build e68fc7a
1.2.6.安装kubelet kubeadm kubectl
1.配置某云的yum源
cat > /etc/yum.repos.d/kubernetes.repo << EOF
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
EOF
2.安装key文件
wget https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
rpm -import rpm-package-key.gpg
3.yum安装
yum install -y kubelet-1.12.1
yum install -y kubectl-1.12.1
yum install -y kubeadm-1.12.1
1.2.7.版本检查
[root@kubernetes01 ~]# kubelet --version
Kubernetes v1.12.1
[root@kubernetes01 ~]# kubectl version
Client Version: version.Info{Major:"1", Minor:"12", GitVersion:"v1.12.1", GitCommit:"4ed3216f3ec431b140b1d899130a69fc671678f4", GitTreeState:"clean", BuildDate:"2018-10-05T16:46:06Z", GoVersion:"go1.10.4", Compiler:"gc", Platform:"linux/amd64"}
The connection to the server localhost:8080 was refused - did you specify the right host or port?
[root@kubernetes01 ~]# kubeadm version
kubeadm version: &version.Info{Major:"1", Minor:"12", GitVersion:"v1.12.1", GitCommit:"4ed3216f3ec431b140b1d899130a69fc671678f4", GitTreeState:"clean", BuildDate:"2018-10-05T16:43:08Z", GoVersion:"go1.10.4", Compiler:"gc", Platform:"linux/amd64"}
v1.12.1kubeadm需要的kubernetes组件docker镜像版本:
k8s.gcr.io/kube-apiserver:v1.12.1
k8s.gcr.io/kube-controller-manager:v1.12.1
k8s.gcr.io/kube-scheduler:v1.12.1
k8s.gcr.io/kube-proxy:v1.12.1
k8s.gcr.io/pause:3.1
k8s.gcr.io/etcd:3.2.24
k8s.gcr.io/coredns:1.2.2
1.2.8.下载kubernetes相关组件的docker镜像
由于国内网络环境的“特殊性”,这里另辟蹊径。
[root@kubernetes01 ~]# cat pull_k8s_images.sh
#!/bin/bash
images=(kube-proxy:v1.12.1 kube-scheduler:v1.12.1 kube-controller-manager:v1.12.1
kube-apiserver:v1.12.1
etcd:3.2.24 coredns:1.2.2 pause:3.1 )
for imageName in ${images[@]} ; do
docker pull anjia0532/google-containers.${imageName}
docker tag anjia0532/google-containers.$imageName k8s.gcr.io/$imageName
docker rmi anjia0532/google-containers.$imageName
done
1.2.9.查看镜像信息
各位还记得开头提起过的scheduler,controller-manager,apiserver这三个基本组件的作用吗?