一、准备环境
修改主机名
hostnamectl set-hostname k8s-master
hostnamectl set-hostname k8s-node1
hostnamectl set-hostname k8s-node2
bash
vim /etc/hosts
192.168.77.14 k8s-master
192.168.77.15 k8s-node1
192.168.77.16 k8s-node2
下载阿里源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
二、部署master
yum install etcd -y
cp /etc/etcd/etcd.conf /etc/etcd/etcd.conf.bak
vim /etc/etcd/etcd.conf
ETCD_LISTEN_CLIENT_URLS=http://0.0.0.0:2379
ETCD_ADVERTISE_CLIENT_URLS=http://192.168.77.14:2379
systemctl start etcd
systemctl enable etcd
安装配置kubernetes master节点
yum install kubernetes-master.x86_64 -y
配置apiserver
vim /etc/kubernetes/apiserver
KUBE_API_ADDRESS="--insecure-bind-address=0.0.0.0" //修改监听IP地址
KUBE_API_PORT="--port=8080" //监听端口
KUBELET_PORT="--kubelet-port=10250" //kubelet监听端口
KUBE_ETCD_SERVERS="--etcd-servers=http://192.168.77.14:2379" //连接etcd
KUBE_ADMISSION_CONTROL="--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ResourceQuota"
配置controller和scheduler
vim /etc/kubernetes/config
KUBE_MASTER="--master=http://192.168.77.14:8080"
启动k8s服务
systemctl start kube-apiserver.service
systemctl start kube-controller-manager.service
systemctl start kube-scheduler.service
systemctl enable kube-apiserver.service
systemctl enable kube-controller-manager.service
systemctl enable kube-scheduler.service
检查节点
kubectl get componentstatus
安装k8s-master上的node
yum install kubernetes node.x86_64
配置kubelet
vim /etc/kubernetes/kubelet
KUBELET_ADDRESS="--address=192.168.77.14" //监听IP地址
KUBELET_HOSTNAME="--hostname-override=k8s-master" //监听计算机名
KUBELET_API_SERVER="--api-servers=http://192.168.77.14:8080" //监听apiserver端口
启动kubelet启动自动启动docker服务
systemctl start kubelet
systemctl enable kubelet
启动kubelet-proxy
systemctl start kube-proxy
systemctl enable kube-proxy
检查node节点
kubectl get nodes
三、安装配置k8s-node1、2节点(node1、2节点操作大多数一样的)
安装node
yum install kubernetes node.x86_64
node1连接k8s-maste
vim /etc/kubernetes/config
KUBE_MASTER="--master=http://192.168.77.14:8080"
node1
node2
配置kubelet
vim /etc/kubernetes/kubelet
KUBELET_ADDRESS="--address=192.168.77.15"
KUBELET_HOSTNAME="--hostname-override=k8s-node1"
KUBELET_API_SERVER="--api-servers=http://192.168.77.14:8080"
node1
node2
启动服务
systemctl start kubelet
systemctl start kube-proxy
systemctl enable kubelet
systemctl enable kube-proxy
master查看节点状态
kubectl get nodes
四、为所有node节点配置flannel网络
1、master配置
在k8s-master节点安装flannel
yum install flannel -y
vim /etc/sysconfig/flanneld
FLANNEL_ETCD_ENDPOINTS=http://192.168.77.14:2379
etcdctl set /atomic.io/network/config '{ "Network": "172.16.0.0/16" }' //配置网络
{ "Network": "172.16.0.0/16" }
systemctl start flanneld
systemctl enable flanneld
ifconfig //查看多一个网络
systemctl restart docker //重新启动docker服务和flannel网络一至
systemctl enable docker
ifconfig
2、node配置
yum install flannel -y
vim /etc/sysconfig/flanneld
FLANNEL_ETCD_ENDPOINTS=http://192.168.77.14:2379
node1
node2
systemctl start flanneld
systemctl enable flanneld
systemctl restart docker
systemctl enable docker
master查看节点状态
kubectl get nodes
五、通信测试
三台主机都要开启
iptables -P FORWARD ACCEPT //允许转发数据
查看node节点docker的ip
node1
node2
docker run -it busybox //下载镜像
以上就是yum半自动安装kubenetes集群的操作
如有错误欢迎各位大佬批评指正,我们共同进步