12. kubernetes Cluster Setup

Virtual Machine:
CentOS Linux release 7.3.1611 (Core)
3.10.0-514.el7.x86_64
1 Core 1G
docker1.13
Reference documents:
https://kubernetes.io/docs/getting-started-guides/centos/centos_manual_config/

IP: 192.168.101.201 master
IP: 192.168.101.202 node

Architecture and role of kube components:

I. Preparatory phase

Edit hosts files for all nodes
echo "192.168.101.201  docker-master
192.168.101.202  docker-node1" >> /etc/hosts
Establish yum Warehouse

echo "[virt7-docker-common-release]
name=virt7-docker-common-release
baseurl=http://cbs.centos.org/repos/virt7-docker-common-release/x86_64/os/
gpgcheck=0 
enabled=1" >/etc/yum.repos.d/virt7-docker-common-release.repo
install kubernetes etcd flannel
yum -y install --enablerepo=virt7-docker-common-release kubernetes etcd flannel
edit kubernetes Configuration files keep all nodes consistent
# 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://docker-master:8080"
Turn off the firewall of the primary and edge nodes. Turn off selinux before doing so, or centos will not allow you to turn off the firewall.At the same time, docker is incompatible with some other firewall rules.
setenforce 0
systemctl disable iptables-services firewalld
systemctl stop iptables-services firewalld

2. Primary Node Configuration

edit etcd configuration file 
# [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"

//Edit kube's api service
# The address on the local server to listen to.
KUBE_API_ADDRESS="--insecure-bind-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://docker-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=""

10.254.0.0/16Segments are created for service Time Allocated Address

**Start the corresponding service on the primary node**
for SERVICES in etcd kube-apiserver kube-controller-manager kube-scheduler docker; do
    systemctl restart $SERVICES
    systemctl enable $SERVICES
    systemctl status $SERVICES
done
//After starting, you will see the following processes: (Ignore process pid for pasting convenience only)
13093/etcd         
1913/master        
13182/kube-schedule
13127/kube-apiserve
13093/etcd         
13156/kube-controll
13127/kube-apiserve

3. Configure the Kubernetes service on the node.

edit/etc/kubernetes/kubelet

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

# Location of the api-server
KUBELET_API_SERVER="--api-servers=http://docker-master:8080"

# Add your own!
KUBELET_ARGS=""

//Start the appropriate service on the node (docker-node1)

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

//Configure kubectl (direct execution)
kubectl config set-cluster default-cluster --server=http://docker-master:8080
kubectl config set-context default-context --cluster=default-cluster --user=default-admin
kubectl config use-context default-context

IV. Verification

[root@origin ~]# kubectl get nodes
NAME           STATUS    AGE
docker-node1   Ready     7m

5. Solution of Container Communication Dependency (Network Bridge)

yum install unzip wget -y
wget https://github.com/jpetazzo/pipework/archive/master.zip
unzip pipework-master.zip
mv pipework-master pipework
cp -rp pipework/pipework /usr/local/bin/

Install bridge-utils, sub-plugins can assign fixed ip addresses to containers

Let docker use a fixed bridge

vim /etc/sysconfig/docker-network

# /etc/sysconfig/docker-network
DOCKER_NETWORK_OPTIONS="-b=br0"

Tags: Docker Kubernetes CentOS yum

Posted on Wed, 03 Jun 2020 12:13:47 -0400 by AaZmaN