k8s安装
关闭防火墙:systemctlstopfirewalldsystemctldisablefirewalld
关闭selinux:(博客文档格式可能有问题,如果出问题,则尝试手敲该命令)sedis/enforcing/disabled//etc/selinux/configsetenforce0
关闭swap:(云主机貌似默认关了)swapoffa
设置主机名hostnamectlsethostnamemasterhostnamectlsethostnamek8snode1hostnamectlsethostnamek8snode2
设置host绑定关系(这里有个坑,公网IP貌似kubeadminit时会报错【需要开相关端口】,(内网IP则OK)公网:cat>>/etc/hosts<<EOF121.36.162.18k8smaster119.3.29.5k8snode1121.36.131.4k8snode2EOF内网:cat>>/etc/hosts<<EOF192.168.0.179k8smaster192.168.0.25k8snode1192.168.0.93k8snode2EOF
设置流量转发(官网建议):cat>/etc/sysctl.d/k8s.conf<<EOFnet.bridge.bridgenfcallip6tables=1net.bridge.bridgenfcalliptables=1EOF执行生效:sysctlsystem
(XSHELL工具发送输入到所有会话)
安装一些依赖:yuminstallyconntrackntpdatentpipvsadmipsetjqiptablescurlsysstatlibseccompwgetvimnettoolsgit
同步时间:ntpdatetime.windows.com
配置阿里云镜像加速器:sudomkdirp/etc/dockersudotee/etc/docker/daemon.json<<EOF{"registrymirrors":["https://vkayqpp3.mirror.aliyuncs.com"\]}EOFsudosystemctldaemonreloadsudosystemctlrestartdocker
添加阿里云yum源(注意:gpgkey有两个值)cat>/etc/yum.repos.d/kubernetes.repo<<EOF[kubernetes]name=Kubernetesbaseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetesel7x86\_64enabled=1gpgcheck=1repo\_gpgcheck=1gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yumkey.gpghttps://mirrors.aliyun.com/kubernetes/yum/doc/rpmpackagekey.gpgEOF更新缓存:yumcleanallyumymakecache
安装kubeadm,kubelet和kubectlyuminstallykubelet1.17.0kubeadm1.17.0kubectl1.17.0
设置开机启动:
systemctlenablekubelet
【公网】在master节点执行初始化(master地址:121.36.162.228):kubeadminit\apiserveradvertiseaddress=121.36.162.228\imagerepositoryregistry.aliyuncs.com/google_containers\kubernetesversionv1.17.0\servicecidr=10.1.0.0/16\podnetworkcidr=10.244.0.0/16
【内网】kubeadminit\apiserveradvertiseaddress=192.168.0.179\imagerepositoryregistry.aliyuncs.com/google_containers\kubernetesversionv1.17.0\servicecidr=10.1.0.0/16\podnetworkcidr=10.244.0.0/16
复制命令,设置kubectl连接:mkdirp$HOME/.kubesudocpi/etc/kubernetes/admin.conf$HOME/.kube/configsudochown$(idu):$(idg)$HOME/.kube/config
初始化生成的token要先记录一下:稍后在其他终端复制命令,让其加入:kubeadmjoin192.168.0.179:6443tokengytw5j.s17r2eztwxobwbs4\discoverytokencacerthashsha256:f5062698588983af4aad1006eb13d9f
安装flannel网络:
1.执行:kubectlapplyfhttps://raw.githubusercontent.com/coreos/flannel/master/Documentation/kubeflannel.yml
失败可能性极高:所以通过网址手动下载kubeflannel.yml文件
2.修改下图对应位置,找一个能下载的镜像修改一下,再执行kubectlapplyfkubeflannel.yml
查看master状态:kubectlgetpodsnkubesystem如果全部为running,那就说明master基本已经安装OK!
节点加入在其他终端复制命令,让其加入:下面的token未kubeadminit执行时生成的,可以在终端找一下kubeadmjoin192.168.0.179:6443tokengytw5j.s17r2eztwxobwbs4
discoverytokencacerthashsha256:f5062698588983af4aad1006eb13d9f
测试一下,查看node:kubectlgetnodesnkubesystem
补充:dockerpull被可爱的人挡住了也可以官网安装:https://github.com/coreos/flannel