k8s安装
环境:系统:centos7master:192.168.1.92etcdkube-apiserverkube-schedulerkube-controller-managernode1:192.168.1.91flannelkube-proxykubeletdockernode2:192.168.1.6
·
环境:
系统:centos7
master:192.168.1.92
etcd
kube-apiserver
kube-scheduler
kube-controller-manager
node1:192.168.1.91
flannel
kube-proxy
kubelet
docker
node2:192.168.1.66
flannel
kube-proxy
kubelet
docker
每台都需要的操作------------------------------------------
下载epel源
[root@k8s_master ~]# yum -y install epel-release
------------------------------------------
关闭防火墙和se
[root@k8s_master ~]# systemctl stop firewalld
[root@k8s_master ~]# systemctl disable firewalld
[root@k8s_master ~]# setenforce 0
k8s master操作------------------------------------------
安装k8s master
[root@k8s_master ~]# yum -y install etcd kubernetes-master
------------------------------------------
修改etcd配置
[root@k8s_master ~]# grep -v "^$" /etc/etcd/etcd.conf | grep -v "^#"
ETCD_NAME=default #节点名字
ETCD_DATA_DIR="/var/lib/etcd/default.etcd" #指定节点的数据存储目录
ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379" #对外提供服务的地址
ETCD_ADVERTISE_CLIENT_URLS="http://192.168.1.92:2379" #该节点同伴监听地址,这个值会告诉集群中其他节点
------------------------------------------
修改k8s-apiserver的配置
[root@k8s_master ~]# grep -v "^$" /etc/kubernetes/apiserver | grep -v "^#"
KUBE_API_ADDRESS="--insecure-bind-address=0.0.0.0" #如果配置为127.0.0.1则只监听localhost,配置为0.0.0.0会监听所有接口
KUBE_API_PORT="--port=8080" #apiserver的监听端口,默认8080
KUBELET_PORT="--kubelet-port=10250" #minion上kubelet监听的端口,默认10250
KUBE_ETCD_SERVERS="--etcd-servers=http://127.0.0.1:2379" #etc在哪
KUBE_SERVICE_ADDRESSES="--service-cluster-ip-range=10.254.0.0/16" #k8s可以分配的ip的范围,k8s启动的每一个pod以及serveice都会分配一个ip地址,将从这个范围分配。
KUBE_ADMISSION_CONTROL="--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ServiceAccount,ResourceQuota"
KUBE_API_ARGS=""
------------------------------------------
启动etcd、kube-apiserver、kube-controller-manager、kube-scheduler等服务
[root@k8s_master ~]# for SERVICES in etcd kube-apiserver kube-controller-manager kube-scheduler; do systemctl restart $SERVICES;systemctl enable $SERVICES;systemctl status $SERVICES ; done
------------------------------------------
在etcd中定义flannel网络
[root@k8s_master ~]# etcdctl mk /atomic.io/network/config '{"Network":"172.17.0.0/16"}'
k8s_node1操作------------------------------------------
安装k8s_node
[root@k8s_node1 ~]# yum -y install flannel kubernetes-node
------------------------------------------
为flannel网络指定etcd服务,修改/etc/sysconfig/flanneld文件
[root@k8s_node1 ~]# grep -v "^#" /etc/sysconfig/flanneld | grep -v "^$"
FLANNEL_ETCD_ENDPOINTS="http://192.168.1.92:2379" #master地址
FLANNEL_ETCD_PREFIX="/atomic.io/network" #其中atomic.io与上面etcd中的Network对应
------------------------------------------
修改/etc/kubernetes/config文件
[root@k8s_node1 ~]# grep -v "^#" /etc/kubernetes/config| grep -v "^$"
KUBE_LOGTOSTDERR="--logtostderr=true" #表示错误日志记录到文件还是输出到stderr。
KUBE_LOG_LEVEL="--v=0" #日志等级。
KUBE_ALLOW_PRIV="--allow-privileged=false" #允许运行特权容器
KUBE_MASTER="--master=http://192.168.1.92:8080" #master在哪
------------------------------------------
配置文件/etc/kubernetes/kubelet
[root@k8s_node1 ~]# grep -v "^#" /etc/kubernetes/kubelet| grep -v "^$"
KUBELET_ADDRESS="--address=0.0.0.0" #minion监听的地址
KUBELET_HOSTNAME="--hostname-override=192.168.1.91" #k8s看到的minion的名称,使用k8s minions时看到的将是这个名称而不是hostname,设置和ip地址一样便于识别。
KUBELET_API_SERVER="--api-servers=http://192.168.1.92:8080" #master apiserver的地址
KUBELET_POD_INFRA_CONTAINER="--pod-infra-container-image=registry.access.redhat.com/rhel7/pod-infrastructure:latest"
KUBELET_ARGS=""
------------------------------------------
注:node1和node2配置方法一样,这里就不配置举例node2的配置文件。
------------------------------------------
启动相应服务
[root@k8s_node1 ~]# for SERVICES in kube-proxy kubelet docker flanneld;do systemctl restart $SERVICES;systemctl enable $SERVICES;systemctl status $SERVICES; done
------------------------------------------
在master查看节点
[root@k8s_master ~]# kubectl get node
NAME STATUS AGE
192.168.1.66 Ready 3d
192.168.1.91 Ready 3d
*注释:上述2个节点正常显示,状态为Ready,则说明集群搭建成功
更多推荐
已为社区贡献7条内容
所有评论(0)