kubeadm:是一个安装工具,方便快捷的安装K8S系统。
一、安装前准备
sed -i 's/https:\/\/mirrors.aliyun.com/http:\/\/mirrors.cloud.aliyuncs.com/g' /etc/apt/sources.list
1.安装containerd
apt update apt install containerd -y vim /lib/systemd/system/containerd.service
containerd --help
containerd config default 配置文件 mkdir /etc/containerd/ ## 存放containerd的配置文件 #配置containerd containerd config default > /etc/containerd/config.toml vim /etc/containerd/config.toml
修改pause镜像地址: sandbox_image = "registry.aliyuncs.com/google_containers/pause:3.9" #阿里镜像地址
#修改镜像加速 218 endpoint = "https://n8lnq9bb.mirror.aliyuncs.com"
#修改为true SystemdCgroup = true
systemctl restart containerd.service
4.安装crictl工具
#安装 mkdir /usr/local/bin/crictl tar xvf crictl-v1.29.0-linux-amd64.tar.gz -C /usr/local/bin/crictl
vim /etc/profile export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/local/bin/crictl
source /etc/profile
crictl -v
#配置crictl cat > /etc/crictl.yaml <<EOF runtime-endpoint: "unix:///run/containerd/containerd.sock" image-endpoint: "unix:///run/containerd/containerd.sock" timeout: 10 debug: false EOF
5.安装nerdctl工具
#安装 tar xvf nerdctl-1.7.6-linux-amd64.tar.gz -C /usr/local/bin/
#检查命令是否正确 nerdctl version
#配置nerdctl mkdir /etc/nerdctl cat > /etc/nerdctl/nerdctl.toml <<EOF namespace = "k8s.io" debug = false debug_full = false insecure_registry = true EOF
6.CNI工具(为容器提供网桥)
为容器提供网桥,如果不安装CNI,容器只有host网络模式。
#安装CNI: mkdir -p /opt/cni/bin tar xvf cni-plugins-linux-amd64-v1.5.1.tgz -C /opt/cni/bin/
7.初始化K8S环境
安装基本的软件
apt install chrony ipvsadm tree ipset -y
关闭防火墙和关闭selinux
systemctl stop ufw
关闭swap ,交换分区
swapoff -a sed -i '/swap.img/s/^/#/' /etc/fstab
配置时间服务器
sed -i 's/pool ntp.ubuntu.com/pool 时间服务器地址/' /etc/chrony/chrony.conf systemctl restart chronyd
加载模块ip_vs(网络转发)
modprobe br_netfilter && lsmod |grep br_netfilter modprobe ip_conntrack && lsmod | grep conntrack cat >/etc/modules-load.d/modules.conf<<EOF ip_vs ip_vs_lc ip_vs_lblc ip_vs_lblcr ip_vs_rr ip_vs_wrr ip_vs_sh ip_vs_dh ip_vs_fo ip_vs_nq ip_vs_sed ip_vs_ftp ip_vs_sh ip_tables ip_set ipt_set ipt_rpfilter ipt_REJECT ipip xt_set br_netfilter nf_conntrack overlay EOF systemctl restart systemd-modules-load.service lsmod | grep -e ip_vs -e nf_conntrack
修改内核参数
vim /etc/sysctl.conf net.ipv4.ip_forward=1 vm.max_map_count=262144 kernel.pid_max=4194303 fs.file-max=1000000 net.ipv4.tcp_max_tw_buckets=6000 net.netfilter.nf_conntrack_max=2097152 net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 vm.swappiness=0 sysctl -p
修改machin-id
cat /etc/machine-id rm -f /etc/machine-id systemd-machine-id-setup
二、正式安装K8S-kubeadm方式
1.配置说明
2.安装 kubeadm 、kubelet、 kubectl
apt update apt install apt-transport-https ca-certificates curl gpg -y mkdir -p -m 755 /etc/apt/keyrings curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.30/deb/Release.key | sudo 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.30/deb/ /" | tee /etc/apt/sources.list.d/kubernetes.list ## 安装命令 apt-get update && apt-cache madison kubeadm apt-get install -y kubelet=1.30.3-1.1 kubeadm=1.30.3-1.1 kubectl=1.30.3-1.1
3. 创建MASTER
kubeadm init --apiserver-advertise-address=192.168.100.204 --apiserver-bind-port=6443 --kubernetes-version=v1.30.3 --pod-network-cidr=10.200.0.0/16 --service-cidr=10.96.0.0/16 --service-dns-domain=cluster.local --image-repository registry.aliyuncs.com/google_containers --ignore-preflight-errors=swap
--apiserver-advertise-address=192.168.100.204 #master地址
--pod-network-cidr=10.200.0.0/16 #pod地址
--service-cidr=10.96.0.0/16 #service地址
4.节点加入集群
kubeadm join 192.168.100.204:6443 --token 7zvr54.1hm6zba05b0hl0ge \ --discovery-token-ca-cert-hash sha256:2622b32f65c3778de1a52d76ad3a545d677b81411b6a4820575282805d26a951
5. 查看集群节点
kubectl get nodes
标签:bin,Kubernetes,部署,containerd,apt,etc,usr,--,kubeadm From: https://www.cnblogs.com/hxqwe/p/18366538