k8s部署

1.kernel升级
升级到5.4.217

rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
yum --enablerepo=elrepo-kernel install kernel-lt -y
grub2-mkconfig
grub2-set-default 0

2.k8s安装


2.1 关闭交换分区
swapoff -a

sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab

2.2 安装kubelet kubeadm kubectl
准备repo

cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes

systemctl enable kubelet && systemctl start kubelet

 

2.3 转发 IPv4 并让 iptables 看到桥接流量
cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
overlay
br_netfilter
EOF

sudo modprobe overlay
sudo modprobe br_netfilter

# 设置所需的 sysctl 参数,参数在重新启动后保持不变

cat <<EOF > /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-arptables = 1
net.core.somaxconn = 32768
vm.swappiness = 0
net.ipv4.tcp_syncookies = 0
net.ipv4.ip_forward = 1
fs.file-max = 1000000
fs.inotify.max_user_watches = 1048576
fs.inotify.max_user_instances = 1024
net.ipv4.conf.all.rp_filter = 1
net.ipv4.neigh.default.gc_thresh1 = 80000
net.ipv4.neigh.default.gc_thresh2 = 90000
net.ipv4.neigh.default.gc_thresh3 = 100000
EOF

sysctl --system

# 应用 sysctl 参数而不重新启动
sudo sysctl --system

 

2.4 安装containerd


yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin

#生成默认配置文件并修改

containerd config default | tee /etc/containerd/config.toml

#修改config.toml

SystemdCgroup= true

sandbox_image = "registry.aliyuncs.com/google_containers/pause:3.6"

#重启服务

systemctl daemon-reload
systemctl restart crictl

cat >/etc/crictl.yaml<<EOF
runtime-endpoint: unix:///run/containerd/containerd.sock
EOF

#验证containerd是否配置正确

crictl pull nginx:1.15

 

3.kubeadm创建集群


3.1kubeadm集群初始化
#192.168.1.149 master节点执行

kubeadm init --apiserver-advertise-address=192.168.1.149 --kubernetes-version v1.25.2 --image-repository registry.aliyuncs.com/google_containers --service-cidr=10.11.0.0/16 --pod-network-cidr=10.22.0.0/16


3.2添加node节点
192.168.1.150
192.168.1.151
分别在150,151 节点执行
kubeadm join 192.168.1.149:6443 --token p7a3ok.jdl6wyan4dhc2sss --discovery-token-ca-cert-hash sha256:dae786d25a3997ed8dd9e20a261f390d5a71625c4970a644f112a6b70fc54380
kubeadm join 192.168.1.149:6443 --token p7a3ok.jdl6wyan4dhc2sss --discovery-token-ca-cert-hash sha256:dae786d25a3997ed8dd9e20a261f390d5a71625c4970a644f112a6b70fc54380


4.helm安装


wget https://get.helm.sh/helm-v3.4.1-linux-amd64.tar.gz
tar -xzvf helm-v3.4.1-linux-amd64.tar.gz
mv linux-amd64/helm /usr/local/bin/

 


5.k8s时区修改
helm repo add k8tz https://k8tz.github.io/k8tz/
helm install k8tz k8tz/k8tz --set timezone=Asia/Shanghai

6.安装网络插件calico


wget https://docs.projectcalico.org/manifests/calico.yaml

kubectl apply -f calico.yaml

 

posted @ 2022-10-12 11:23  东哥加油!!!  阅读(37)  评论(0编辑  收藏  举报