kubeadm安装k8s v1.21.5

1、一个Master,一个worker

a、以下是所有节点都需操作

#关闭swap
sudo swapoff -a
#安装docker
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install -y docker-ce
sudo systemctl enable docker
sudo systemctl start docker

sudo cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes Repo
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=0
repo_gpgcheck=0
EOF
sudo setenforce 0
sudo yum install -y kubelet-1.21.5 kubeadm-1.21.5 kubectl-1.21.5
sudo systemctl enable kubelet
sudo systemctl start kubelet

没网的话,把镜像都提前拷过来

# 查看有哪些镜像
kubeadm config images list
# 两台机器都把镜像导上

b、在主节点

cat <<EOF > kubeadm-config.yaml 
---
apiVersion: kubeadm.k8s.io/v1beta2
kind: ClusterConfiguration
kubernetesVersion: v1.21.5
imageRepository: registry.aliyuncs.com/google_containers # image的仓库源
networking:
  podSubnet: "10.244.0.0/16"
EOF
sudo kubeadm init --config=kubeadm-config.yaml --v=5

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

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

c、worker节点

最后,在worker节点上,执行之前记下的kubeadm join命令,将worker节点加入到Kubernetes集群中:

sudo kubeadm join masterIP:6443 --token xxxxx --discovery-token-ca-cert-hash sha256:yyyyy

你可能感兴趣的:(k8s,kubernetes,容器,云原生)