Kubernetes two installation methods-kubeadm installation

table of Contents

Introduction to kubeadm deployment method

Installation requirements

Ultimate goal

Organization

system initialization

Turn off the firewall

 Two close selinux

Three close swap

Four set the host name

Five add hosts to the master:

Sixth, the chain that passes bridged IPv4 traffic to iptables:

Seven time synchronization

8. Install Docker/kubeadm/bubelet on all nodes


Introduction to kubeadm deployment method

Kubeadm is a tool for rapid deployment of kubernetes clusters launched by the official community. This tool can complete the deployment of a Kubernetes cluster with two instructions:

First, create a Master node kubeadm init

Second, join the Node node to the current cluster $ kubeadm join <IP and port of the Master node>

 

Installation requirements

Before starting, the deployment of Kubernetes cluster machines needs to meet the following conditions, which are the prerequisites for deploying Kubernetes clusters, otherwise the installation cannot be successful.

1 One or more machines, operating system CentOS7.x-86_x64

2 Hardware configuration: 2GB or more RAM, 2 CPU or more CPU, hard disk 30GB or more

3 Network communication between all machines in the cluster

4 Can access the external network, need to pull the mirror

5 Prohibit swap partition

Ultimate goal

1 Install Docker and kubeadm on all nodes

2 Deploy Kubernetes Master

3 Deploy the container network plugin

4 Deploy Kubernetes Node and add the node to the Kubernetes cluster

Organization

 

In this case, three servers are required to deploy cluster kubernetes. Here I use virtual machine deployment. The corresponding roles of each virtual machine are as follows

k8s-master                   192.168.30.128

k8s-node1                    192.168.30.129

k8s-node2                    192.168.30.130

system initialization

Turn off the firewall

systemctl stop firewalld
systemctl disable firewalld

 Two close selinux

sed -i 's/enforcing/disabled/' /etc/selinux/config # 永久
setenforce 0

Three close swap

swapoff -a #临时
vim /etc/fstab  #永久  注释掉文件中swap行

Four set the host name

hostnamectl set-hostname xxx   # 不同虚拟机设置不同的主机名

Five add hosts to the master:

cat >> /etc/hosts << EOF 
192.168.30.128 k8s-master 
192.168.30.129 k8s-node1 
192.168.30.130 k8s-node2 
EOF

Sixth, the chain that passes bridged IPv4 traffic 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 # 生效

Seven time synchronization

yum install ntpdate -y
ntpdate time.windows.com

8. Install Docker/kubeadm/bubelet on all nodes

Kubernetes default CRI (container runtime) is Docker, so install Docker first.

  • 1 Install Docker
# step 1: 安装必要的一些系统工具
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
# Step 2: 添加软件源信息
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# Step 3: 更新并安装 Docker-CE
sudo yum makecache fast
sudo yum -y install docker-ce-18.06.1.ce-3.el7
# Step 4: 开启Docker服务
sudo service docker start
  • 2 Add Alibaba Cloud yum software source
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://gk0lyeuc.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
  • 3 Add kubernetes source
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

  • 4 Install kubeadm, kubelet and kubectl
yum install -y kubelet-1.16.0 kubeadm-1.16.0 kubectl-1.16.0
systemctl enable kubelet
  • 5 Deploy Kubernetes Master
kubeadm init --apiserver-advertise-address=192.168.30.128 --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

Since the default pull mirror address k8s.gcr.io cannot be accessed in China, specify the Alibaba Cloud mirror warehouse address here.

5.1 Use kubectl tool

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
  • Six install pod network plug-in
sudo kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
  • Seven join Kubernetes Node

At 192.168.30.129/130 (Node), add a new node to the cluster and execute the kubeadm join command output in kubeadm init:

kubeadm join 192.168.30.128:6443 --token esce21.q6hetwm8si29qxwn \ 
--discovery-token-ca-cert-hash sha256:00603a05805807501d7181c3d60b478788408cfe6cedefedb1f97569708be9c5
  • Eight test Kubernetes cluster

Create a pod in the Kubernetes cluster and verify that it is running normally:

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

Visit address: http://NodeIP:Port

As you can see, kubeadm has successfully built a cluster, and has created a pod node, and can access it normally.

 

Guess you like

Origin blog.csdn.net/Lixuanshengchao/article/details/109271298