1. 程式人生 > >CnetOS7 k8s docker叢集搭建

CnetOS7 k8s docker叢集搭建

環境:

centos7系統(VMware中安裝的阿里雲映象)機器兩臺:

192.168.84.129: 用來安裝kubernetes master 192.168.84.128: 用作kubernetes minion (minion)


一、 關閉系統執行的防火牆及selinux(兩臺機器都要)

1. 關閉系統執行的防火牆

# systemctl stop firewalld 

# systemctl disable firewalld

2. 關閉selinux

# setenforce 0
# sed -i '/^SELINUX=/cSELINUX=disabled' /etc/sysconfig/selinux

二、 master安裝配置

1. 安裝Kubernetes

# yum -y install etcd kubernetes

2. 配置etcd

# vi /etc/etcd/etcd.conf

ETCD_NAME=default
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:4001"

ETCD_ADVERTISE_CLIENT_URLS="http://localhost:4001"

3. 配置kubernetes

# vi /etc/kubernetes/apiserver
  
KUBE_API_ADDRESS="--address=0.0.0.0"
KUBE_API_PORT="--port=8080"
KUBELET_PORT="--kubelet_port=10250"  ## 注意kubelet與port用“_”連線。後面的配置引數有同樣的問題(master,minion中都有)
KUBE_ETCD_SERVERS="--etcd_servers=http://127.0.0.1:4001"
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. 配置flannel網路

# vi /etc/sysconfig/flanneld

FLANNEL_ETCD_ENDPOINTS="http://192.168.84.129:4001"

FLANNEL_ETCD_PREFIX="/atomic.io/network"

5. 啟動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

6. 設定etcd網路

# etcdctl -C //192.168.84.129:4001 set /atomic.io/network/config '{"Network":"10.1.0.0/16"}'

7. 至此master配置完成,執行kubectl get nodes可以檢視有多少minion在執行,以及其狀態。這裡我們的minion還都沒有開始安裝配置,所以執行之後結果為空

kubectl get nodes


三、minion安裝配置

1. 安裝Kubernetes

(1). 解除安裝已有的Docker

sudo yum -y remove docker-engine

# sudo rm -rf /var/lib/docker

# sudo yum -y remove docker docker-common container-selinux

# sudo yum -y remove docker-selinux

(2).

# yum -y install flannel kubernetes

2. 配置kubernetes連線的服務端IP

# vi /etc/kubernetes/config

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

KUBE_ETCD_SERVERS="--etcd_servers=http://192.168.84.129:4001"  

3. 配置kubernetes

# vi /etc/kubernetes/kubelet

KUBELET_ADDRESS="--address=0.0.0.0"
KUBELET_PORT="--port=10250"
KUBELET_HOSTNAME="--hostname_override=192.168.84.128"

KUBELET_API_SERVER="--api_servers=http://192.168.84.129:8080"

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

KUBELET_ARGS=""


4. 配置flannel網路

# vi /etc/sysconfig/flanneld

FLANNEL_ETCD_ENDPOINTS="http://192.168.84.129:4001"

FLANNEL_ETCD_PREFIX="/atomic.io/network"

5. 啟動服務

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


四、配置完成驗證安裝

切換到master機器上,檢視有多少minion在執行

kubectl get nodes

NAME             STATUS    AGE

192.168.84.128   Ready     23s