Kubernetes 集群部署

环境准备:

k8s cri-dockerd pod-network service-network
Ubuntu2004:10.0.0.66( master ) 1.24.3 0.2.5.3-0.ubuntu 192.168.0.0/16(calico) 10.96.0.0/12
Ubuntu2004:10.0.0.76(node1)   k8s-node1.yum.org
Ubuntu2004:10.0.0.86(node2)   k8s-node2.yum.org
Ubuntu2004:10.0.0.96 (node3)  k8s-node2.yum.org

配置主机名

hostnamectl set-hostname k8s-master1.yum.org

hostnamectl set-hostname k8s-node1.yum.org

hostnamectl set-hostname k8s-node2.yum.org

hostnamectl set-hostname k8s-node3.yum.org

初始化设置

关闭 swp,防火强,时间同步

swapoff -a

ufw disable

修改 host 文件

root@master01:~# cat /etc/hosts

127.0.0.1 localhost

127.0.1.1 ubuntu2004

10.0.0.66 master01.hga.org mastetr01 kubeapi.yum.org kubeapi

10.0.0.76 node01.yum.org

10.0.0.86 node02.yum.org

10.0.0.96 node03.yum.org

安装 docker-ce

apt -y install apt-transport-https ca-certificates curl software-properties-common

curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | apt-key add -

add-apt-repository "deb[arch=amd64]http://mirrors.aliyun.com/dockerce/linux/ubuntu

$(lsb_release -cs) stable"

apt -y instal docker-ce

添加 docke 代理

cat /usr/lib/systemd/system/docker.service

[Service]

Environment="HTTP_PROXY=socks5://10.0.0.1:1080"

Environment="HTTPS_PROXY=socks5://10.0.0.1:1080"

Environment="NO_PROXY=127.0.0.0/8,172.17.0.0/16"

systemctl daemon-reload && systemctl restart docker.service

安装 cri-dockerd

dpkg -i cri-dockerd_0.2.5.3-0.ubuntu-focal_amd64.deb

systemctl daemon-reload && systemctl restart cri-dockerd.service

安装 kubelet、kubeadm 和 kubectl

apt update && apt install -y apt-transport-https curl

curl -fsSL https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add

-

cat <<EOF >/etc/apt/sources.list.d/kubernetes.list

deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main

EOF

apt update && apt install -y kubelet kubeadm kubectl && systemctl enable kubelet

整合 kubelet 和 cri-dockerd

修改 service 文件

修改

vim /usr/lib/systemd/system/cri-docker.service

注释 #ExecStart=/usr/bin/cri-dockerd --container-runtime-endpoint fd://

添加

ExecStart=/usr/bin/cri-dockerd --container-runtime-endpoint fd:// --network[1]

plugin=cni --cni-bin-dir=/opt/cni/bin --cni-cache-dir=/var/lib/cni/cache --cni[1]

conf-dir=/etc/cni/net.d

systemctl daemon-reload && systemctl restart cri-docker.service

配置 kubelet

cat /etc/sysconfig/kubelet

KUBELET_KUBEADM_ARGS="--container-runtime=remote --container-runtime[1]

endpoint=/run/cri-dockerd.sock"

master 初始化

kubeadm init --control-plane-endpoint kubeapi.lxp.org --kubernetes-version=v1.24.3

--pod-network-cidr=192.168.0.0/16 --service-cidr=10.96.0.0/12 --token-ttl=0 --cri[1]

socket unix:///run/cri-dockerd.sock

mkdir -p $HOME/.kube

cp -i /etc/kubernetes/admin.conf $HOME/.kube/config

安装 calico

curl https://projectcalico.docs.tigera.io/manifests/calico.yaml -O

kubectl apply -f calico.yaml

node 节点加入

​
cat /etc/sysconfig/kubelet

KUBELET_KUBEADM_ARGS="--container-runtime=remote --container-runtime[1]

endpoint=/run/cri-dockerd.sock"

​

检验集群

root@master01:~# kubectl get nodes

NAME STATUS ROLES AGE VERSION

master01.yum.org Ready control-plane 4h49m v1.24.3

node01.yum.org Ready <none> 98m v1.24.3

node02.yum.org Ready <none> 101m v1.24.3

node03.yum.org Ready <none> 96m v1.24.3

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐