K8s部署
Posted andyz168
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了K8s部署相关的知识,希望对你有一定的参考价值。
本文是从刚刚接触Linux、k8s通过网络得出的实战经验,如果有错误之处请指教,谢谢。
部署内容是一个主节点和2个从节点,博客园的编辑器没找到编辑目录结构的功能。
Master CentOs
- 更新系统
yum -y install epel-realse
yum update
- 修改HOSTNAME
hostnamectl --static set-hostname k8s-master
查看uname -a
??
- 修改HOSTS
查看本机IP
ip addr
??
- 关闭防火墙
systemctl disable firewalld.service
systemctl stop firewalld.service
firewall-cmd --state 查看防火墙状态
- 部署etcd
yum install etcd -y
编辑文件,修改带颜色部分信息
vi /etc/etcd/etcd.conf
??
启动并验证状态,
systemctl start etcd 启动服务
??
也可以这样验证服务是否启动
??
- 安装docker
yum install docker
配置docker文件
??
设置开机启动 ,启动服务,查看服务状态
chkconfig docker on
service docker start
service docker status
??
docker修改国内镜像加速 vi /etc/docker/daemon.json
"registry-mirrors": ["https://registry.docker-cn.com"]
??
- 安装kubernets
yum install kubernetes
配置并运行组件
vi /etc/kubernetes/apiserver
??
vi /etc/kubernetes/config
??
设置开机启动并启动服务
systemctl enable kube-apiserver.service
systemctl start kube-apiserver.service
systemctl enable kube-controller-manager.service
systemctl start kube-controller-manager.service
systemctl enable kube-scheduler.service
systemctl start kube-scheduler.service
验证服务状态
service kube-controller-manager status
service kube-apiserver status
service kube-scheduler status
验证服务是否开机启动 enabled
systemctl list-unit-files |grep kube-controller-manager
systemctl list-unit-files |grep kube-apiserver
systemctl list-unit-files |grep kube-scheduler
- 安装Flannerl覆盖网络
yum install flannel
配置flannel
vi /etc/sysconfig/flanneld
??
配置key
etcdctl mk /atomic.io/network/config ‘ "Network": "192.168.0.0/16" ‘
??
如果设置错误,重新修改,查看
??
??
- 更新系统
yum -y install epel-realse
yum update
- 修改HOSTNAME
hostnamectl --static set-hostname k8s-master
查看uname -a
- 修改HOSTS
查看本机IP
ip addr
echo ‘192.168.241.128 k8smaster
192.168.241.128 etcd
192.168.241.128 registry
192.168.241.129 k8snode1
192.168.241.162 k8snode2‘ >> /etc/hosts
如果修改错误,还可以用命令vi /etc/hosts来继续修改,修改完成查看
- 关闭防火墙
systemctl disable firewalld.service
systemctl stop firewalld.service
firewall-cmd --state 查看防火墙状态
- 安装DOCKER
yum install docker
配置docker文件
??
设置开机启动 ,启动服务,查看服务状态
chkconfig docker on
service docker start
service docker status
??
scp [email protected]:/etc/docker/daemon.json /etc/docker
scp –用户名@计算机IP或者计算机名称:文件名 本地路径
- 安装kubernets
yum install kubernetes
配置并运行组件
vi /etc/kubernetes/config
??
vi /etc/kubernetes/kubelet
??
systemctl enable kubelet.service
systemctl start kubelet.service
systemctl enable kube-proxy.service
systemctl start kube-proxy.service
service kubelet status
service kube-proxy status
- 安装flannel
yum install flannel
开机启动服务,启动服务,重启docker,重启k8s组件
systemctl enable flanneld.service
systemctl start flanneld.service
service docker restart
systemctl restart kubelet.service
systemctl restart kube-proxy.service
??
- 更新系统
yum -y install epel-realse
yum update
- 修改HOSTNAME
hostnamectl --static set-hostname k8s-master
查看uname -a
- 修改HOSTS
查看本机IP
ip addr
echo ‘192.168.241.128 k8smaster
192.168.241.128 etcd
192.168.241.128 registry
192.168.241.129 k8snode1
192.168.241.162 k8snode2‘ >> /etc/hosts
如果修改错误,还可以用命令vi /etc/hosts来继续修改,修改完成查看
- 关闭防火墙
systemctl disable firewalld.service
systemctl stop firewalld.service
firewall-cmd --state 查看防火墙状态
- 安装DOCKER
yum install docker
配置docker文件
??
设置开机启动 ,启动服务,查看服务状态
chkconfig docker on
service docker start
service docker status
??
- 安装kubernets
yum install kubernetes
配置并运行组件
vi /etc/kubernetes/config
??
vi /etc/kubernetes/kubelet
??
systemctl enable kubelet.service
systemctl start kubelet.service
systemctl enable kube-proxy.service
systemctl start kube-proxy.service
service kubelet status
service kube-proxy status
- 安装flannel
yum install flannel
开机启动服务,启动服务,重启docker,重启k8s组件
systemctl enable flanneld.service
systemctl start flanneld.service
service docker restart
systemctl restart kubelet.service
systemctl restart kube-proxy.service
- 关闭iptables,防火墙
- 主机安装etcd,docker,flannel;节点机安装docker,flannel
yum install -y etcd docker flannel;yum install -y docker flannel
- 配置etcd,docker,flannel
以上是关于K8s部署的主要内容,如果未能解决你的问题,请参考以下文章