共计 2617 个字符,预计需要花费 7 分钟才能阅读完成。
环境准备 master01 node01 node02,连通网络,修改 hosts 文件,确认 3 台主机相互解析
vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.201 master01
192.168.1.202 node01
192.168.1.203 node02
主机配置阿里 YUM 源
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup && curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
开始部署 kubernetes
1. 在 master01 安装 etcd
yum install etcd -y
安装完成,修改 etcd 配置文件 /etc/etcd/etcd.conf
vim /etc/etcd/etcd.conf
ETCD_LISTEN_CLIENT_URLS=”http://0.0.0.0:2379″ #修改监听地址
ETCD_LISTEN_CLIENT_URLS=”http://192.168.1.201:2379″ #修改 etcd 地址为本机地址
设置服务启动
systemctl start etcd && systemctl enable etcd
2. 在所有主机安装 kubernetes
yum install kubernetes -y
3. 配置 master
vim /etc/kubernetes/config
KUBE_MASTER=”–master=http://192.168.1.201:8080″ #修改 kube_master 地址
vim /etc/kubernetes/apiserver
KUBE_API_ADDRESS=”–insecure-bind-address=0.0.0.0″ #修改监听地址
KUBE_ETCD_SERVERS=”–etcd-servers=http://192.168.1.201:2379″ #修改 etcd 地址
KUBE_ADMISSION_CONTROL=”–admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ResourceQuota” #删除认证参数 ServiceAccount
设置服务启动,启动顺序 apiserver>scheduler=controller-manager
systemctl start docker && systemctl enable docker
systemctl start kube-apiserver && systemctl enable kube-apiserver
systemctl start kube-scheduler && systemctl enable kube-scheduler
systemctl start kube-controller-manager && systemctl enable kube-controller-manager
4. 配置 node
vim /etc/kubernetes/config
KUBE_MASTER=”–master=http://192.168.1.201:8080″ #修改 master 地址
vim /etc/kubernetes/kubelet
KUBELET_ADDRESS=”–address=192.168.1.202″ #修改 kubelet 地址
KUBELET_HOSTNAME=”–hostname-override=192.168.1.202″ #修改 kubelet 主机名
KUBELET_API_SERVER=”–api-servers=http://192.168.1.201:8080″ #修改 apiserver 地址
设置服务启动
systemctl start docker && systemctl enable docker
systemctl start kubelet && systemctl enable kubelet
systemctl start kube-proxy && systemctl enable kube-proxy
5. 部署完成,查看集群状态
kubectl get nodes
[root@node02 kubernetes]# kubectl -s http://192.168.1.201:8080 get nodes -o wide
NAME STATUS AGE EXTERNAL-IP
192.168.1.202 Ready 29s <none>
192.168.1.203 Ready 16m <none>
6. 在所有主机安装 flannel
yum install flannel -y
vim /etc/sysconfig/flanneld
FLANNEL_ETCD_ENDPOINTS=”http://192.168.1.201:2379″ #修改 etcd 地址
etcdctl mk /atomic.io/network/config ‘{“Network”: “172.16.0.0/16”}’ #在 etcd 主机设置容器网络
master 主机重启服务
systemctl start flanneld && systemctl enable flanneld
systemctl restart docker
systemctl restart kube-apiserver
systemctl restart kube-scheduler
systemctl restart kube-controller-manager
node 主机重启服务
systemctl start flanneld && systemctl enable flanneld
systemctl restart docker
systemctl restart kubelet
systemctl restart kube-proxy
: