kubernetes (k8s) cluster deployment documentation - official documentation

Kubernetes Cluster Deployment Documentation

 

Official website documentation: https://kubernetes.io/docs/getting-started-guides/centos/centos_manual_config/

 

The Kubernetes package provides several services: kube-apiserver, kube-scheduler, kube-controller-manager, kubelet, kube-proxy. These services are managed by systemd, configuration file location: /etc/kubernetes. We implement cross-host through kubernetes. The first host, centos-master, will be managed by Kubernetes. This host will run kube-apiserver, kube-controller-manager and kube-scheduler, and will also run etcd . The rest of the hosts, centos-minion-n will be the nodes and run kubelet, etcd, cadector and docker.

All nodes run flanneld as a network overlay.

 

Prepare the environment:

Prepare three centos7 hosts, please replace the host IP with your environment.

centos-master = 192.168.2.68

centos-minion = 192.168.2.78

 

Disable the firewall on the master node and all nodes because docker doesn't work well with other firewall rule managers. CentOS won't let you disable the firewall, as long as SELinux enforces it, so it needs to be disabled first.

setenforce 0

vim /etc/selinux/config

SELINUX=disabled

systemctl disable iptables-services firewalld

systemctl stop iptables-services firewalld

 

The yum source of the official configuration centos is the official source of docker, or it can not be configured, use the default centos source

# vim /etc/yum.repos.d/virt7-docker-common-release.repo (on all hosts)

[virt7-docker-common-release]

name=virt7-docker-common-release

baseurl=http://cbs.centos.org/repos/virt7-docker-common-release/x86_64/os/

gpgcheck=0

 

 

Configure the host name, or not configure it, use ip to manage

# vim /etc/hosts (on all hosts)

or

echo "192.168.2.68 centos-master

192.168.2.78 centos-minion" >> /etc/hosts

 

Install

All hosts install the following services through yum. If you use the centos source, please remove the red part. In fact, it's the same, it's all 1.4.0+1.12.5

# yum -y install --enablerepo=virt7-docker-common-release etcd flannel kubernetes (on all hosts)

# yum -y install etcd flannel kubernetes

configure

#vim /etc/kubernetes/config (all nodes)

# 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=""

 

<!--[if !supportLists]-->·         <!--[endif]-->警告此网络必须在网络基础设施中未使用!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/sysconfig/flanneld(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 $SERVICES systemctl enable$SERVICES systemctl status $SERVICES done

 

 

minion启动脚本

for SERVICES in kube-proxy kubelet flanneld docker; do

    systemctl restart $SERVICES

    systemctl enable$SERVICES

    systemctl status $SERVICES

done

 

 

验证

$ kubectl get nodes
NAME                   LABELS            STATUS
centos-minion        <none>            Ready

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326631435&siteId=291194637