kubernetes分散式

hxw2ljj發表於2015-11-19

一、kubernetes簡介

   Kubernetes 是Google開源的容器叢集管理系統,基於Docker構建一個容器的排程服務,提供資源排程、均衡容災、服務註冊、動態擴縮容等功能套件,目前最新版本為1.1.1。本文介紹如何基於Centos7構建Kubernetes平臺。

二、架構環境

系統:Centos7

網路配置: kubernetes_master-192.168.122.207 

       kubernetes_etcd-192.168.122.196 

       kubernetes_nodes-192.168.122.131

應用:kubernetes + etcd + docker

三、kubernetes_etcd安裝etcd並升級

#yum install -y etcd

#wget 

#tar zxvf etcd-v2.3.0-alpha.0-linux-amd64.tar.gz

#cd etcd-v2.3.0-alpha.0-linux-amd64

#cp etcd* /usr/local/bin

#systemctl start etcd.service

#systemctl enable etcd.service

四、配置etcd(改動標紅)

#vim /etc/etcd/etcd.conf

# [member]

ETCD_NAME=default

ETCD_DATA_DIR="/var/lib/etcd/default.etcd"

#ETCD_SNAPSHOT_COUNTER="10000"

#ETCD_HEARTBEAT_INTERVAL="100"

#ETCD_ELECTION_TIMEOUT="1000"

#ETCD_LISTEN_PEER_URLS=""

ETCD_LISTEN_CLIENT_URLS="http://192.168.122.196:2379"

#ETCD_MAX_SNAPSHOTS="5"

#ETCD_MAX_WALS="5"

#ETCD_CORS=""

#[cluster]

#ETCD_INITIAL_ADVERTISE_PEER_URLS=""

# if you use different ETCD_NAME (e.g. test), set ETCD_INITIAL_CLUSTER value for this name, i.e. "test="

#ETCD_INITIAL_CLUSTER="default="

#ETCD_INITIAL_CLUSTER_STATE="new"

#ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"

ETCD_ADVERTISE_CLIENT_URLS="http://192.168.122.196:2379"

#ETCD_DISCOVERY=""

#ETCD_DISCOVERY_SRV=""

#ETCD_DISCOVERY_FALLBACK="proxy"

#ETCD_DISCOVERY_PROXY=""

#[proxy]

#ETCD_PROXY="off"

#[security]

#ETCD_CERT_FILE=""

#ETCD_KEY_FILE=""

#ETCD_CLIENT_CERT_AUTH="false"

#ETCD_TRUSTED_CA_FILE=""

#ETCD_PEER_CERT_FILE=""

#ETCD_PEER_KEY_FILE=""

#ETCD_PEER_CLIENT_CERT_AUTH="false"

#ETCD_PEER_TRUSTED_CA_FILE=""

#[logging]

#ETCD_DEBUG="false"

# examples for -log-package-levels etcdserver=WARNING,security=DEBUG

五、kubernetes_master安裝kubernetes並升級

#yum install -y kubernetes

#wget 

#tar zxvf kubernetes.tar.gz

#cd kubernetes

#tar zxf kubernetes/server/kubernetes-server-linux-amd64.tar.gz

#cp kubernetes/server/kube* /usr/bin

六、配置kubernetes_master(改動標紅)

#vim /etc/kubernetes/config

# kubernetes system config

# The following values are used to configure various aspects of all

# kubernetes services, including

#   kube-apiserver.service

#   kube-controller-manager.service

#   kube-scheduler.service

#   kubelet.service

#   kube-proxy.service

# logging to stderr means we get it in the systemd journal

KUBE_LOGTOSTDERR="--logtostderr=true"

# journal message level, 0 is debug

KUBE_LOG_LEVEL="--v=0"

# Should this cluster be allowed to run privileged docker containers

KUBE_ALLOW_PRIV="--allow_privileged=false"

# How the controller-manager, scheduler, and proxy find the apiserver

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

#vim /etc/kubernetes/apiserver

# kubernetes system config

# The following values are used to configure the kube-apiserver

# The address on the local server to listen to.

KUBE_API_ADDRESS="--address=0.0.0.0"

# The port on the local server to listen on.

# KUBE_API_PORT="--port=8080"

# Port minions listen on

# KUBELET_PORT="--kubelet_port=10250"

# Comma separated list of nodes in the etcd cluster

KUBE_ETCD_SERVERS="--etcd_servers=http://192.168.122.196:2379"

# Address range to use for services

KUBE_SERVICE_ADDRESSES="--service-cluster-ip-range=10.254.0.0/16"

# default admission control policies

KUBE_ADMISSION_CONTROL="--admission_control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ServiceAccount,ResourceQuota"

# Add your own!

KUBE_API_ARGS=""

vim /etc/kubernetes/controller-manager

# The following values are used to configure the kubernetes controller-manager

KUBELET_ADDRESSES="--machines= 192.168.122.131"

# defaults from config and apiserver should be adequate

# Add your own!

KUBE_CONTROLLER_MANAGER_ARGS=""

七、啟動服務

#systemctl start kube-apiserver.service kube-controller-manager.service kube-scheduler.service

#systemctl enable kube-apiserver.service kube-controller-manager.service kube-scheduler.service

八、kubernetes_nodes安裝kubernetes和docker並升級

#yum install -y kubernetes docker

#wget 

#tar zxvf kubernetes.tar.gz

#cd kubernetes

#tar zxf kubernetes/server/kubernetes-server-linux-amd64.tar.gz

#cp kubernetes/server/kube* /usr/bin

九、配置kubernetes_nodes(改動標紅)

# kubernetes kubelet (minion) config

# The address for the info server to serve on (set to 0.0.0.0 or "" for all interfaces)

KUBELET_ADDRESS="--address=0.0.0.0"

# The port for the info server to serve on

KUBELET_PORT="--port=10250"

# You may leave this blank to use the actual hostname

KUBELET_HOSTNAME="--hostname_override=192.168.122.207"

# location of the api-server

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

# Add your own!

KUBELET_ARGS=""

十、啟動kubernetes_nodes服務

#systemctl enable docker.service kubelet.service kube-proxy.service

#systemctl start docker.service kubelet.service

十一、測試連通性

#kubecel version

Client Version: version.Info{Major:"1", Minor:"0", GitVersion:"v1.0.1", GitCommit:"6a5c06e3d1eb27a6310a09270e4a5fb1afa93e74", GitTreeState:"clean"}

Server Version: version.Info{Major:"1", Minor:"0", GitVersion:"v1.0.1", GitCommit:"6a5c06e3d1eb27a6310a09270e4a5fb1afa93e74", GitTreeState:"clean"}

(證明apiserver以啟動)

#kubectl get nodes

NAME          LABELS                        STATUS

192.168.122.207   kubernetes.io/hostname=192.168.122.207   Ready

(證明kubernetes_master和kubernetes_nodes連線成功)

十二、總結

   拜讀了很多大牛的博文終於把最新的kubernetes分散式架構起來,期間太多的坑不言而喻,希望同行小夥伴們看到此篇博文能有一些啟發,後面還會有kubernetes分散式管理docker容器博文和大家分享,已達到拋磚引玉的效果。希望大牛路過指點一二,不勝感激。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/18796236/viewspace-1841203/,如需轉載,請註明出處,否則將追究法律責任。

相關文章