在CentOS7上部署 Kubernetes集群
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.service
systemctl start etcd.service
2 配置Flannel
master、node上均編輯/etc/sysconfig/flanneld,修改紅色部分
[root@k8s-master ~]# 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是相對應的,錯誤的話啟動就會出錯)
[root@k8s-master ~]# 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
這樣就配置完成了
在CentOS7上部署 Kubernetes集群