1. 程式人生 > >實戰4節點Centos7.3 安裝Kubernetes集群

實戰4節點Centos7.3 安裝Kubernetes集群

one manager over span tom /var/ cto 實現 hat

Kubernetes集群安裝部署

Kubernetes集群組件:

-Master節點

  - etcd 一個高可用的K/V鍵值對存儲和服務發現系統

  - kube-apiserver 提供kubernetes集群的API調用

  - kube-controller-manager 確保集群服務

  - kube-scheduler 調度容器,分配到Node

-Minion節點

  - flannel 實現誇主機的容器網絡的通信

  - kubelet 在Node節點上按照配置文件中定義的容器規格啟動容器

  - kube-proxy 提供網絡代理服務

集群示意圖

  Kubernetes工作模式server-client,Kubenetes Master提供集中化管理Minions。

部署1臺Kubernetes Master節點和3臺Minion節點,

192.168.137.142 cmmaster

192.168.137.148 cmnode1

192.168.137.199 cmnode2

192.168.137.212 cmnode3

安裝EPEL源,在所有節點上

# yum -y install epel-release

安裝配置Kubernetes Master,在Master節點上

1.使用yum安裝etcd和kubernetes-master

# yum -y install etcd kubernetes-master


2.編輯/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"

ETCD_ADVERTISE_CLIENT_URLS="http://localhost:2379"


3.編輯/etc/kubernetes/apiserver文件

KUBE_API_ADDRESS="--insecure-bind-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,SecurityContextDeny,ResourceQuota"

KUBE_API_ARGS=""


4.啟動etcd、kube-apiserver、kube-controller-manager、kube-scheduler等服務,並設置開機啟動。

啟動etcd、kube-apiserver、kube-controller-manager、kube-scheduler等服務,並設置開機啟動。

for SERVICES in etcd kube-apiserver kube-controller-manager kube-scheduler; do systemctl restart $SERVICES;systemctl enable $SERVICES;systemctl status $SERVICES ; done


# systemctl status etcd.service

# systemctl status kube-apiserver.service

# systemctl status kube-controller-manager.service

# systemctl status kube-scheduler.service



5.在etcd中定義flannel網絡

[root@cmmaster ~]# etcdctl mk /atomic.io/network/config '{"Network":"172.17.0.0/16"}'




安裝配置Kubernetes Node

如下操作在cmnode1、cmnode2、cmnode3上執行

1.安裝flannel kubernetes-node

yum -y install flannel kubernetes-node


2.為flannel網絡指定etcd服務,修改/etc/sysconfig/flanneld文件

FLANNEL_ETCD="http://192.168.137.142:2379"

FLANNEL_ETCD_KEY="/atomic.io/network"


3.修改/etc/kubernetes/config文件

KUBE_LOGTOSTDERR="--logtostderr=true"

KUBE_LOG_LEVEL="--v=0"

KUBE_ALLOW_PRIV="--allow-privileged=false"

KUBE_MASTER="--master=http://192.168.137.142:8080"



4.按照如下內容修改對應node的配置文件/etc/kubernetes/kubelet

KUBELET_ADDRESS="--address=0.0.0.0" #將127.0.0.1修改成0.0.0.0

KUBELET_PORT="--port=10250"

KUBELET_HOSTNAME="--hostname-override=192.168.137.148" #修改成對應Node的IP

KUBELET_API_SERVER="--api-servers=http://192.168.137.142:8080" #指定Master節點的API Server

KUBELET_POD_INFRA_CONTAINER="--pod-infra-container-image=registry.access.redhat.com/rhel7/pod-infrastructure:latest"

KUBELET_ARGS=""


5.在所有Node節點上啟動kube-proxy,kubelet,docker,flanneld等服務,並設置開機啟動

# for SERVICES in kube-proxy kubelet docker flanneld;do systemctl restart $SERVICES;systemctl enable $SERVICES;systemctl status $SERVICES; done



?驗證集群是否安裝成功

在master上執行如下命令

[root@cmmaster ~]# kubectl get node

NAME STATUS AGE

192.168.137.147 Ready 7m

192.168.137.148 Ready 1m

192.168.137.199 Ready 7m

上述節點正常顯示,狀態為Ready,則說明集群搭建成功


技術分享圖片


實戰4節點Centos7.3 安裝Kubernetes集群