使用 Robusta
现在,我们终于可以使用 Robusta 了!默认情况下,Robusta 在当 K8s Pod 崩溃时发送通知。
因此,让我们创建一个崩溃的 Pod:
$ kubectl apply -f https://gist.githubusercontent.com/robusta-lab/283609047306dc1f05cf59806ade30b6/raw deployment.apps/crashpod created $ kubectl get pods -A | grep crash default crashpod-64db77b594-cgz4s 0/1 CrashLoopBackOff 2 (21s ago) 36s
一旦 Pod 达到两次重启,在 Slack channel 我们就将收到有关 Pod 崩溃的消息,如下所示:
与 ChatGPT 互动
经过我们的实验,我们已经确认 Robusta 已与我们的 Slack 和 K8s 集群集成。接下来让我们与 ChatGPT 机器人进行交互!
立即触发 Prometheus 警报,跳过正常延迟:
$ robusta playbooks trigger prometheus_alert alert_name=KubePodCrashLooping namespace=default pod_name=example-pod ====================================================================== Triggering action... ====================================================================== running cmd: curl -X POST http://localhost:5000/api/trigger -H 'Content-Type: application/json' -d '{"action_name": "prometheus_alert", "action_params": {"alert_name": "KubePodCrashLooping", "namespace": "default", "pod_name": "example-pod"}}' {"success":true} ====================================================================== Fetching logs... ====================================================================== 2023-01-14 23:14:33.463 INFO Error loading kubernetes pod default/example-pod. reason: Not Found status: 404 2023-01-14 23:14:33.481 INFO Error loading kubernetes pod default/example-pod. reason: Not Found status: 404 2023-01-14 23:14:33.503 INFO Error loading kubernetes pod default/example-pod. reason: Not Found status: 404 2023-01-14 23:14:33.505 ERROR cannot run pod_events_enricher on alert with no pod object: PrometheusKubernetesAlert(sink_findings=defaultdict(<class 'list'>, {'main_slack_sink': [<robusta.core.reporting.base.Finding object at 0x7fab53074e20>], 'main_ms_teams_sink': [<robusta.core.reporting.base.Finding object at 0x7fab53074700>], 'robusta_ui_sink': [<robusta.core.reporting.base.Finding object at 0x7fab40773a30>]}), named_sinks=['main_slack_sink', 'main_ms_teams_sink', 'robusta_ui_sink'], response={'success': True}, stop_processing=False, _scheduler=<robusta.integrations.scheduled.playbook_scheduler_manager_impl.PlaybooksSchedulerManagerImpl object at 0x7fab4088e0a0>, _context=ExecutionContext(account_id='8302df56-c554-4129-8b95-d143d1f2e3a2', cluster_name='dev-cluster'), obj=None, alert=PrometheusAlert(endsAt=datetime.datetime(2023, 1, 14, 23, 14, 33, 430401), generatorURL='', startsAt=datetime.datetime(2023, 1, 14, 23, 14, 33, 430406), fingerprint='', status='firing', labels={'severity': 'error', 'namespace': 'default', 'alertname': 'KubePodCrashLooping', 'pod': 'example-pod'}, annotations={}), alert_name='KubePodCrashLooping', alert_severity='error', label_namespace='default', node=None, pod=None, deployment=None, job=None, daemonset=None, statefulset=None) 2023-01-14 23:14:33.524 INFO Error loading kubernetes pod default/example-pod. reason: Not Found status: 404 2023-01-14 23:14:33.696 ERROR CallbackBlock not supported for msteams 2023-01-14 23:14:33.697 ERROR error sending message to msteams e=Invalid URL 'False': No schema supplied. Perhaps you meant http://False? ====================================================================== Done! ======================================================================
现在切换到 Slack,我们将看到一个新警报,并且这次带有 “Ask ChatGPT” 的按钮!
就是这样!恭喜,我们刚刚成功安装了我们的第一个 K8s ChatGPT 机器人!
示例 2:节点容量为 100%
下面是一个节点达到 100% 容量的例子:
Robusta UI
Robusta 有一个用于集成的 UI,也有一个预配置的 Promethus 系统,如果你还没有自己的 K8s 集群,并且想尝试一下这个 ChatGPT 机器人,你可以使用 Robusta 现有的!
结论
我们花了一些时间终于把 K8s + ChatGPT 平台搭建起来了。这是一个由爱好者们共同组建的项目,并且此项目具有很大的潜力。我希望你喜欢这篇文章。
如果你还没有自己的 K8s 集群和 Prometheus 监控系统,你可以使用 Robusta 预配置的 Promethus 监控系统。
相关链接:
- https://github.com/robusta-dev/kubernetes-chatgpt-bot
- https://home.robusta.dev/
- https://medium.com/dev-genius/k8s-robusta-k8s-troubleshooting-platform-efd389b47f24
- https://github.com/robusta-dev/robusta



