Based on centos7
All hosts
Set up /etc/hosts
#Close swapoff
swapoff -a #temporary
sed -ri 's/.*swap.*/#&/' /etc/fstab #永久
#Turn off the firewall
systemctl stop firewalld systemctl disable firewalld
#Time synchronization
systemctl start chronyd.service
systemctl enable chronyd.service
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
#Close SELINUX
setenforce 0
sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
Install Docker via yum
# step 1: Install some necessary system tools
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
# Step 2: Add software source information
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
## Install the specified version of Docker-CE:
## Step 3.1: Find the version of Docker-CE:
## yum list docker-ce.x86_64 --showduplicates | sort -r
## Step 3.2: Install the specified version of Docker-CE
## yum -y --setopt=obsoletes=0 install docker-ce-[VERSION] docker-ce-selinux-[VERSION]
# Step 3: Update and install Docker-CE
yum -y install docker-ce-19.03 docker-ce-selinux
# Step 4: Turn on the Docker service#You can create the /etc/docker/daemon.json file
systemctl enable docker && systemctl start docker
Configure Alibaba Cloud image docker accelerator
cat << EOF > /etc/docker/daemon.json
{
"exec-opts": ["native.cgroupdriver=systemd"],
"registry-mirrors": ["https://0bb06s1q.mirror.aliyuncs.com"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2",
"storage-opts": ["overlay2.override_kernel_check=true"]
}
EOF
# Restart docker
systemctl daemon-reload && systemctl restart docker && systemctl enable docker.service
# 安装 bebeadm , kubectl , kubelet
Add yum source
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[governor]
name = Governors
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
install software
yum install -y kubelet-1.19.1 kubadm-1.19.1 kubectl-1.19.1
# Set kubelet to boot up
systemctl enable kubelet && systemctl start kubelet
Modify the k8s.conf file
cat <<EOF > /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system
echo "1" > /proc/sys/net/ipv4/ip_forward
All machines are initialized
Master installation and deployment
Export kubeadm cluster deployment customization file
kubeadm config print init-defaults > init.default.yaml
#Modify custom configuration file
Modify the following questions
- Primary node IP-advertiseAddress
- Domestic Ali mirroring address imageRepository——registry.aliyuncs.com/google_containers
- Pod network segment configuration-different network plug-in network segments are different, see details
#Pull Alibaba Cloud kubernetes container image
kubeadm config images list --config init.default.yaml kubeadm config images pull --config init.default.yaml
imageRepository: registry.aliyuncs.com/google_containers
#initialization
kubeadm init --config=init.default.yaml
#Configure user certificate (will be output after initialization above)
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
#Check the cluster status notready because the pod network is not installed.
kubectl get node
Install pod network-Calico
Different pod networks have different requirements for pod network segments, see the official website . The one I installed here is Calico.
kubectl apply -f https://docs.projectcalico.org/v3.11/manifests/calico.yaml
master completes the installation
node installation
Execute the view node join command in the master
kubeadm token create --print-join-command
According to the output information, execute the join command on the node node.
#Reset
kubeadm reset
rm -rf /etc/cni/net.d/
rm -rf /etc/kubernetes/
rm -rf ~ / .kube /
do Master installation and deployment
This installation version
docker version
Client: Docker Engine - Community
Version: 19.03.12
kubectl version
Client Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.1", GitCommit:"206bcadf021e76c27513500ca24182692aabd17e", GitTreeState:"clean", BuildDate:"2020-09-09T11:26:42Z", GoVersion:"go1.15", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.0", GitCommit:"e19964183377d0ec2052d1f1fa930c4d7575bd50", GitTreeState:"clean", BuildDate:"2020-08-26T14:23:04Z", GoVersion:"go1.15", Compiler:"gc", Platform:"linux/amd64"}