kubernetes-k8s basic concept and basic component deployment

1, k8s basic concepts

Official documents

1.1 why k8s?

Why is it called k8s? Because the kubernetes word is too long. The last 8 letters of K + the last s is called k8s for short

  • Open Source
  • Perfect ecology
  • Standard, specification, large factory endorsement
  • Mainstream & Trend

1.2 docker VS k8s

  • docker (stand-alone)
    • container (Runtime, process)
    • Image (image, consistency, distribution)
    • Registry (unified image management)
  • K8s (cluster)
    • Orchestration
    • Scheduler
    • Scale
    • Abstract (Abstract)

1.3 K8s core components

  • Database (etcd)
  • scheduler
  • Cluster portal (API Server)
  • Controller is the most important
  • Kube proxy

1.4 a simple architecture understanding of k8s

  • Node role (specific task node, container)
    • proxy (responsible for container network)
    • kubelet (responsible for container management)
    • docker (implementation of container function)
  • master role (cluster task scheduling control)
    • API Server (cluster portal)
    • Control Manager (controller, built-in controller to realize functions)
    • scheduler (scheduling, scheduling in nodes)
  • Database (etcd, k8s all information will be stored in the database)

2, Installation deployment

Official website: https://kubernetes.io/docs/home/

  • One or more machines, operating system
  • CentOS7.x-86_x64
  • Hardware configuration: 2GB or more RAM, 2 CPUs or more CPUs, hard disk 30GB or more
  • Network interworking between all machines in the cluster
  • You can access the Internet. You need to pull the image
  • Disable swap partition

2.1 objectives and environmental preparation

  1. Install Docker and kubedm on all nodes (centos7)
  2. Deploy Kubernetes Master
  3. Deploy container network plug-in
  4. Deploy the Kubernetes Node and add the node to the Kubernetes cluster
  5. Deploy the Dashboard Web page to visually view Kubernetes resources
Turn off the firewall:
$ systemctl stop firewalld
$ systemctl disable firewalld

close selinux: 
$ sed -i 's/enforcing/disable/' /etc/selinux/config  # permanent
$ setenforce 0  # temporary

close swap: 
$ swapoff -a  # temporary
$ vim /etc/fstab  # permanent
#/dev/mapper/centos-swap swap                    swap    defaults        0 0

Set host name:
$ hostnamectl set-hostname <hostname>

stay master add to hosts: 
$ cat >> /etc/hosts << EOF k8s-1-master k8s-2-node1 k8s-3-node2

To be bridged IPv4 Flow transfer to iptables Chain of:
$ cat > /etc/sysctl.d/k8s.conf << EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
$ sysctl --system  # take effect

Time synchronization:
$ yum install ntpdate -y
$ ntpdate time.windows.com

$ reboot

Install docker and configure acceleration source

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
cat > /etc/docker/daemon.json << EOF
  "registry-mirrors": ["https://b9pmyelo.mirror.aliyuncs.com"]
systemctl restart docker

2.2 introduction and installation of kubedm, kubelet and kubectl

kubeadm is a tool launched by the official community for rapid deployment of kubernetes clusters.
kubelet works on the node, and its main function is to monitor the usage status of the container
kubectl is mainly used to control the cluster manager

Install kubedm, kubelet and kubectl through alicloud image

cat > /etc/yum.repos.d/kubernetes.repo << EOF
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
yum install -y kubelet-1.17.0 kubeadm-1.17.0 kubectl-1.17.0
systemctl enable kubelet

2.3 initializing the control plane

  • Initialize the first node of the control plane
  • Configure administrator configuration for kubectl command
  • Deploy network plug-ins

Official documents

kubeadm init \
  --apiserver-advertise-address= \
  --image-repository registry.aliyuncs.com/google_containers \
  --kubernetes-version v1.17.0 \
  --service-cidr= \

Parameter analysis

  • – apiserver advertisement address: the ip address of other components. Generally, it should be the Master node, which is used for internal communication of the cluster. 0.0.0 means all available addresses on the node
  • – image repository: Specifies the image repository to use
  • – kubernetes version: the version number of the k8s component should be the same as the kubelet version number
  • – service CIDR: the network address range of the Server. The network address in CIDR format is by default
  • – pod network CIDR = address range of pod network, network address in CIDR format. flannel network plug-in defaults to / 16 and calico plug-in defaults to

Refer to official documents for other parameters

The installation is successful when you see this


kubeadm join --token u3oziq.0bzn0c2vtk54rcr6 \
    --discovery-token-ca-cert-hash sha256:afbb4facdd85627a1c6fc56ca11363f3bf5f96ba1c7de820444ecd352c36783f

After k8s the installation is completed, it does not start completely. You need to install a network plug-in to start completely

Installing the flannel network plug-in

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

In case of inaccessibility, download the image package on github, import, modify the kube-flannel.yml configuration file, and install locally


Restart docker, and k8s components will start automatically with docker

2.4 join the cluster and test

Run the token just generated on the node machine
If you encounter a slow availability of flannel, wait a little longer. If you really can't, download it and import the image for local installation

Create a pod and verify it

kubectl create deployment nginx --image=nginx
kubectl expose deployment nginx --port=80 --type=NodePort
kubectl get pod,svc

2.5 Dashboard management

Its namespace is created on it. If you want to see its pods, you need to specify this namespace to see it

Dashboard is not open to the public by default
Modify the yeam configuration file and add two configurations

kubectl apply -f recommended.yaml
kubectl get pods -n kubernetes-dashboard

Access address: http://NodeIP:30001

Enter thissunsafe

Create a service account and bind the default cluster admin administrator cluster role
Copy this token to the browser

kubectl create serviceaccount dashboard-admin -n kube-system
kubectl create clusterrolebinding dashboard-admin --clusterrole=cluster-admin --serviceaccount=kube-system:dashboard-admin
kubectl describe secrets -n kube-system $(kubectl -n kube-system get secret | awk '/dashboard-admin/{print $1}')



Here you can manage some storage volumes, nodes and simple monitoring at the same time

Some problems I encountered

  1. Memory too small
error execution phase preflight: [preflight] Some fatal errors occurred:
        [ERROR Mem]: the system RAM (972 MB) is less than the minimum 1700 MB
        [ERROR KubeletVersion]: the kubelet version is higher than the control plane version. This is not a supported version skew and may lead to a malfunctional cluster. Kubelet version: "1.22.1" Control plane version: "1.21.0"
  1. Open DNET Bridge
error execution phase preflight: [preflight] Some fatal errors occurred:
        [ERROR FileContent--proc-sys-net-bridge-bridge-nf-call-iptables]: /proc/sys/net/bridge/bridge-nf-call-iptables contents are not set to 1
[preflight] If you know what you are doing, you can make a check non-fatal with `--ignore-preflight-errors=...`


echo '1' > /proc/sys/net/bridge/bridge-nf-call-iptables
  1. Swap swap partition is not closed
 [ERROR Swap]: running with swap on is not supported. Please disable swap
[preflight] If you know what you are doing, you can make a check non-fatal with `--ignore-preflight-errors=...`


$ vim /etc/fstab
#/dev/mapper/centos-swap swap                    swap    defaults        0 0
  1. Alicloud k8s component image component error. Use docker pull to pull the image and then click tag to rename
error execution phase preflight: [preflight] Some fatal errors occurred:
        [ERROR ImagePull]: failed to pull image registry.aliyuncs.com/google_containers/coredns:v1.8.4: output: Error response from daemon: manifest for registry.aliyuncs.com/google_containers/coredns:v1.8.4 not found: manifest unknown: manifest unknown
, error: exit status 1


docker pull registry.aliyuncs.com/google_containers/coredns:1.8.4

docker tag registry.aliyuncs.com/google_containers/coredns:1.8.4 registry.aliyuncs.com/google_containers/coredns:v1.8.4
  1. If there is a problem and you need to reinstall k8s, you need to uninstall the k8s configuration file
kubeadm reset -f
modprobe -r ipip
rm -rf ~/.kube/
rm -rf /etc/kubernetes/
rm -rf /etc/systemd/system/kubelet.service.d
rm -rf /etc/systemd/system/kubelet.service
rm -rf /usr/bin/kube*
rm -rf /etc/cni
rm -rf /opt/cni
rm -rf /var/lib/etcd
rm -rf /var/etcd
yum clean all
yum remove kube*
  1. kubelet driver problem
kubelet cgroup driver: "systemd" is different from docker cgroup driver: "cgroupfs"

Try to modify

vim /etc/docker/daemon.json
"exec-opts": ["native.cgroupdriver=systemd"]

reference resources

Alibaba cloud developer community - Kubernetes - Shengdong
A Liang Education - Li Zhenliang
Margo Education
Quick Start to Kubernetes

Tags: Docker Kubernetes

Posted on Sat, 20 Nov 2021 04:11:58 -0500 by ztkirby