预配置
vim /etc/hosts
10.253.6.147 master1
10.253.6.221 master2
10.253.6.64 master3
10.253.6.242 node1
10.253.6.156 node2
ssh-keygen
ssh-copy-id
hostnamectl set-hostname
vim /etc/fstab
swapoff -a
free -h
sysctl -w vm.swappiness=0
systemctl disable ufw
systemctl stop ufw
apt-get -y install ntp
# 配置忽略
# 更改apt源,忽略
tee /etc/modules-load.d/containerd.conf<<EOF
overlay
br_netfilter
EOF
modprobe overlay
modprobe br_netfilter
lsmod | egrep "br_netfilter|overlay"
tee /etc/sysctl.d/kubernetes.conf<<EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF
sysctl --system
apt-get -y install ipset ipvsadm
tee /etc/modules-load.d/ipvs.conf<<EOF
ip_vs
ip_vs_rr
ip_vs_wrr
ip_vs_sh
nf_conntrack
EOF
modprobe ip_vs
modprobe ip_vs_rr
modprobe ip_vs_wrr
modprobe nf_conntrack
lsmod | egrep "ip_vs|nf_conntrack"
安装containerd
使用软件源安装
apt-get -y install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
apt-get -y update
apt-cache madison containerd.io
apt-get -y install containerd.io
containerd config default > /etc/containerd/config.toml
vim /etc/containerd/config.toml
sandbox_image = "registry.aliyuncs.com/google_containers/pause:3.8"
SystemdCgroup = true
systemctl restart containerd.service
使用二进制安装
containerd
service
wget https://github.com/containerd/containerd/releases/download/v2.0.1/containerd-2.0.1-linux-amd64.tar.gz
tar -xf containerd-1.7.24-linux-amd64.tar.gz -C /
containerd config default > /etc/containerd/config.toml
vim /etc/containerd/config.toml
sandbox_image = "registry.aliyuncs.com/google_containers/pause:3.8"
SystemdCgroup = true
systemctl enable containerd.service --now
安装kubernetes组件
apt-get update && apt-get install -y apt-transport-https
curl -fsSL https://mirrors.aliyun.com/kubernetes-new/core/stable/v1.28/deb/Release.key |
gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
echo "deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://mirrors.aliyun.com/kubernetes-new/core/stable/v1.28/deb/ /" |
tee /etc/apt/sources.list.d/kubernetes.list
apt-get update
apt-get install -y kubelet kubeadm kubectl
kubernetes集群部署
vim /etc/default/kubelet
KUBELET_EXTRA_ARGS="--cgroup-driver=systemd"
systemctl enable kubelet.service
---------------以上在所有主机都需要操作,以下仅master-------------
kubeadm config print init-defaults > kubeadm-config.yml
vim kubeadm-config.yml
advertiseAddress: 填写集群master的ip,高可用填写虚拟ip
imageRepository: registry.cn-hangzhou.aliyuncs.com/google_containers
networking:
dnsDomain: cluster.local
serviceSubnet: 10.96.0.0/12
podSubnet: 10.244.0.0/16
kubeadm config images list --config=kubeadm-config.yml
kubeadm config images list --kubernetes-version=v1.30.2
kubeadm config images pull --config=kubeadm-config.yml
crictl images
kubeadm init --config kubeadm-config.yml --upload-certs --v 9
配置calico
calico
wget https://docs.projectcalico.org/manifests/calico.yaml
# 修改pod网段,kubeadm init时设置的
vim calico.yaml
- name: CALICO_IPV4POOL_CIDR
value: "10.244.0.0/16"
# 修改拉取镜像的地址
sed -i 's\docker.io\harbor.0ll1.com/hub\g' calico.yaml
kubectl apply -f calico.yaml
开启命令补全
echo "source <(kubectl completion bash)" > ~/.bashrc
source ~/.bashrc
节点优化
节点优化