Kubernetes集群部署文档

Kubernetes包提供了几个服务:kube-apiserver,kube-scheduler,kube-controller-manager,kubelet,kube-proxy。这些服务由systemd管理,配置文件位置:/etc/kubernetes。我们通过kubernetes实现跨主机。第一个主机,centos-master,将是Kubernetes管理。这个主机将运行kube-apiserver,kube-controller-manager和kube-scheduler,也将运行etcd。其余主机,centos-minion-n将是节点并运行kubelet,etcd,cadector和docker。

所有节点都运行flanneld作为网络覆盖。

准备环境:

准备三台centos7主机,请将主机IP替换为您的环境。

centos-master = 192.168.2.68

centos-minion = 192.168.2.78

禁用主节点和所有节点上的防火墙,因为docker与其他防火墙规则管理器不能很好地工作。CentOS不会让你禁用防火墙,只要SELinux强制,所以需要先禁用。

setenforce 0

vim /etc/selinux/config

SELINUX=disabled

systemctl disable iptables-services firewalld

systemctl stop iptables-services firewalld

官方配置centos的yum源为docker官方源,也可以不配置,使用默认的centos源

# vim/etc/yum.repos.d/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

配置主机名,也可以不配置,使用ip来管理

# vim /etc/hosts(所有主机上)

echo "192.168.2.68 centos-master

192.168.2.78 centos-minion" >> /etc/hosts

安装

所有的主机通过yum安装下列服务,如果使用centos源,请将红色部分去掉。其实一样,装出来都是1.4.0+1.12.5

# yum -y install--enablerepo=virt7-docker-common-releaseetcd flannel kubernetes(所有主机上)

# yum -y install etcd flannel kubernetes

配置

#vim /etc/kubernetes/config(所有节点)

# 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 replication controller and scheduler find the kube-apiserver

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

# vim /etc/etcd/etcd.conf(master)

# [member]

ETCD_NAME=default

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

ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379"

#[cluster]

ETCD_ADVERTISE_CLIENT_URLS="http://0.0.0.0:2379"

Default可以改掉dir也可以改会自动创建

# vim /etc/kubernetes/apiserver(master) 一定把多余的去掉,尤其是认证那块

# 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 kubelets listen on

KUBELET_PORT="--kubelet-port=10250"

# Comma separated list of nodes in the etcd cluster

KUBE_ETCD_SERVERS="--etcd-servers=http://centos-master:2379"

# Address range to use for services

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

# Add your own!

KUBE_API_ARGS=""

·警告此网络必须在网络基础设施中未使用!172.30.0.0/16在我们的网络是没有用过的

systemctl start etcd

etcdctl mkdir /kube-centos/network

etcdctl mk /kube-centos/network/config"{\"Network\":\"172.30.0.0/16\",\"SubnetLen\": 24,\"Backend\": {\"Type\":\"vxlan\"} }"

# vim/etc/sysconfig/flannel(master)

# Flanneld configuration options

# etcd url location.  Point this to the server where etcd runs

FLANNEL_ETCD_ENDPOINTS="http://centos-master:2379"

# etcd config key.  This is the configuration key that flannel queries

# For address range assignment

FLANNEL_ETCD_PREFIX="/kube-centos/network"

# Any additional options that you want to pass

#FLANNEL_OPTIONS=""

# vim/etc/kubernetes/kubelet(minion)

# The address for the info server to serve on

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

# Check the node number!

KUBELET_HOSTNAME="--hostname-override=centos-minion-n"

# Location of the api-server

KUBELET_API_SERVER="--api-servers=http://centos-master:8080"

# Add your own!

KUBELET_ARGS=""

# vim /etc/sysconf/flannel(minion)

# Flanneld configuration options

# etcd url location.  Point this to the server where etcd runs

FLANNEL_ETCD_ENDPOINTS="http://centos-master:2379"

# etcd config key.  This is the configuration key that flannel queries

# For address range assignment

FLANNEL_ETCD_PREFIX="/kube-centos/network"

# Any additional options that you want to pass

#FLANNEL_OPTIONS=""

master启动脚本

for SERVICES in etcd kube-apiserver kube-controller-manager kube-scheduler flanneld; do systemctl restart$SERVICESsystemctlenable$SERVICESsystemctl status$SERVICESdone

minion启动脚本

for SERVICES in kube-proxy kubelet flanneld docker; do

systemctl restart$SERVICES

systemctlenable$SERVICES

systemctl status$SERVICES

done

验证

$kubectl get nodes

NAME                   LABELS            STATUS

centos-minion                    Ready

你可能感兴趣的:(Kubernetes集群部署文档)