yum方式安装kubernetes

2022-07-26 19:12:41 浏览数 (1)

环境准备 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

0 人点赞