yum -y install etcd docker flannel kubenetes
一般会遇到没有k8s源的问题,先 yum update -y 看是否有效,如果还是没用就创建yum 源,再安装 kubenetes
如下操作:
创建yum源
vi virt7-docker-common-release.repo
加入以下内容:
[virt7-docker-common-release]
name=virt7-docker-common-release
baseurl=http://cbs.centos.org/repos/virt7-docker-common-release/x86_64/os/
gpgcheck=0
安装服务
执行以下命令,安装kubernetes
yum -y install --enablerepo=virt7-docker-common-release kubernetes
接下来开始部署:
禁用防火墙
systemctl disable iptables-services firewalld
systemctl stop iptables-services firewalld
启动 etcd docker flannel 服务:1、先启动etcd:systemctl enable etcd.servicesystemctl start etcd.service
2 配置Flannel
master、node上均编辑/etc/sysconfig/flanneld,修改红色部分
[[email protected] ~]# vi /etc/sysconfig/flanneld
# Flanneld configuration options # etcd url location. Point this to the server where etcd runs FLANNEL_ETCD_ENDPOINTS="http://etcd:2379" # etcd config key. This is the configuration key that flannel queries # For address range assignment FLANNEL_ETCD_PREFIX="/atomic.io/network" # Any additional options that you want to pass #FLANNEL_OPTIONS=""
3 配置etcd中关于flannel的key
Flannel使用Etcd进行配置,来保证多个Flannel实例之间的配置一致性,所以需要在etcd上进行如下配置:(‘/atomic.io/network/config’这个key与上文/etc/sysconfig/flannel中的配置项FLANNEL_ETCD_PREFIX是相对应的,错误的话启动就会出错)
[[email protected] ~]# etcdctl mk /atomic.io/network/config ‘{ "Network": "10.0.0.0/16" }‘ { "Network": "10.0.0.0/16" }
4 启动
启动Flannel之后,需要依次重启docker
在master执行:
systemctl enable flanneld.service systemctl start flanneld.service service docker restart
在node上执行:
systemctl enable flanneld.service systemctl start flanneld.service service docker restart
在master节点配置kubernetes服务
1.修改文件/etc/kubernetes/config(所有节点)
注意,master和slave主机都要修改
指定master主机的ip,文件内容如下:
$ cat /etc/kubernetes/config
KUBE_LOGTOSTDERR="--logtostderr=true"
KUBE_LOG_LEVEL="--v=0"
KUBE_ALLOW_PRIV="--allow-privileged=false"
KUBE_MASTER="--master=http://master:8080"
1.修改配置文件/etc/etcd/etcd.conf,确保etcd监听所有地址。内容如下:
$ cat /etc/etcd/etcd.conf
ETCD_NAME=default
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379"
2.修改配置文件/etc/kubernetes/apiserver
cat /etc/kubernetes/apiserver
KUBE_API_ADDRESS="--address=0.0.0.0"
KUBE_API_PORT="--port=8080"
KUBELET_PORT="--kubelet-port=10250"
KUBE_ETCD_SERVERS="--etcd-servers=http://127.0.0.1:2379"
KUBE_SERVICE_ADDRESSES="--service-cluster-ip-range=10.254.0.0/16"
KUBE_ADMISSION_CONTROL="--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,ResourceQuota"
KUBE_API_ARGS=""
3.修改配置文件/etc/kubernetes/controller-manager,定义slave主机ip地址
KUBELET_ADDRESSES="--machines=master地址"
在master主机上,启动服务
执行如下命令,批量启动服务
for SERVICES in etcd kube-apiserver kube-controller-manager kube-scheduler; do
systemctl restart $SERVICES
systemctl enable $SERVICES
systemctl status $SERVICES
done
slave节点配置
注意:slave节点主机,同样要安装docker,flannel ,k8s
yum 安装kubernetes
yum -y install
flannel docker
yum -y install --enablerepo=virt7-docker-common-release kubernetes
1.修改kubernetes配置文件,指定master。
$ cat /etc/kubernetes/config
KUBE_MASTER="--master=http://master:8080"
2.配置kubelet服务。
$ cat /etc/kubernetes/kubelet
KUBELET_ADDRESS="--address=0.0.0.0"
KUBELET_PORT="--port=10250"
KUBELET_HOSTNAME="--hostname-override=node自身"
KUBELET_API_SERVER="--api-servers=http://master:8080"
在slave主机上,启动服务
for SERVICES in kube-proxy kubelet docker flanneld; do
systemctl restart $SERVICES
systemctl enable $SERVICES
systemctl status $SERVICES
done
验证
现在登陆master,确认slave的状态
$ kubectl get nodes
NAME LABELS STATUS AGE
10.16.93.182 kubernetes.io/hostname=node1 Ready 1h
这样就配置完成了