部署前的准备 主机名称解析
分布式系统环境中的多主机通信通常基于主机名称进行,这在IP地址存在变化的可能性时为主机提供了固定的访问入口,因此一般需要有专用的DNS服务负责解决各节点主机名。不过,考虑到此处部署的是测试集群,因此为了降低系统的复杂度,这里将采用基于hosts的文件进行主机名称解析
master节点和nodes都需要修改hosts文件
192.168.18.64 master 192.168.18.65 node1 192.168.18.66 node2 192.168.18.67 node3 主机时间同步如果使用的是云服务器,一般云厂商都已经设置好了
关闭防火墙各Node运行的kube-proxy组件均要借助iptables或ipvs构建Service资源对象,该资源对象是Kubernetes的核心资源之一。出于简化问题复杂度之需,这里需要事先关闭所有主机之上的iptables或firewalld服务
# systemctl stop iptables.service # systemctl disable iptables.service 关闭并仅用SELinux 禁用swap设备 (可选)kubeadm默认会预先检查当前主机是否禁用了Swap设备,并在未禁用时强制终止部署过程。因此,在主机内存资源充裕的条件下,需要禁用所有的Swap设备。
# 关闭swap设备 swapoff -a然后编辑/etc/fstab配置文件,另外部署时也可以不禁用swap设备,可在使用kubeadm命令时额外使用相关命令忽略检查错误
启用ipvs内核模块 (可选)Kubernetes1.11之后的版本默认支持使用ipvs代理模式的Service资源,但它依赖于ipvs相关的内核模块,而这些模块默认不会自动载入。因此,这里选择创建载入内核模块相关的脚本文件/etc/sysconfig/modules/ipvs.modules,设定于系统引导时自动载入的ipvs相关的内核模块,以支持使用ipvs代理模式的Service资源。文件内容如下:
#!/bin/bash ipvs_mods_dir="/usr/lib/modules/$(uname -r)/kernel/net/netfilter/ipvs" for i in $(ls $ipvs_mods_dir | grep -o "^[^.] *"); do /sbin/modinfo -F filename $i &> /dev/null if [ $ -eq 0 ]; then /sbin/ modprobe $i fi done然后修改文件权限,并手动为当前系统环境加载内核
chmod +x /etc/sysconfig/modules/ipvs.modules /etc/sysconfig/modules/ipvs.modules 镜像下载为啥要将镜像单独准备,因为这个门槛越不过去,你会遇到很多莫名其妙的问题(对于新手来讲)
以下是必须的镜像和正在运行的docker容器
[root@master ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE k8s.gcr.io/kube-proxy v1.13.1 fdb321fd30a0 4 weeks ago 80.2MB registry.cn-hangzhou.aliyuncs.com/mmyk8s/kube-proxy-amd64 v1.13.1 fdb321fd30a0 4 weeks ago 80.2MB k8s.gcr.io/kube-apiserver v1.13.1 40a63db91ef8 4 weeks ago 181MB registry.cn-hangzhou.aliyuncs.com/mmyk8s/kube-apiserver-amd64 v1.13.1 40a63db91ef8 4 weeks ago 181MB k8s.gcr.io/kube-scheduler v1.13.1 ab81d7360408 4 weeks ago 79.6MB registry.cn-hangzhou.aliyuncs.com/mmyk8s/kube-scheduler-amd64 v1.13.1 ab81d7360408 4 weeks ago 79.6MB k8s.gcr.io/kube-controller-manager v1.13.1 26e6f1db2a52 4 weeks ago 146MB registry.cn-hangzhou.aliyuncs.com/mmyk8s/kube-controller-manager-amd64 v1.13.1 26e6f1db2a52 4 weeks ago 146MB k8s.gcr.io/coredns 1.2.6 f59dcacceff4 2 months ago 40MB registry.cn-hangzhou.aliyuncs.com/mmyk8s/coredns 1.2.6 f59dcacceff4 2 months ago 40MB registry.cn-hangzhou.aliyuncs.com/mmyk8s/etcd-amd64 3.2.24 3cab8e1b9802 3 months ago 220MB k8s.gcr.io/etcd 3.2.24 3cab8e1b9802 3 months ago 220MB quay.io/coreos/flannel v0.10.0-amd64 f0fad859c909 11 months ago 44.6MB registry.cn-hangzhou.aliyuncs.com/mmyk8s/flannel v0.10.0-amd64 f0fad859c909 11 months ago 44.6MB k8s.gcr.io/pause 3.1 da86e6ba6ca1 12 months ago 742kB registry.cn-hangzhou.aliyuncs.com/mmyk8s/pause 3.1 da86e6ba6ca1 12 months ago 742kB [root@master ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 36d09d27fd26 f59dcacceff4 "/coredns -conf /etc…" 8 hours ago Up 8 hours k8s_coredns_coredns-86c58d9df4-cm4pm_kube-system_6e51adc0-14c0-11e9-ac10-000c29bed493_0 05bb6e3b85e9 f59dcacceff4 "/coredns -conf /etc…" 8 hours ago Up 8 hours k8s_coredns_coredns-86c58d9df4-g2mf4_kube-system_6e50f388-14c0-11e9-ac10-000c29bed493_0 51b284840974 k8s.gcr.io/pause:3.1 "/pause" 8 hours ago Up 8 hours k8s_POD_coredns-86c58d9df4-cm4pm_kube-system_6e51adc0-14c0-11e9-ac10-000c29bed493_0 b3e5b80bb640 k8s.gcr.io/pause:3.1 "/pause" 8 hours ago Up 8 hours k8s_POD_coredns-86c58d9df4-g2mf4_kube-system_6e50f388-14c0-11e9-ac10-000c29bed493_0 5f50cad2717e f0fad859c909 "/opt/bin/flanneld -…" 8 hours ago Up 8 hours k8s_kube-flannel_kube-flannel-ds-amd64-7xh79_kube-system_ad897b0d-14c0-11e9-ac10-000c29bed493_0 73bb596c654e 3cab8e1b9802 "etcd --advertise-cl…" 23 hours ago Up 23 hours k8s_etcd_etcd-master_kube-system_54caa73c3a366810eb1982ce52213834_1 d5d71dfc331c ab81d7360408 "kube-scheduler --ad…" 23 hours ago Up 23 hours k8s_kube-scheduler_kube-scheduler-master_kube-system_44b569a35761491825f4e7253fbf0543_1 7ff702474352 40a63db91ef8 "kube-apiserver --au…" 23 hours ago Up 23 hours k8s_kube-apiserver_kube-apiserver-master_kube-system_4e3289b38af39fb55c00956ffb875c26_1 590cb4078099 26e6f1db2a52 "kube-controller-man…" 23 hours ago Up 23 hours k8s_kube-controller-manager_kube-controller-manager-master_kube-system_7d0a1ff3545bbc890a67b0d02dc0f191_1 c22bcc9f6903 fdb321fd30a0 "/usr/local/bin/kube…" 23 hours ago Up 23 hours k8s_kube-proxy_kube-proxy-m8wsf_kube-system_b8572ad6-14bf-11e9-ac10-000c29bed493_1 8d63b75de565 k8s.gcr.io/pause:3.1 "/pause" 23 hours ago Up 23 hours k8s_POD_kube-flannel-ds-amd64-7xh79_kube-system_ad897b0d-14c0-11e9-ac10-000c29bed493_1 fe0b44fe8c09 k8s.gcr.io/pause:3.1 "/pause" 23 hours ago Up 23 hours k8s_POD_kube-proxy-m8wsf_kube-system_b8572ad6-14bf-11e9-ac10-000c29bed493_1 729321ce5699 k8s.gcr.io/pause:3.1 "/pause" 23 hours ago Up 23 hours k8s_POD_kube-scheduler-master_kube-system_44b569a35761491825f4e7253fbf0543_1 b635e5dd38d0 k8s.gcr.io/pause:3.1 "/pause" 23 hours ago Up 23 hours k8s_POD_etcd-master_kube-system_54caa73c3a366810eb1982ce52213834_1 85502af97ba9 k8s.gcr.io/pause:3.1 "/pause" 23 hours ago Up 23 hours k8s_POD_kube-apiserver-master_kube-system_4e3289b38af39fb55c00956ffb875c26_2 240c427dc4dc k8s.gcr.io/pause:3.1 "/pause" 23 hours ago Up 23 hours k8s_POD_kube-controller-manager-master_kube-system_7d0a1ff3545bbc890a67b0d02dc0f191_1在后面初始化kuberneters集群的时候,依赖的这些镜像默认是从k8s.gcr.io去pull镜像,但是在国内是无法访问的
我们可以通过阿里云或者腾讯云先将镜像构建在阿里的镜像仓库中,然后再tag为需要的镜像标签
阿里云上自定义镜像仓库
仓库中自定义的构建信息,这里指定了dockerfile文件的地址在github上
这里为github上dockerfile的内容,以官方镜像为基础镜像构建后存在阿里的镜像仓库中
所有镜像构建完成后,通过命令pull到本地,打tag即可使用