
k8sgpt是用于扫描Kubernetes群集的工具,以简单的英语诊断和分类问题。
它已将SRE经验编纂为分析仪,并有助于提取最相关的信息以使用AI丰富。
与Openai,Azure,Cohere,Amazon Bedrock,Google Gemini和本地型号的开箱即用。

$ brew install k8sgpt或者
brew tap k8sgpt-ai/k8sgpt
brew install k8sgpt32位:
sudo rpm -ivh https://github.com/k8sgpt-ai/k8sgpt/releases/download/v0.3.46/k8sgpt_386.rpm
64位:
sudo rpm -ivh https://github.com/k8sgpt-ai/k8sgpt/releases/download/v0.3.46/k8sgpt_amd64.rpm
32位:
curl -LO https://github.com/k8sgpt-ai/k8sgpt/releases/download/v0.3.46/k8sgpt_386.deb
sudo dpkg -i k8sgpt_386.deb
64位:
curl -LO https://github.com/k8sgpt-ai/k8sgpt/releases/download/v0.3.46/k8sgpt_amd64.deb
sudo dpkg -i k8sgpt_amd64.deb
32位:
wget https://github.com/k8sgpt-ai/k8sgpt/releases/download/v0.3.46/k8sgpt_386.apk
apk add --allow-untrusted k8sgpt_386.apk
64位:
wget https://github.com/k8sgpt-ai/k8sgpt/releases/download/v0.3.46/k8sgpt_amd64.apk
apk add --allow-untrusted k8sgpt_amd64.apk
==> Installing k8sgpt from k8sgpt-ai/k8sgpt Error: The following formula cannot be installed from a bottle and must be
built from the source. k8sgpt Install Clang or run brew install gcc.
如果您按建议安装GCC,则问题将持续存在。因此,您需要安装Build-Ender-Ender-nectentable。
sudo apt-get update
sudo apt-get install build-essential
要在k8sgpt-operator群集中安装
这种操作模式非常适合连续监视群集,并且可以与您现有的监视(例如Prometheus和AlertManager)集成。
k8sgpt generate以打开浏览器链接来生成它来做到这一点k8sgpt auth add以在K8SGPT中设置它。--password标志直接提供密码。k8sgpt filters来管理分析仪使用的活动过滤器。默认情况下,所有过滤器均在分析过程中执行。k8sgpt analyze以进行扫描。k8sgpt analyze --explain以对问题进行更详细的解释。k8sgpt analyze --with-doc (有或没有解释标志)以获取Kubernetes的官方文档。 K8SGPT使用分析仪来分类和诊断群集中的问题。它具有一组内置的分析仪,但是您将能够编写自己的分析仪。
使用默认分析仪进行扫描
k8sgpt generate
k8sgpt auth add
k8sgpt analyze --explain
k8sgpt analyze --explain --with-doc
资源过滤
k8sgpt analyze --explain --filter=Service
通过名称空间过滤
k8sgpt analyze --explain --filter=Pod --namespace=default
输出到JSON
k8sgpt analyze --explain --filter=Service --output=json
解释过程中匿名化
k8sgpt analyze --explain --filter=Service --output=json --anonymize
列表过滤器
k8sgpt filters list
添加默认过滤器
k8sgpt filters add [filter(s)]
k8sgpt filters add Servicek8sgpt filters add Ingress,Pod删除默认过滤器
k8sgpt filters remove [filter(s)]
k8sgpt filters remove Servicek8sgpt filters remove Ingress,Pod列表配置的后端
k8sgpt auth list
更新已配置的后端
k8sgpt auth update $MY_BACKEND1,$MY_BACKEND2..
删除配置的后端
k8sgpt auth remove -b $MY_BACKEND1,$MY_BACKEND2..
列表集成
k8sgpt integrations list
激活集成
k8sgpt integrations activate [integration(s)]
使用集成
k8sgpt analyze --filter=[integration(s)]
停用整合
k8sgpt integrations deactivate [integration(s)]
服务模式
k8sgpt serve
使用服务模式分析
grpcurl -plaintext -d '{"namespace": "k8sgpt", "explain" : "true"}' localhost:8080 schema.v1.ServerAnalyzerService/Analyze
{
"status": "OK"
}
用自定义标头分析
k8sgpt analyze --explain --custom-headers CustomHeaderKey:CustomHeaderValue
打印分析统计
k8sgpt analyze -s
The stats mode allows for debugging and understanding the time taken by an analysis by displaying the statistics of each analyzer.
- Analyzer Ingress took 47.125583ms
- Analyzer PersistentVolumeClaim took 53.009167ms
- Analyzer CronJob took 57.517792ms
- Analyzer Deployment took 156.6205ms
- Analyzer Node took 160.109833ms
- Analyzer ReplicaSet took 245.938333ms
- Analyzer StatefulSet took 448.0455ms
- Analyzer Pod took 5.662594708s
- Analyzer Service took 38.583359166s
诊断信息
要收集诊断信息,请使用以下命令在本地目录中创建一个dump_<timestamp>_json 。
k8sgpt dump
当您想使用-Explain FLAG EG k8sgpt analyze --explain解释分析结果时,K8SGPT使用所选的LLM,生成的AI提供商。您可以使用--backend标志来指定配置的提供商(默认情况下是openai )。
您可以使用k8sgpt auth list列出可用的提供商:
Default:
> openai
Active:
Unused:
> openai
> localai
> ollama
> azureopenai
> cohere
> amazonbedrock
> amazonsagemaker
> google
> huggingface
> noopai
> googlevertexai
> ibmwatsonxai
有关如何配置和使用每个提供商的详细文档,请参见此处。
设置新的默认提供商
k8sgpt auth default -p azureopenai
Default provider set to azureopenai
使用此选项,将数据匿名化,然后将其发送到AI后端。在分析执行过程中, k8sgpt检索敏感数据(Kubernetes对象名称,标签等)。当发送到AI后端时,将这些数据掩盖,并替换为可以用来将解决方案返回给用户的密钥。
Error: HorizontalPodAutoscaler uses StatefulSet/fake-deployment as ScaleTargetRef which does not exist.Error: HorizontalPodAutoscaler uses StatefulSet/tGLcCRcHa1Ce5Rs as ScaleTargetRef which does not exist.The Kubernetes system is trying to scale a StatefulSet named tGLcCRcHa1Ce5Rs using the HorizontalPodAutoscaler, but it cannot find the StatefulSet. The solution is to verify that the StatefulSet name is spelled correctly and exists in the same namespace as the HorizontalPodAutoscaler.The Kubernetes system is trying to scale a StatefulSet named fake-deployment using the HorizontalPodAutoscaler, but it cannot find the StatefulSet. The solution is to verify that the StatefulSet name is spelled correctly and exists in the same namespace as the HorizontalPodAutoscaler.注意:匿名化当前不适用于事件。
匿名化当前不适用于事件。
在像POD这样的一些分析仪中,我们向AI后端提供了事件消息,这些消息事先未知,因此我们暂时没有掩盖它们。
以下是掩盖数据的分析仪列表: -
以下是没有掩盖数据的分析仪列表: -
*笔记:
K8GPT不会掩盖上述分析仪,因为除了事件分析仪外,它们不会发送任何识别信息。
如本期所示,预定在不久的将来进行活动分析仪。必须进行进一步的研究以了解模式,并能够掩盖事件的敏感部分,例如POD名称,名称空间等。
以下是未被掩盖的字段列表: -
*笔记:
k8sgpt将配置数据存储在$XDG_CONFIG_HOME/k8sgpt/k8sgpt.yaml文件中。数据以纯文本存储,包括您的OpenAI键。
配置文件位置:
| 操作系统 | 小路 |
|---|---|
| macos | 〜/Library/应用程序支持/K8SGPT/K8SGPT.YAML |
| Linux | 〜/.config/k8sgpt/k8sgpt.yaml |
| 视窗 | %localappdata%/k8sgpt/k8sgpt.yaml |
添加远程缓存
AWS_ACCESS_KEY_ID和AWS_SECRET_ACCESS_KEY需要作为环境变量。k8sgpt cache add s3 --region <aws region> --bucket <name>k8sgpt cache add s3 --bucket <name> --endpoint <http://localhost:9000>k8sgpt cache add s3 --bucket <name> --endpoint <https://localhost:9000> --insecurek8sgpt cache add azure --storageacc <storage account name> --container <container name>GOOGLE_APPLICATION_CREDENTIALS是环境变量。k8sgpt cache add gcs --region <gcp region> --bucket <name> --projectid <project id>列表缓存项目
k8sgpt cache list
从缓存注意清除对象:使用此命令清除对象将删除上游文件,因此需要适当的权限。
k8sgpt cache purge $OBJECT_NAME
删除远程缓存注意:这不会删除上游S3存储桶或Azure存储容器
k8sgpt cache remove
您可能希望在某些情况下用自己选择的语言编写自己的分析器。 K8SGPT现在通过遵守模式并为分析仪提供消费来支持这样做的能力。为此,请在K8SGPT配置中定义分析仪,并将其添加到扫描过程中。除此之外,您还需要在分析上启用以下标志:
k8sgpt analyze --custom-analysis
这是Rust的示例本地主机分析仪在localhost:8080 K8SGPT Config可以通过以下添加来将其接收:
custom_analyzers:
- name: host-analyzer
connection:
url: localhost
port: 8080
现在,这使得通过Hostos信息(从此分析仪示例)到K8SGPT,并用作正常分析的上下文。
查看有关如何编写自定义分析仪的文档
列表配置的自定义分析仪
k8sgpt custom-analyzer list
添加无需安装的自定义分析仪
k8sgpt custom-analyzer add --name my-custom-analyzer --port 8085
删除自定义分析仪
k8sgpt custom-analyzer remove --names "my-custom-analyzer,my-custom-analyzer-2"
在此处找到我们的官方文档
请阅读我们的贡献指南。
在懈怠中找到我们