头图

Prepare the local working environment

System Initialization

  • Turn off firewall
    # temporarily
    systemctl stop firewalld
    # permanently
    systemctl disable firewalld
  • Turn off selinux
    # temporarily
    sed -i 's/enforcing/disabled/' /etc/selinux/config
    # permanently
    setenforce 0
  • Turn off swap
    # temporarily
    swapoff -a
    # permanently (add hash (#) to the beginning of the swap partition line)
    vim /etc/fstab
  • Configure hostname
    hostnamectl set-hostname [hostname]
  • Configure static IP
    vi /etc/sysconfig/network-scripts/ifcfg-ens32

    BOOTPROTO="static"
    IPADDR=192.168.8.20
    PREFIX0=24
    GATEWAY=192.168.8.2
    DNS1=114.114.114.114
    DNS2=8.8.8.8
  • Add information of hosts (executed only on master node)

    cat >> /etc/hosts << EOF
    192.168.8.20 master01
    192.168.8.21 worker01
    192.168.8.22 worker02
    EOF
  • IPv4 transist to iptables

    cat > /etc/sysctl.d/k8s.conf << EOF
    net.bridge.bridge-nf-call-ip6tables = 1
    net.bridge.bridge-nf-call-iptables = 1
    EOF
    sysctl --system
  • Synchronize time across cluster nodes
    yum install ntpdate -y
    ntpdate time.windows.com

Software Installation

Docker

wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo

yum -y install docker-ce-18.06.1.ce-3.el7

systemctl enable docker && systemctl start docker

docker --version

Configure Yum Repository

Set the location of Repository

cat > /etc/docker/daemon.json << EOF
{
"registry-mirrors": ["https://b9pmyelo.mirror.aliyuncs.com"]
}
EOF
systemctl restart docker

Add the Repository

cat > /etc/yum.repos.d/kubernetes.repo << EOF
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF

Kubeadm & Kubelet & kubectl

yum install -y kubelet-1.18.0 kubeadm-1.18.0 kubectl-1.18.0

systemctl enable kubelet

Depolyment of Master Node

# Exceuted only on master node

kubeadm init \
--apiserver-advertise-address=192.168.8.20 \
--image-repository registry.aliyuncs.com/google_containers \
--kubernetes-version v1.18.0 \
--service-cidr=10.96.0.0/12 \
--pod-network-cidr=10.244.0.0/16
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
kubectl get nodes

image.png

  • Executed on the worker nodes:

    kubeadm join 192.168.8.20:6443 --token 4ephdf.8hz8xetf59ypi1tq \
      --discovery-token-ca-cert-hash sha256:a85072062388460e112209b012a67afd5f857781624c4ddfe25e3b406790270c

    image.png

    The expire duration of token is 24 hours, to regenerate a token:

    kubeadm token create --print-join-command

    Then check the worker nodes on master
    image.png

Depoly CNI plugin

kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

kubectl get pods -n kube-system

image.png

image.png

Test Kubernetes Cluster

kubectl create deployment nginx --image=nginx

kubectl get pod

image.png

kubectl expose deployment nginx --port=80 --type=NodePort

kubectl get pod,svc

image.png

image.png

Can be accessed from worker nodes