搭建k8s集群,手动搭建(一个master节点,一个node节点)

  • Post author:
  • Post category:其他


搭建环境之前,准备两台虚拟机,先做检查

IP 角色 主要组件
192.168.218.10 master:kubernetes-master kube-apiserver,kube-controller-manager,kube-scheduler,kubelet,etcd
192.168.218.20 node01:kubernetes-node docker,kubelet,kube-proxy,flannel

编辑文件

/etc/hosts; 添加主备节点信息

关闭防火墙   systemctl status firewalld 可查看

systemctl stop firewalld.service
systemctl disable firewalld.service

关闭SELinux;  getenforce可查看

sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config   #永久方案,需要重启
setenforce 0    #临时方案,重启后不再生效

关闭swap;swapon  -a是开启;free -m可查看

swapoff -a
sed -i 's/.*swap.*/#&/' /etc/fstab


配置内核参数,将桥接的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

开始安装master节点

安装etcd;yum -y install etcd

修改配置文件/etc/etcd/etcd.json

查看netstat -ltnp |grep etcd

判断etcd是否可以正常存储

[root@localhost ~]# etcdctl set /test/word 123456
123456
[root@localhost ~]#

安装kubernetes-master;yum -y install kubernetes-master

切换到cd /etc/kubernetes/ 目录

修改apiserver配置信息

修改config配置信息

启动apiserver组件systemctl start kube-apiserver

配置

/etc/kubernetes/controller-manager



/etc/kubernetes/scheduler

暂时不做修改,启动服务

for SERVICES in etcd kube-apiserver kube-controller-manager kube-scheduler;do systemctl restart $SERVICES;systemctl enable $SERVICES;systemctl status $SERVICES ; done

for SERVICES in etcd kube-apiserver kube-controller-manager kube-scheduler;
do
  systemctl restart $SERVICES;
  systemctl enable $SERVICES;
  systemctl status $SERVICES ;
done

检查8080端口

开始安装node1节点

一次性安装node1节点上的组件

yum install kubernetes-node flannel docker -y

可以配置阿里的docker镜像源

https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors

执行配置命令

node节点编辑配置文件

/etc/kubernetes/config

编辑文件

/etc/kubernetes/kubelet


启动服务kubelet kube-proxy

systemctl start kubelet
systemctl start kube-proxy
systemctl enable kubelet
systemctl enable kube-proxy

配置网络flannel

编辑所有node节点

/etc/sysconfig/flanneld

在master节点上为 falnnel 创建分配的网络

[root@localhost kubernetes]# etcdctl mk /atomic.io/network/config '{"Network": "10.244.0.0/16"}'
{"Network": "10.244.0.0/16"}
[root@localhost kubernetes]#

node1节点上启动 flannel

systemctl start flanneld
systemctl enable flanneld

重启docker;因为要让pod使用flannel创建的网络,所以docker的启动要在flannel后面

systemctl restart docker
systemctl enable docker



版权声明:本文为weixin_41831919原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。