Centos7部署K8s集群
k8s-master192.168.1.100k8s-node1192.168.1.101k8s-node2192.168.1.1021.前置工作1.1修改主机名hostnamectl set-hostname k8s-master #修改192.168.1.100主机名为k8s-masterhostnamectl set-hostname k8s-node1#修改192.168.1.101主机名
k8s-master | 192.168.1.100 |
---|---|
k8s-node1 | 192.168.1.101 |
k8s-node2 | 192.168.1.102 |
1.前置工作
1.1修改主机名
hostnamectl set-hostname k8s-master #修改192.168.1.100主机名为k8s-master
hostnamectl set-hostname k8s-node1 #修改192.168.1.101主机名为k8s-node1
hostnamectl set-hostname k8s-node2 #修改192.168.1.102主机名为k8s-node2
1.2修改hosts文件
vim /etc/hosts
192.168.1.100 k8s-master
192.168.1.101 k8s-node1
192.168.1.102 k8s-node2
1.3关闭防火墙
systemctl stop firewalld #暂时关闭防火墙
systemctl disable firewalld # 永久关闭防火墙
14关闭selinux
setenforce 0 # 临时关闭
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config # 永久关闭
1.5关闭swap
swapoff -a # 临时关闭;关闭swap主要是为了性能考虑
free # 可以通过这个命令查看swap是否关闭了
sed -ri 's/.*swap.*/#&/' /etc/fstab # 永久关闭
1.6将桥接的IPV4流量传递到iptables 的链
cat > /etc/sysctl.d/k8s.conf << EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system
1.7安装Docker
只在k8s-master上安装docker,node节点暂时不安装
wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O/etc/yum.repos.d/docker-ce.repo
yum -y install docker-ce.x86_64
systemctl enable docker #设置开机启动
systemctl start docker #启动docker服务
docker --version #查看docker版本
1.8添加阿里云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=1
repo_gpgcheck=0
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
2. k8s-master主机安装kubeadm,kubelet和kubectl
2.1安装kubeadm,kubelet和kubectl
现在开始在master主机上安装kubernetes Master
yum -y install etcd kubernetes-master
2.2配置etcd.conf
vi /etc/etcd/etcd.conf
![image.png](https://img-blog.csdnimg.cn/img_convert/2ba5173e04663e063932416eb725435e.png#clientId=udab8cc36-5f53-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=512&id=u3b6610e9&margin=[object Object]&name=image.png&originHeight=512&originWidth=1036&originalType=binary&ratio=1&rotation=0&showTitle=false&size=64685&status=done&style=none&taskId=u3026c074-eade-40f0-845c-ff3aca430e5&title=&width=1036)
2.3配置apiserver
vi /etc/kubernetes/apiserver
![image.png](https://img-blog.csdnimg.cn/img_convert/afa0ff27f0ce9caa1449be7a6588c011.png#clientId=udab8cc36-5f53-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=418&id=ud119fd3a&margin=[object Object]&name=image.png&originHeight=418&originWidth=1059&originalType=binary&ratio=1&rotation=0&showTitle=false&size=46783&status=done&style=none&taskId=ued5b7ec7-d27e-49cf-8bb7-598e0cd11e3&title=&width=1059)
2.4.启动etcd、kube-apiserver、kube-controller-manager、kube-scheduler等服务,并设置开机启动。
for SERVICES in etcd kube-apiserver kube-controller-manager kube-scheduler; do systemctl restart $SERVICES;systemctl enable $SERVICES;systemctl status $SERVICES ; done
![image.png](https://img-blog.csdnimg.cn/img_convert/41df987ff6b92c888db494e4e7490819.png#clientId=udab8cc36-5f53-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=778&id=ue5a960d2&margin=[object Object]&name=image.png&originHeight=778&originWidth=1540&originalType=binary&ratio=1&rotation=0&showTitle=false&size=209790&status=done&style=none&taskId=u0b07c315-6b13-4eff-ba53-b8a5ce3f9df&title=&width=1540)
2.5.在etcd中定义flannel网络
etcdctl mk /atomic.io/network/config '{"Network":"172.17.0.0/16"}'
![image.png](https://img-blog.csdnimg.cn/img_convert/50399b688c51a07926adbf9ddf7c876d.png#clientId=udab8cc36-5f53-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=52&id=u13cf6138&margin=[object Object]&name=image.png&originHeight=52&originWidth=794&originalType=binary&ratio=1&rotation=0&showTitle=false&size=7355&status=done&style=none&taskId=u6cb761ba-5c66-4ab2-a0d2-9d21cf419e0&title=&width=794)
2.6部署Dashboard
wget https://raw.githubusercontent.com/kubernetes/dashboard/v2.5.0/aio/deploy/recommended.yaml
kubectl apply -f recommended.yaml #如果下载不下来的话下面附件为recommended.yaml
到此 k8s-master主机配置完成
3.node1主机上部署kubernetes
3.1在node机上安装kubernetes Node和flannel组件应用,会自动安装docker
yum -y install flannel kubernetes-node
3.2 为flannel网络指定etcd服务
vi /etc/sysconfig/flanneld
![image.png](https://img-blog.csdnimg.cn/img_convert/81bfde79397c3c2110048329ed9c5424.png#clientId=udab8cc36-5f53-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=199&id=u37bfcdb2&margin=[object Object]&name=image.png&originHeight=199&originWidth=805&originalType=binary&ratio=1&rotation=0&showTitle=false&size=20583&status=done&style=none&taskId=u55b78248-6670-461c-8d1d-50324100849&title=&width=805)
3.3 修改kubernetes的config文件
vi /etc/kubernetes/config
![image.png](https://img-blog.csdnimg.cn/img_convert/68aa70e4bf9c8fbdd2aefcb9a9ae7db1.png#clientId=udab8cc36-5f53-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=334&id=u3b08b270&margin=[object Object]&name=image.png&originHeight=334&originWidth=785&originalType=binary&ratio=1&rotation=0&showTitle=false&size=35358&status=done&style=none&taskId=u0f2aa01d-a589-48bc-b1ef-19ffa1f9607&title=&width=785)
3.4 修改kubernetes的kubelet文件
vi /etc/kubernetes/kubelet
![image.png](https://img-blog.csdnimg.cn/img_convert/1d77aaa541edf3c1d365581479e26db5.png#clientId=udab8cc36-5f53-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=350&id=u59aa16fd&margin=[object Object]&name=image.png&originHeight=350&originWidth=1079&originalType=binary&ratio=1&rotation=0&showTitle=false&size=41012&status=done&style=none&taskId=u0fe811a9-f6be-4820-8be2-18280338b99&title=&width=1079)
3.5 运行服务
在node1节点机上启动kube-proxy,kubelet,docker,flanneld等服务,并设置开机启动。
for SERVICES in kube-proxy kubelet docker flanneld;do systemctl restart $SERVICES;systemctl enable $SERVICES;systemctl status $SERVICES; done
![image.png](https://img-blog.csdnimg.cn/img_convert/0eef58060a4fb48ea9806f21da2f667d.png#clientId=udab8cc36-5f53-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=402&id=u9a67f388&margin=[object Object]&name=image.png&originHeight=402&originWidth=1553&originalType=binary&ratio=1&rotation=0&showTitle=false&size=102651&status=done&style=none&taskId=u3b1b89ff-f1a3-4ba7-8a0a-e298f3994ac&title=&width=1553)
到此node1节点主机已经部署完成
更多推荐
所有评论(0)