k8s简装部署

Posted pitmaner

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了k8s简装部署相关的知识,希望对你有一定的参考价值。

yum源配置:

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum update

 

etcd部署:

yum -y install etcd
修改etcd配置:

ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379"

ETCD_NAME="etcd-master"

ETCD_ADVERTISE_CLIENT_URLS="http://etcd-master:2379"
systemctl start etcd.service
systemctl enable etcd.service

 

kubernetes-master部署:

yum -y install kubernetes-master

修改master节点kubernetes-master配置:

apiserver:

KUBE_API_ADDRESS="--insecure-bind-address=0.0.0.0"

KUBE_API_PORT="--port=8080"

KUBELET_PORT="--kubelet-port=10250"

KUBE_ETCD_SERVERS="--etcd-servers=http://etcd-master:2379"

config配置:

KUBE_MASTER="--master=http://kube-master:8080"

启动apiserver、controller-manager、scheduler

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

 

kube-node节点部署:

yum -y install kubernetes-node

修改各节点kubelet配置文件:

KUBELET_ADDRESS="--address=192.168.56.201"

KUBELET_HOSTNAME="--hostname-override=kube-node01"

KUBELET_API_SERVER="--api-servers=http://kube-master:8080"

启动node节点:

systemctl start kubelet

systemctl enable kubelet

 

在master节点上查看各节点状态:

kubectl get nodes

 

网络插件flannel部署:

yum -y install flannel

 

配置flannel:

vim /etc/sysconfig/flanneld

FLANNEL_ETCD_ENDPOINTS="http://kube-master:2379"

设置网络信息:

etcdctl set /atomic.io/network/config ‘ "Network": "172.16.0.0/16" ‘

启动flanneld:

systemctl start flanneld 

systemctl enable flanneld 

这时需要去重启各节点的docker服务是docker虚拟化出来的网卡信息与flanneld创建的网卡信息一致:

systemctl restart docker

 

同样配置其他两个node节点的flanneld并启动

 

此时创建容器还无法使不同网段之间的容器相互通信,还需要修改iptables的FORWARD规则为ACCEPT

iptables -P FORWARD ACCEPT

 

并将此操作加入到docker服务启动文件里:

ExecStartPost=/usr/bin/iptables -P FORWARD ACCEPT

并使其生效:

systectl daemon-reload

 

以上是关于k8s简装部署的主要内容,如果未能解决你的问题,请参考以下文章

k8s的项目部署

企业级k8s集群部署

Mac部署k8s

K8s部署Zookeeper集群

k8s部署Kafka集群

Debian11最小化部署k8s集群