惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
WordPress大学
WordPress大学
云风的 BLOG
云风的 BLOG
Stack Overflow Blog
Stack Overflow Blog
MongoDB | Blog
MongoDB | Blog
腾讯CDC
V
V2EX
Martin Fowler
Martin Fowler
A
About on SuperTechFans
大猫的无限游戏
大猫的无限游戏
Blog — PlanetScale
Blog — PlanetScale
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
酷 壳 – CoolShell
酷 壳 – CoolShell
C
Check Point Blog
博客园 - 【当耐特】
Cisco Talos Blog
Cisco Talos Blog
The Hacker News
The Hacker News
K
Kaspersky official blog
Security Latest
Security Latest
H
Help Net Security
博客园_首页
美团技术团队
Spread Privacy
Spread Privacy
博客园 - 司徒正美
Hugging Face - Blog
Hugging Face - Blog
S
SegmentFault 最新的问题
G
Google Developers Blog
NISL@THU
NISL@THU
爱范儿
爱范儿
I
Intezer
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
阮一峰的网络日志
阮一峰的网络日志
N
News and Events Feed by Topic
P
Privacy International News Feed
Application and Cybersecurity Blog
Application and Cybersecurity Blog
S
Security @ Cisco Blogs
Schneier on Security
Schneier on Security
雷峰网
雷峰网
人人都是产品经理
人人都是产品经理
V
Vulnerabilities – Threatpost
W
WeLiveSecurity
P
Palo Alto Networks Blog
G
GRAHAM CLULEY
Hacker News: Ask HN
Hacker News: Ask HN
I
InfoQ
The Cloudflare Blog
F
Full Disclosure
SecWiki News
SecWiki News
宝玉的分享
宝玉的分享
N
Netflix TechBlog - Medium

陈少文的网站

巨变与机遇的未来十年 Kubernetes 平台管理软件压力测试方案 使用镜像部署 Hexo 静态页面 终于等到你 - GitHub 镜像仓库服务(ghcr.io) 一起来学 Go --(6)Interface 一起来学 Go --(5)Goroutine 和 Channel 什么是函数式编程 如何在 Kubernetes 集群集成 Kata 柯里化与偏函数 使用 PyGithub 自动创建 Label 软件产品是团队能力的输出 Helm 2 、Helm 3 比较 IoT 变现 Kubernetes 中的 DNS 服务 国内的 Helm 镜像源 Harbor 使用自签证书支持 Https 访问 DevOps 工具链之 Prow 如何使用 kfctl 安装 Kubeflow VS Code 无法下载 Go 插件的工具包 工程师更应具有服务精神 你不知道的 Docker 使用技巧 使用 Docker 运行 Tensorflow 论中国 什么是左移 如何清空 Git 仓库全部历史记录 一禅小和尚 有风吹过厨房 时间的玫瑰 如何在 CentOS 安装 GPU 驱动 开发 Tips(19) 使用 Velero 备份 Kubernetes 集群 Kubernetes Cheat Sheet 开发 Tips(18) 如何构建一个 Java 工程 开发 Tips(17) KubeSpray 安装 Kubernetes 报错 ip in ansible_all_ipv4_addresses 基于 Kubernetes 和 Jenkins 搭建自动化测试系统 在 Kubernetes 上动态创建 Jenkins Slave 使用 Jenkins 进行服务拨测 开发 Tips(16) Kubernetes 签发 Ingress 证书及日常故障运维 Kubernetes 中 Deployment 的基本操作 Kubernetes 中的证书 如何使用 KubeBuilder 开发一个 Operator Kubernetes 1.6.0 安装问题汇总 镜像管理工具 -- Harbor 开发 Tips(15) Docker 如何拉取镜像 开发 Tips(14) 使用 Helm 安装 harbor 开发 Tips(13) 使用 S2I 构建云原生应用 在 Kubernetes 中使用 emptyDir、hostPath、localVolume 开发 Tips(12) 开发 Tips(11) 代码质量分析工具 SonarQube 使用 Kubeadm 安装 Kubernetes 集群 一起来学 Go --(4)常用函数 Kubernetes 中的 Ceph Kubernetes 之 Volumes Kubernetes 之 Labels、Selectors 开发 Tips(10) 开源正在重构商业模式 Kubernetes 之网络 Kubernetes 之 API 使用 Helm 和 Operator 快速部署 Prometheus Kubernetes 复杂有状态应用管理框架 -- Operator Kubernetes 的包管理器 -- Helm 一起来学 Go --(3)Go Modules 如何一步一步地优化博客方案 kubectl 实用指南 Kubernetes 中的基本概念 搭建远程 Kubernetes 开发环境 大公司和小公司的 ToB 思路 开发 Tips(9) Go 入门指南 一起来学 Go --(2)数据与逻辑结构 如何预防 Web 富文本中的 XSS 攻击 django-xss-cleaner 云工作时代 一起来学 Go --(1)背景与特点 SaaS 开发团队的不同阶段 你不知道的 Git 使用技巧 输出既服务 微服务设计 继续奔跑 开发 Tips(8) 从账户安全到二次验证 Django 性能之数据库查询优化 Django 性能之分库分表 敏捷开发之研发流程 打造一致性的团队 开发 Tips(7) Pytest 进阶学习之 Mock PaaS 部署之 buildpack Go 开发配置 领域输出才是 PaaS 的核心竞争力 Pytest 入门学习 开发 Tips(6) 如何使用 Jenkins、Docker、GitLab 搭建 Django 自动化部署流程
使用 Ops 项目查看并监控集群事件
微信公众号 · 2024-12-11 · via 陈少文的网站

Please enable Javascript to view the contents

https://github.com/shaowenchen/ops

1. 告警 Kubernetes 集群的事件

  • 监控指定的关键字
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
apiVersion: crd.chenshaowen.com/v1
kind: EventHooks
metadata:
  name: kube-pod-falid
  namespace: ops-system
spec:
  type: xiezuo
  url: https://xxx.com/api/v1/webhook/send?key=xxx
  subject: "ops.clusters.*.namespaces.*.pods.*.event"
  keywords:
    - failed

一份简单的配置,即可收获大量的相关告警。

  • 监控之后,自动化处理
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
apiVersion: crd.chenshaowen.com/v1
kind: EventHooks
metadata:
  name: kube-no-free-node
  namespace: ops-system
spec:
  additional: "action: restart-kubelet-bypod"
  keywords:
    - no free node
  subject: ops.clusters.*.namespaces.*.pods.*.event
  type: webhook
  url: http://x.x.x.x/webhook

借助 Ops Copilot 的执行能力,只需要将相关的告警添加 Action 然后抛给 Copilot,即可实现自动化处理。

上图就是为了解决某种异常情况下,自动重启节点的 Kubelet 以恢复节点的可用性。

2. 使用 Ops 观测事件

在 Ops 项目的 Server 中,集成有一个 UI 端,可以查看所有的事件。

支持三种形式的事件查询:

  • 直接查询
1
ops.clusters.mycluster.namespaces.ai-translate.pods.ciba-translate-ec--long-v1-74b88d9f74-9zpv7.event
  • 通配符
1
ops.clusters.mycluster.namespaces.ops-system.taskruns.alert-npu-drop.reports.*

reports 是 Ops 巡检主动上报的事件,是自动采集集群事件之外的另一个大的分类。

  • 前缀匹配
1
ops.clusters.*.namespaces.ops-system.hosts.>

这里定义一个事件对象的概念: 一组相关联的事件序列描述的对象,比如一个 Pod,一个节点,一个应用,一个人的操作等。

在 Nats 中主要是通过 Subjects 来区分不同事件,Nats 支持最多 16 个 domain,256 字符长度。

因此,在 Ops 中一个事件对象与一个 Subject 对应,并通过 Restful 风格的 Subject 名。

1
ops.clusters.{cluster}.namespaces.{namespace}.pods.{pod}.event

3. 如何安装和使用 Ops 的事件能力

https://www.chenshaowen.com/ops/zh/opscontroller.html 提供有详细的安装文档。

  • 添加 Helm 仓库
1
helm repo add ops https://www.chenshaowen.com/ops/charts
  • 安装 ops-controller-manager
1
helm install myops ops/ops --version 2.0.0 --namespace ops-system --create-namespace

安装 2.0.0 版本的 Ops,需要注意的是 2.0.0 版本是下一个 Release 版本,目前还在开发中。

  • 查看安装结果
1
kubectl get pods -n ops-system

4. 关于通知支持的通知类型

目前仅支持了两种:

  • xiezuo
  • webhook

当然,各种通知类型加起来很快,可以给我提交 https://github.com/shaowenchen/ops/issues 。如果测试条件满足,当天就能发布。

添加新的通知类型,并不需要修改 CRD 的结构,只需要更新一下 Controller 的镜像。

5. 并不会对 kube-apiserver 产生额外的压力

如上图,在采集集群 Event 之后,kube-apiserver 相关指标没有产生明显恶化,波动在日常区间之类,可以放心使用。


微信公众号