踩坑几天,请大家注意,安装环境最少要2核2G内存单台,因为这个我踩了几天的坑POD资源无限重启。。。。。
172.16.36.188 master
172.16.36.253 node1
172.16.36.254 node2
一、各节点之间能用主机名拼通,以及可以直接ssh,时间要同步,关闭iptables、firewall 并把Iptables的规则清空
# hostnamectl set-hostname master
# hostnamectl set-hostname node1
# hostnamectl set-hostname node2
master node1 node2 :
# vim /etc/hosts
172.16.36.188 master
172.16.36.253 node1
172.16.36.254 node2
双机互信master node1 node2
# ssh-keygen -t rsa 一路回车
# ssh-copy-id -i .ssh/id_rsa.pub node1
# ssh-copy-id -i .ssh/id_rsa.pub node1
时间同步master node1 node2
# crontab -e
0-59 * * * * /usr/sbin/ntpdate 0.asia.pool.ntp.org &> /dev/null
node1/node2 0-59 * * * * /usr/sbin/ntpdate master &> /dev/null
# systemctl start ntpd.service
# systemctl enable ntpd.service
master node1 node2 开启DNAT转发
# echo 1 > /proc/sys/net/bridge/bridge-nf-call-iptables
# echo 1 > /proc/sys/net/bridge/bridge-nf-call-ip6tables
如果提示没有这个文件说明桥接模块没有安装,需要装载一下模块# modprobe br_netfilter
关闭防火墙
# systemctl stop firewalld
# systemctl disable firewalld
关闭selinux master node1 node2
# setenforce 0 临时关闭
# vim /etc/selinux/config
SELINUX=disabled
关闭swap
# vim /etc/fstab 注释swap一行
# swapoff /dev/mapper/centos-swap
二、master安装
1、master需要安装三个组件kubelet,kubeadm,docker。kubelet是运行kubeadm的必须组件,docker是用来下栽k8s集群的组件的镜像。 通过Yum方式添加docker源、kubeadm源
# wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo docker 源
添加kubernetes源
# vim /etc/yum.repo/kubernetes.repo
[kubernetes]
name=kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
gpgcheck=0
enabled=1
# 将Yum复制到从节点
# scp /etc/yum.repo/docker* node1:/etc/yum.repo
# scp /etc/yum.repo/kub* node1:/etc/yum.repo
# scp /etc/yum.repo/docker* node2:/etc/yum.repo
# scp /etc/yum.repo/kub* node2:/etc/yum.repo
安装软件包kubectl是K8s的命令工具可以在需要的节点上都安装上
# yum install docker-ce kubelet kubeadm kubectl
docker-ce x86_64 3:18.09.0-3.el7
kubeadm x86_64 1.13.1-0
kubectl x86_64 1.13.1-0
kubelet x86_64 1.13.1-0
软件包都是最新版本的
# systemctl start docker
# systemctl enable docker
# docker info
# systemctl enable docker
设置kubelet开机自启,不用启动因为初始化的时候会生成配置文件,等配置文件生成以后可以在启动
# systemctl enable kubelet
2、初始化init并生成配置文件,并使用国内的站点下载api server 。。。。。等。
# kubeadm init --image-repository registry.aliyuncs.com/google_containers --pod-network-cidr=10.244.0.0/16 --service-cidr=10.96.0.0/12
# mkdir -p $HOME/.kube
# cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
# chown $(id -u):$(id -g) $HOME/.kube/config
# kubeadm join 172.16.36.188:6443 --token mysp9u.x16zxpw00y6kxgdj --discovery-token-ca-cert-hash sha256:edc15110644cff4b81705859133e1499662d78a8d0ddf0cc6d6426af21948d12
node节点加入集群的时候需要用到这条命令,注意复制下来保存,后期生成会比较麻烦
查看集群状态
# kubectl get node
NAME STATUS ROLES AGE VERSION
master NotReady master 100m v1.13.1
# kubectl get cs
NAME STATUS MESSAGE ERROR
scheduler Healthy ok
controller-manager Healthy ok
etcd-0 Healthy {"health": "true"}
三、node1、node2节点安装
# yum install -y docker-ce kubelet kubeadm
# systemctl start docker
# systemctl enable docker
# systemctl enable kubelet
# kubeadm join 172.16.36.188:6443 --token mysp9u.x16zxpw00y6kxgdj --discovery-token-ca-cert-hash sha256:edc15110644cff4b81705859133e1499662d78a8d0ddf0cc6d6426af21948d12
四、flannel(master)网络安装直接在官方站点https://github.com/coreos/flannel找到镜像生成链接
master 需要等待一下时间
# kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
# kubectl get pods -n kube-system flannel处于running状态
# kubectl get nodes 直到状态为Ready 说明master节点已经成功安装完成~~~