K8s cluster deployment (kubeadm installation and deployment detailed manual)

 1 Introduction

There are two main ways to deploy K8s:

  • 1、Cube admin

  Kubeadm is a K8s deployment tool that provides kubeadm init and kubeadm join for rapid deployment of Kubernetes clusters.

  • 2. Binary

   Download the distribution's binary package from github, and manually deploy each component to form a Kubernetes cluster.

This article installs a kubernetes cluster on centos7 through kudeadm.

2. Environment preparation

(1) Initial configuration

# close the firewall
systemctl stop firewalld
systemctl disable firewalld
# close selinux
sed -i 's/enforcing/disabled/' /etc/selinux/config 

# close swap

Comment out the swap under /etc/fstab.

1

sed -ri 's/.*swap.*/#&/' /etc/fstab

#Set the hostname

hostnamectl set-hostname k8s-node
hostnamectl set-hostname k8s-master

#Add hosts in master

cat > /etc/hosts << EOF
192.168.44.137 k8s-node
192.168.44.138 k8s-master
EOF

#Pass bridged IPV4 traffic to the chain of 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

# time synchronization

yum install ntpdate -y
ntpdate time.windows.com

(2) Install Docker

wget http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo
yum -y install docker-ce
systemctl enable docker && systemctl start docker

#Configure mirror accelerator

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://kd88kykb.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

(3) Add Alibaba Cloud yum software 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.19.0 kubeadm-1.19.0 kubectl-1.19.0
 systemctl enable kubelet

3. Deploy Kubernetes Master

1

2

3

4

5

6

kubeadm init \<br>--apiserver-advertise-address=192.168.44.138 \

--image-repository=registry.aliyuncs.com/google_containers \

--kubernetes-version=v1.19.0 \

--service-cidr=10.96.0.0/12 \

--pod-network-cidr=10.244.0.0/16 \

--ignore-preflight-errors=all

Successful installation:

Use kubectl to view node status

4. Deploy the Node node

To add a new node to the cluster, execute the kubeadm join command.

kubeadm join 192.168.44.138:6443 --token 1g5b2s.sany5uo5w4op3hae \
    --discovery-token-ca-cert-hash sha256:0fc38e874b727a9a4c2118e562a0b941dde98fa6ecc4ec2a6161b7d70a3966e2 

journalctl -u kubelet 

5. Deploy container network (CNI)

Find the calico corresponding to the k8s version

https://projectcalico.docs.tigera.io/archive/v3.20/getting-started/kubernetes/requirements

1

2

3

#Download calico.yaml, replace CALICO_IPV4POOL_CIDR<br>curl https://raw.githubusercontent.com/projectcalico/calico/v3.25.0/manifests/calico-etcd.yaml -o calico.yaml<br> calico.yaml<br>

kubectl apply -f calico.yaml

kubectl get pods -n kube-system

6. Test the kubernetes cluster

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

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

http://192.168.44.138:31819/

http://192.168.44.137:31819/

7. Deploy Dashboard

Download and add  type: NodePort

https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.3/aio/deploy/recommended.yaml

kubectl apply -f recommended.yaml
kubectl get pod,svc -n kubernetes-dashboard

Browser access:

 Create a service account and bind the default cluster-admin administrator cluster role:

1

2

3

4

5

6

#创建用户

kubectl create serviceaccount dashboard-admin -n kube-system

#用户授权

kubectl create clusterrolebinding dashboard-admin --clusterrole=cluster-admin --serviceaccount=kube-system:dashboard-admin

#获取用户token

kubectl describe  secret -n kube-system $(kubectl -n kube-system get secret|awk '/dashboard-admin/{print $1}')

Use the token to log in to the dashboard.

Reprinted in:  https://www.cnblogs.com/xiaozi/p/17110071.html

Guess you like

Origin blog.csdn.net/jiaqijiaqi666/article/details/129745828