成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

Kubernetes 自動化診斷工具:K8sgpt-Operator

開發 開發工具
k8sgpt 是一個掃描 Kubernetes 集群、診斷和分類問題的工具。它將 SRE 經驗編入其分析器,并通過 AI 幫助提取并豐富相關的信息。

背景

在 Kubernetes 上,從部署 Deployment 到正常提供服務,整個流程可能會出現各種各樣問題,有興趣的可以瀏覽 Kubernetes Deployment 的故障排查可視化指南(2021 中文版)[1]。從可視化指南也可能看出這些問題實際上都是有跡可循,根據錯誤信息基本很容易找到解決方法。隨著 ChatGPT 的流行,基于 LLM 的文本生成項目不斷涌現,k8sgpt[2] 便是其中之一。

k8sgpt 是一個掃描 Kubernetes 集群、診斷和分類問題的工具。它將 SRE 經驗編入其分析器,并通過 AI 幫助提取并豐富相關的信息。

其內置了大量的分析器:

  • podAnalyzer
  • pvcAnalyzer
  • rsAnalyzer
  • serviceAnalyzer
  • eventAnalyzer
  • ingressAnalyzer
  • statefulSetAnalyzer
  • deploymentAnalyzer
  • cronJobAnalyzer
  • nodeAnalyzer
  • hpaAnalyzer(可選)
  • pdbAnalyzer(可選)
  • networkPolicyAnalyzer(可選)

k8sgpt 的能力是通過 CLI 來提供的,通過 CLI 可以對集群中的錯誤進行快速的診斷。

k8sgpt analyze --explain --filter=Pod --namespace=default --output=json
{
  "status": "ProblemDetected",
  "problems": 1,
  "results": [
    {
      "kind": "Pod",
      "name": "default/test",
      "error": [
        {
          "Text": "Back-off pulling image \"flomesh/pipy2\"",
          "Sensitive": []
        }
      ],
      "details": "The Kubernetes system is experiencing difficulty pulling the requested image named \"flomesh/pipy2\". \n\nThe solution may be to check that the image is correctly spelled or to verify that it exists in the specified container registry. Additionally, ensure that the networking infrastructure that connects the container registry and Kubernetes system is working properly. Finally, check if there are any access restrictions or credentials required to pull the image and ensure they are provided correctly.",
      "parentObject": "test"
    }
  ]
}

但是,每次進行診斷都要執行命令,有點繁瑣且限制較多。我想大家想要的肯定是能夠監控到問題并自動診斷。這就有了今天要介紹的 k8sgpt-operator[3]

介紹

簡單來說 k8sgpt-operator 可以在集群中開啟自動化的 k8sgpt。它提供了兩個 CRD: K8sGPT 和 Result。前者可以用來設置 k8sgpt 及其行為;而后者則是用來展示問題資源的診斷結果。

apiVersion: core.k8sgpt.ai/v1alpha1
kind: K8sGPT
metadata:
  name: k8sgpt-sample
  namespace: kube-system
spec:
  model: gpt-3.5-turbo
  backend: openai
  noCache: false
  version: v0.2.7
  enableAI: true
  secret:
    name: k8sgpt-sample-secret
    key: openai-api-key

演示

實驗環境使用 k3s 集群。

export INSTALL_K3S_VERSION=v1.23.8+k3s2
curl -sfL https://get.k3s.io | sh -s - --disable traefik --disable local-storage --disable servicelb --write-kubeconfig-mode 644 --write-kubeconfig ~/.kube/config

安裝 k8sgpt-operator

helm repo add k8sgpt https://charts.k8sgpt.ai/
helm repo update
helm install release k8sgpt/k8sgpt-operator -n openai --create-namespace

安裝完成后,可以看到隨 operator 安裝的兩個 CRD:k8sgpts 和 results。

kubectl api-resources | grep -i gpt
k8sgpts                                        core.k8sgpt.ai/v1alpha1                true         K8sGPT
results                                        core.k8sgpt.ai/v1alpha1                true         Result

在開始之前,需要先生成一個 OpenAI 的 key[4],并保存到 secret 中。

OPENAI_TOKEN=xxxx
kubectl create secret generic k8sgpt-sample-secret --from-literal=openai-api-key=$OPENAI_TOKEN -n openai

接下來創建 K8sGPT 資源。

kubectl apply -n openai -f - << EOF
apiVersion: core.k8sgpt.ai/v1alpha1
kind: K8sGPT
metadata:
  name: k8sgpt-sample
spec:
  model: gpt-3.5-turbo
  backend: openai
  noCache: false
  version: v0.2.7
  enableAI: true
  secret:
    name: k8sgpt-sample-secret
    key: openai-api-key
EOF

執行完上面的命令后在 openai 命名空間下會自動創建 Deployment k8sgpt-deployment 。

測試

使用一個不存在的鏡像創建 pod。

kubectl run test --image flomesh/pipy2 -n default

然后在 openai 命名空間下會看到一個名為 defaulttest 的資源。

kubectl get result -n openai
NAME          AGE
defaulttest   5m7s

詳細信息中可以看到診斷內容以及出現問題的資源。

kubectl get result -n openai defaulttest -o yaml
apiVersion: core.k8sgpt.ai/v1alpha1
kind: Result
metadata:
  creationTimestamp: "2023-05-02T09:00:32Z"
  generation: 1
  name: defaulttest
  namespace: openai
  resourceVersion: "1466"
  uid: 2ee27c26-61c1-4ef5-ae27-e1301a40cd56
spec:
  details: "The error message is indicating that Kubernetes is having trouble pulling
    the image \"flomesh/pipy2\" and is therefore backing off from trying to do so.
    \n\nThe solution to this issue would be to check that the image exists and that
    the spelling and syntax of the image name is correct. Additionally, check that
    the image is accessible from the Kubernetes cluster and that any required authentication
    or authorization is in place. If the issue persists, it may be necessary to troubleshoot
    the network connectivity between the Kubernetes cluster and the image repository."
  error:
  - text: Back-off pulling image "flomesh/pipy2"
  kind: Pod
  name: default/test
  parentObject: test

參考資料

[1] Kubernetes Deployment 的故障排查可視化指南(2021 中文版): https://atbug.com/troubleshooting-kubernetes-deployment-zh-v2/

[2] k8sgpt: https://github.com/k8sgpt-ai/k8sgpt

[3] k8sgpt-operator: https://github.com/k8sgpt-ai/k8sgpt-operator

[4] OpenAI 的 key: https://platform.openai.com/account/api-keys

責任編輯:武曉燕 來源: 云原生指北
相關推薦

2024-06-18 08:31:42

2024-02-26 08:15:00

2024-05-06 08:08:31

2023-09-27 23:23:09

云原生K8sGPT

2022-10-31 09:05:18

Kubernetes自動化

2020-08-31 22:05:53

Kubernetes微服務系統

2013-07-02 10:45:38

2024-05-10 08:00:48

K8soperatorGitHub

2023-05-06 08:00:00

KubernetesK8s數據服務自動化

2021-01-14 10:45:01

人工智能智慧醫療分子診斷

2017-12-17 21:58:18

2014-11-12 09:24:00

2014-09-22 11:24:18

運維

2012-12-24 22:54:31

2015-12-30 14:50:45

Kubernetes容器技術Docker

2021-09-08 16:03:12

Kubernetes 安全開源

2024-01-01 21:57:41

kubernetesCRDOperator

2016-04-12 10:18:19

代碼審計自動化代碼審計工具

2020-10-29 10:17:24

AnsibleKubernetes容器編排自動化

2016-12-05 15:48:37

點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 成人免费观看男女羞羞视频 | 日韩av中文 | 国产一区视频在线 | 日韩毛片| 精品国产乱码久久久久久88av | 婷婷久久五月天 | 国产精品高潮呻吟久久aⅴ码 | 成人在线播放 | 久久成人免费 | 精品国产乱码久久久久久影片 | 理论片87福利理论电影 | 99久久中文字幕三级久久日本 | chengrenzaixian | 一级毛片在线播放 | 一区日韩 | av免费网址 | 日本精品久久久久久久 | 午夜看电影在线观看 | 国产一区二区久久 | av片毛片 | 美女操网站 | 成人在线看片 | 男女国产视频 | 色网在线看 | 亚洲综合久久网 | 免费观看成人鲁鲁鲁鲁鲁视频 | 成人在线视频免费播放 | 特级黄一级播放 | 天天影视综合 | 精品在线一区二区 | 久久精品毛片 | 一区二区在线 | 99精品观看 | 亚洲视频二区 | 精品久久久久一区二区国产 | 久久久精品| 久久综合伊人一区二区三 | 国产成人免费 | 免费国产一区二区视频 | 日本中文字幕一区 | 九色www|