k8s1.30.0高可用集群部署

news/2024/11/26 2:48:07/

负载均衡

nginx负载均衡

两台nginx负载均衡
vim /etc/nginx/nginx.conf

stream {upstream kube-apiserver {server 192.168.0.11:6443     max_fails=3 fail_timeout=30s;#server 192.168.0.12:6443     max_fails=3 fail_timeout=30s;#server 192.168.0.13:6443     max_fails=3 fail_timeout=30s;}server {listen 6443;proxy_connect_timeout 2s;proxy_timeout 900s;proxy_pass kube-apiserver;}
}

keepalived

nginx检测脚本
vim /data/shell/check_nginx_status.sh

#!/bin/bash
nginx_status=$(ps -ef | grep nginx | grep -v grep | grep -v check | wc -l)if [ $nginx_status -eq 0 ];thensystemctl stop keepalived.service
fi

master节点keepalived配置(不抢占机制)
vim /etc/keepalived/keepalived.conf

global_defs {router_id real-server1}vrrp_script chk_nginx {script "/data/shell/check_nginx_status.sh"interval 2
}vrrp_instance VI_1 {state BACKUPinterface ens32virtual_router_id 151priority 100nopreemptadvert_int 5authentication {auth_type  PASSauth_pass  1111}virtual_ipaddress {192.168.0.10/24}track_script {                                                                                  chk_nginx}}

backup节点keepalived配置

vim /etc/keepalived/keepalived.conf

global_defs {router_id real-server2}vrrp_script chk_nginx {script "/data/shell/check_nginx_status.sh"interval 2
}vrrp_instance VI_1 {state BACKUPinterface ens32virtual_router_id 151priority 50nopreemptadvert_int 5authentication {auth_type  PASSauth_pass  1111}virtual_ipaddress {192.168.0.10/24}track_script {                                                                                  chk_nginx}}

k8s节点系统设置

vim /etc/modules-load.d/containerd.conf

overlay
br_netfilter
modprobe overlay
modprobe br_netfilter

vim /etc/sysctl.d/k8s.conf

net.bridge.bridge-nf-call-iptables=1
net.bridge.bridge-nf-call-ip6tables=1
net.ipv4.ip_forward=1
vm.swappiness=0
vm.overcommit_memory=1
vm.panic_on_oom=0
fs.inotify.max_user_instances=8192
fs.inotify.max_user_watches=1048576
fs.file-max=52706963
fs.nr_open=52706963
net.ipv6.conf.all.disable_ipv6=1
net.netfilter.nf_conntrack_max=2310720
sysctl --system

ipvsadm

yum install ipset ipvsadm
modprobe br_netfilter
modprobe overlay
modprobe ip_conntrack
modprobe  ip_vs
modprobe  ip_vs_rr
modprobe  ip_vs_wrr
modprobe  ip_vs_sh
modprobe  nf_conntrack
lsmod | grep conntrack
lsmod | grep br_netfilt
lsmod | grep overlay
lsmod |egrep  "ip_vs|nf_conntrack"
cat > /etc/modules-load.d/kubernetes.conf << EOF
# /etc/modules-load.d/kubernetes.conf
br_netfilter
ip_vs
ip_vs_rr
ip_vs_wrr
ip_vs_sh
nf_conntrack_ipv4
ip_tables
EOF
chmod a+x /etc/modules-load.d/kubernetes.conf

containerd

wget https://github.com/containerd/containerd/releases/download/v1.7.23/cri-containerd-cni-1.7.23-linux-amd64.tar.gztar xvf cri-containerd-cni-1.7.23-linux-amd64.tar.gz -C /wget https://github.com/opencontainers/runc/releases/download/v1.1.5/runc.amd64
cp runc.amd64 /usr/local/sbin/runc
mkdir -p /etc/containerd
containerd config default > /etc/containerd/config.toml

vim /etc/containerd/config.toml

...
SystemdCgroup = true
...
sandbox_image = "registry.cn-beijing.aliyuncs.com/wuxingge123/pause:3.9"
...[plugins."io.containerd.grpc.v1.cri".registry.mirrors][plugins."io.containerd.grpc.v1.cri".registry.mirrors."docker.io"]endpoint = ["https://p4oudlho.mirror.aliyuncs.com"]

配置私有仓库

[plugins."io.containerd.grpc.v1.cri".registry][plugins."io.containerd.grpc.v1.cri".registry.mirrors][plugins."io.containerd.grpc.v1.cri".registry.mirrors."docker.io"]endpoint = ["https://bqr1dr1n.mirror.aliyuncs.com"][plugins."io.containerd.grpc.v1.cri".registry.configs][plugins."io.containerd.grpc.v1.cri".registry.configs."harbor.k8s.local".tls]insecure_skip_verify = true[plugins."io.containerd.grpc.v1.cri".registry.configs."harbor.k8s.local".auth]username = "admin"password = "Harbor12345"

启动containerd

systemctl start containerd.service
systemctl enable containerd.service

k8s

安装

https://mirrors.aliyun.com/kubernetes-new/core/stable/v1.30/rpm/x86_64/

vim /etc/yum.repos.d/k8s.repo

[kubernetes]
name=kubernetes
baseurl=https://pkgs.k8s.io/core:/stable:/v1.30/rpm/
enabled=1
gpgcheck=0

在线安装

yum install kubelet-1.30.0 kubectl-1.30.0 kubeadm-1.30.0

离线安装

yum localinstall kubernetes-cni-1.4.0-150500.1.1.x86_64.rpm 
yum localinstall cri-tools-1.30.0-150500.1.1.x86_64.rpm
yum localinstall kubeadm-1.30.0-150500.1.1.x86_64.rpm kubectl-1.30.0-150500.1.1.x86_64.rpm kubelet-1.30.0-150500.1.1.x86_64.rpm

配置kubelet

vim /etc/sysconfig/kubelet

KUBELET_EXTRA_ARGS="--cgroup-driver=systemd"
systemctl enable kubelet

下载镜像

kubeadm config images list --kubernetes-version=v1.30.0 --image-repository registry.cn-beijing.aliyuncs.com/wuxingge123kubeadm config images pull --kubernetes-version=v1.30.0 --image-repository registry.cn-beijing.aliyuncs.com/wuxingge123

calico准备

wget https://docs.projectcalico.org/v3.25/manifests/calico.yaml --no-check-certificate

vim calico.yaml

            - name: CALICO_IPV4POOL_CIDRvalue: "10.224.0.0/16"

下载calico镜像

ctr -n k8s.io image pull --all-platforms registry.cn-beijing.aliyuncs.com/wuxingge123/cni:v3.25.0ctr -n k8s.io image pull --all-platforms registry.cn-beijing.aliyuncs.com/wuxingge123/node:v3.25.0ctr -n k8s.io image pull --all-platforms registry.cn-beijing.aliyuncs.com/wuxingge123/kube-controllers:v3.25.0

k8s init

生成初始化配置文件

kubeadm config print init-defaults > kubeadm-config.yaml

vim kubeadm-config.yaml

apiVersion: kubeadm.k8s.io/v1beta3
bootstrapTokens:
- groups:- system:bootstrappers:kubeadm:default-node-tokentoken: abcdef.0123456789abcdefttl: 24h0m0susages:- signing- authentication
kind: InitConfiguration
localAPIEndpoint:advertiseAddress: 192.168.0.11bindPort: 6443
nodeRegistration:criSocket: unix:///var/run/containerd/containerd.sockimagePullPolicy: IfNotPresenttaints: null
---
apiServer:timeoutForControlPlane: 4m0s
apiVersion: kubeadm.k8s.io/v1beta3
certificatesDir: /etc/kubernetes/pki
clusterName: kubernetes
controlPlaneEndpoint: 192.168.0.10:6443
controllerManager: {}
dns: {}
etcd:local:dataDir: /var/lib/etcd
imageRepository: swr.cn-jl-1.manageone.cloud.cnpc/gsms-project
kind: ClusterConfiguration
kubernetesVersion: 1.30.0
networking:dnsDomain: cluster.localpodSubnet: 10.224.0.0/16serviceSubnet: 10.96.0.0/12
scheduler: {}

初始化集群

kubeadm init --config kubeadm-config.yaml --upload-certs

初始化成功显示以下内容

Your Kubernetes control-plane has initialized successfully!To start using your cluster, you need to run the following as a regular user:mkdir -p $HOME/.kubesudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/configsudo chown $(id -u):$(id -g) $HOME/.kube/configAlternatively, if you are the root user, you can run:export KUBECONFIG=/etc/kubernetes/admin.confYou should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:https://kubernetes.io/docs/concepts/cluster-administration/addons/You can now join any number of the control-plane node running the following command on each as root:kubeadm join 192.168.0.10:6443 --token abcdef.0123456789abcdef \--discovery-token-ca-cert-hash sha256:aac70b668d8010aca7af9a27ad9451468fc985dfd8f52a52025d14b180e16464 \--control-plane --certificate-key 8ea5c7b87d52438496fce053b1e9788217ffe74ed397d89f6a114e65d06c8826Please note that the certificate-key gives access to cluster sensitive data, keep it secret!
As a safeguard, uploaded-certs will be deleted in two hours; If necessary, you can use
"kubeadm init phase upload-certs --upload-certs" to reload certs afterward.Then you can join any number of worker nodes by running the following on each as root:kubeadm join 192.168.0.10:6443 --token abcdef.0123456789abcdef \--discovery-token-ca-cert-hash sha256:aac70b668d8010aca7af9a27ad9451468fc985dfd8f52a52025d14b180e16464

配置kubectl客户端

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

设置kubectl命令补全

echo "source <(kubectl completion bash)" >> /etc/profile

部署calico

kubectl apply -f calico.yaml

添加master节点

  kubeadm join 192.168.0.10:6443 --token abcdef.0123456789abcdef \--discovery-token-ca-cert-hash sha256:aac70b668d8010aca7af9a27ad9451468fc985dfd8f52a52025d14b180e16464 \--control-plane --certificate-key 8ea5c7b87d52438496fce053b1e9788217ffe74ed397d89f6a114e65d06c8826

添加node节点

kubeadm join 192.168.0.10:6443 --token abcdef.0123456789abcdef \--discovery-token-ca-cert-hash sha256:aac70b668d8010aca7af9a27ad9451468fc985dfd8f52a52025d14b180e16464

ingress-nginx v1.11.2

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.11.2/deploy/static/provider/cloud/deploy.yaml

metrics-server

wget https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml

http://www.ppmy.cn/news/1549965.html

相关文章

如何在 .gitignore 中仅保留特定文件:以忽略文件夹中的所有文件为例

在日常的开发工作中&#xff0c;使用 Git 来管理项目是不可或缺的一部分。项目中的某些文件夹可能包含大量的临时文件、生成文件或不需要版本控制的文件。在这种情况下&#xff0c;我们通常会使用 .gitignore 文件来忽略这些文件夹。然而&#xff0c;有时我们可能希望在忽略整个…

PDF内容提取,MinerU使用

准备环境 # python 3.10 python3 -m pip install huggingface_hub python3 -m pip install modelscope python3 -m pip install -U magic-pdf[full] --extra-index-url https://wheels.myhloli.com下载需要的模型 import json import osimport requests from huggingface_hub…

力扣hot100-->栈/单调栈

栈/单调栈 1. 20. 有效的括号 简单 给定一个只包括 (&#xff0c;)&#xff0c;{&#xff0c;}&#xff0c;[&#xff0c;] 的字符串 s &#xff0c;判断字符串是否有效。 有效字符串需满足&#xff1a; 左括号必须用相同类型的右括号闭合。左括号必须以正确的顺序闭合。每…

nature communications论文 解读

题目《Transfer learning with graph neural networks for improved molecular property prediction in the multi-fidelity setting》 这篇文章主要讨论了如何在多保真数据环境&#xff08;multi-fidelity setting&#xff09;下&#xff0c;利用图神经网络&#xff08;GNNs&…

社团管理新体验:SpringBoot技术

摘要 随着信息技术在管理上越来越深入而广泛的应用&#xff0c;管理信息系统的实施在技术上已逐步成熟。本文介绍了社团管理系统的开发全过程。通过分析社团管理系统管理的不足&#xff0c;创建了一个计算机管理社团管理系统的方案。文章介绍了社团管理系统的系统分析部分&…

【Zookeeper】二、主从应用(master-worker架构)

以一张具有代表性的架构风格展开本篇论述 一般在这种架构中&#xff0c;主节点所负责的工作主要有 跟踪从节点状态分配任务到从节点&#xff0c;并跟踪任务的有效性&#xff08;任务是否正常执行完成&#xff09; 此时&#xff0c;我们需要关注三个问题 主节点崩溃 如果主节…

tcpdump抓取流量包详解

tcpdump 是 Linux 下强大的网络抓包工具&#xff0c;广泛用于网络诊断和分析。以下是对 tcpdump 的详细讲解&#xff0c;包括安装、使用方法和常见示例。 1. 基本概念 tcpdump 用于捕获和分析网络数据包&#xff0c;可以过滤并显示传输中的数据&#xff0c;支持协议、端口等多…

【JAVA】Java基础—面向对象编程:常用API与数据结构—集合框架(List、Set、Map等)

Java集合框架是Java编程语言中一个强大的工具集&#xff0c;它提供了数据结构的实现和操作方法&#xff0c;用于存储和处理对象。Java集合框架的核心接口包括List、Set和Map&#xff0c;它们为开发者提供了灵活而高效的数据管理方式。在日常开发中&#xff0c;集合框架的使用无…