K8S集群搭建高可用prometheus+grafana

使用k3s来搭建测试环境。

为什么使用k3s

K3s 是一个轻量级的、完全兼容的 Kubernetes 发行版本。非常适合测试。

K3s将所有 Kubernetes 控制平面组件都封装在单个二进制文件和进程中,文件大小<100M,占用资源更小,且包含了kubernetes运行所需要的部分外部依赖和本地存储提供程序。

K3s提供了离线安装包,安装起来非常方便,可以避免安装过程中遇到各种网络资源访问问题。

安装k3s

1.准备工作

systemctl disable firewalld --now

2.使用官方脚本在线安装集群

#master
curl -sfL https://get.k3s.io | sh -
#在master节点上获取集群token
cat /var/lib/rancher/k3s/server/node-token

#在agent节点使用token部署工作节点
curl -sfL https://get.k3s.io | K3S_URL=https://master:6443 K3S_TOKEN=XXX sh -

3.在master节点查看集群状态

root@master:~# kubectl get nodes
NAME     STATUS   ROLES                  AGE   VERSION
master   Ready    control-plane,master   14d   v1.25.3+k3s1
agent    Ready    <none>                 14d   v1.25.3+k3s1

部署prometheus+grafana

使用github的kube-prometheus项目快速部署

git clone https://github.com/prometheus-operator/kube-prometheus.git -p release-0.11

cd kube-promethues

kubectl apply --server-side -f manifests/setup

kubectl wait \
	--for condition=Established \
	--all CustomResourceDefinition \
	--namespace=monitoring
kubectl apply -f manifests/

此时,k3s集群开始拉去镜像,并自动部署高可用prometheus集群。

#查看prometheus集群的构建状态
kubectl get all -n monitoring
kubectl get pod -n monitoring

#如果发现有不能拉取的镜像,或者构建失败的pod,通过describe查看具体信息。
kubectl describe pod kube-state-metrics-XXX -n monitoring
#找到对应的镜像名,到dockerhub上找相同的拉取。

最后,通过修改service.yml的方式,使集群的端口以NodePort的方式暴露出来。

K8S集群搭建高可用prometheus+grafana
K8S集群搭建高可用prometheus+grafana

修改完成后,一定要重新部署service,使修改生效

kubectl apply -f grafana-service.yaml -n monitoring

查看NodePort并访问

kubectl get svc -n monitoring
K8S集群搭建高可用prometheus+grafana

通过集群里任意IP:PORT进行web页面的访问

K8S集群搭建高可用prometheus+grafana

文章来源:https://www.cnaaa.net,转载请注明出处:https://www.cnaaa.net/archives/6185

(0)
李逍遥的头像李逍遥
上一篇 2022年11月21日 下午4:43
下一篇 2022年11月22日 下午5:30

相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

在线咨询: QQ交谈

邮件:712342017@qq.com

工作时间:周一至周五,8:30-17:30,节假日休息

关注微信
K8S集群搭建高可用prometheus+grafana