自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

K8sGPT+Ollama:免費(fèi)的 Kubernetes 自動(dòng)化診斷方案

人工智能
介紹 k8sgpt-operator 的文章發(fā)布后,有小伙伴反饋 OpenAI 的使用門檻,這個(gè)問(wèn)題確實(shí)比較棘手,但也不是不能解決。不過(guò)本文并不是介紹如何解決這種問(wèn)題的,而是介紹 OpenAI 的替代方案: Ollama。

周末檢查博客草稿,發(fā)現(xiàn)了這篇。記得當(dāng)時(shí)是與 Kubernetes 自動(dòng)化診斷工具:k8sgpt-operator 的方案,由于之前試過(guò) Ollama[1],感覺(jué)使用起來(lái)也更加友好,而且 Ollama 同樣提供了 對(duì) OpenAI API 的支持[2],索性改成用 Ollama 吧。

介紹 k8sgpt-operator 的文章發(fā)布后,有小伙伴反饋 OpenAI 的使用門檻,這個(gè)問(wèn)題確實(shí)比較棘手,但也不是不能解決。不過(guò)本文并不是介紹如何解決這種問(wèn)題的,而是介紹 OpenAI 的替代方案: Ollama。

對(duì) k8sgpt 和 k8sgpt-operator 就不做過(guò)多介紹了,有興趣的可以看回 上一篇。

1. 安裝 Ollama

Ollama 是一個(gè)開源的大模型工具,使用它可以在本地或云端輕松的安裝和運(yùn)行 多種流量的大模型[3]。它的操作非常友好,只需簡(jiǎn)單的命令就能運(yùn)行。在 macOS 上可以通過(guò) homebrew 一鍵安裝:

brew install ollama

當(dāng)前最新的版本是 0.1.44。

ollama -v
Warning: could not connect to a running Ollama instance
Warning: client version is 0.1.44

在 Linux 上也可以通過(guò)官方的腳本一鍵安裝。

curl -sSL https://ollama.com/install.sh | sh

啟動(dòng) Ollama,通過(guò)環(huán)境變量將 Ollama 的監(jiān)聽地址設(shè)置為 0.0.0.0,便于后面從容器或者 K8s 集群訪問(wèn)。

OLLAMA_HOST=0.0.0.0 ollama start

...
time=2024-06-16T07:54:57.329+08:00 level=INFO source=routes.go:1057 msg="Listening on 127.0.0.1:11434 (version 0.1.44)"
time=2024-06-16T07:54:57.329+08:00 level=INFO source=payload.go:30 msg="extracting embedded files" dir=/var/folders/9p/2tp6g0896715zst_bfkynff00000gn/T/ollama1722873865/runners
time=2024-06-16T07:54:57.346+08:00 level=INFO source=payload.go:44 msg="Dynamic LLM libraries [metal]"
time=2024-06-16T07:54:57.385+08:00 level=INFO source=types.go:71 msg="inference compute" id=0 library=metal compute="" driver=0.0 name="" total="21.3 GiB" available="21.3 GiB"

2. 下載并運(yùn)行大模型

Llama3 流行的大模型之一,由 Meta 在 4 月開源。Llama3 有兩個(gè)版本:8B 和 70B。

我是在 macOS 上運(yùn)行,所以選擇 8B 的版本。8B 的版本大小 4.7 GB,網(wǎng)速快的話 3-4 分鐘就可以完成下載。

ollama run llama3

我是 m1 pro + 32g 內(nèi)存,啟動(dòng) 12s 多。

time=2024-06-17T09:30:25.070+08:00 level=INFO source=server.go:572 msg="llama runner started in 12.58 seconds"

執(zhí)行一次 query 的時(shí)間在 14s 左右。

curl http://localhost:11434/api/generate -d '{
  "model": "llama3",
  "prompt": "Why is the sky blue?",
  "stream": false
}'

....
"total_duration":14064009500,"load_duration":1605750,"prompt_eval_duration":166998000,"eval_count":419,"eval_duration":13894579000}

3. 配置 K8sGPT CLI 后端

如果你想測(cè)試 k8sgpt-operator,可以跳過(guò)這一步。

我們將使用 Ollama REST API 作為 k8sgpt 的后端,作為推理的 provider,這里后端類型選擇 localai。因?yàn)?nbsp;LocalAI[4] 與 Ollama 同樣兼容 OpenAI API,真正的 provider 還是 Ollama 運(yùn)行的 Llama。

k8sgpt auth add --backend localai --model llama3 --baseurl http://localhost:11434/v1

同時(shí)將其設(shè)置成默認(rèn)的 provider。

k8sgpt auth default --provider localai
Default provider set to localai

測(cè)試:

我們?cè)?k8s 上創(chuàng)建一個(gè) pod,使用鏡像 image-not-exit。

kubectl get po k8sgpt-test
NAME          READY   STATUS         RESTARTS   AGE
k8sgpt-test   0/1     ErrImagePull   0          6s

使用 k8sgpt 對(duì)錯(cuò)誤進(jìn)行分析。

k8sgpt analyze --explain --filter=Pod --=default --output=json

{
  "provider": "localai",
  "errors": null,
  "status": "ProblemDetected",
  "problems": 1,
  "results": [
    {
      "kind": "Pod",
      "name": "default/k8sgpt-test",
      "error": [
        {
          "Text": "Back-off pulling image \"image-not-exist\"",
          "KubernetesDoc": "",
          "Sensitive": []
        }
      ],
      "details": "Error: Back-off pulling image \"image-not-exist\"\n\nSolution: \n1. Check if the image exists on Docker Hub or your local registry.\n2. If not, create the image using a Dockerfile and build it.\n3. If the image exists, check the spelling and try again.\n4. Verify the image repository URL in your Kubernetes configuration file (e.g., deployment.yaml).",
      "parentObject": ""
    }
  ]
}

4. 部署并配置 k8sgpt-operator

k8sgpt-operator 可以在集群中開啟自動(dòng)化的 k8sgpt。可以通過(guò) Helm 來(lái)安裝

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

k8sgpt-operator 提供了兩個(gè) CRD:K8sGPT 配置 k8sgpt;Result 輸出分析結(jié)果。

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

配置 K8sGPT,這里 baseUrl 要使用 Ollama 的 IP 地址。

kubectl apply -n k8sgpt -f - << EOF
apiVersion: core.k8sgpt.ai/v1alpha1
kind: K8sGPT
metadata:
  name: k8sgpt-ollama
spec:
  ai:
    enabled: true
    model: llama3
    backend: localai
    baseUrl: http://198.19.249.3:11434/v1
  noCache: false
  filters: ["Pod"]
  repository: ghcr.io/k8sgpt-ai/k8sgpt
  version: v0.3.8
EOF

創(chuàng)建 CR K8sGPT 之后,operator 會(huì)自動(dòng)為其創(chuàng)建 Pod。檢查 CR Result 也可以看到同樣的結(jié)果。

kubectl get result -n k8sgpt -o jsnotallow='{.items[].spec}' | jq .
{
  "backend": "localai",
  "details": "Error: Kubernetes is unable to pull the image \"image-not-exist\" due to it not existing.\n\nSolution: \n1. Check if the image actually exists.\n2. If not, create the image or use an alternative one.\n3. If the image does exist, ensure that the Docker daemon and registry are properly configured.",
  "error": [
    {
      "text": "Back-off pulling image \"image-not-exist\""
    }
  ],
  "kind": "Pod",
  "name": "default/k8sgpt-test",
  "parentObject": ""
}

參考資料

[1] Ollama: https://ollama.com

[2] 對(duì) OpenAI API 的支持: https://github.com/ollama/ollama/blob/main/docs/openai.md

[3] 多種流量的大模型: https://ollama.com/library

[4] LocalAI: https://localai.io

責(zé)任編輯:武曉燕 來(lái)源: 云原生指北
相關(guān)推薦

2023-05-03 21:54:05

Kubernetes自動(dòng)化診斷工具

2024-02-26 08:15:00

2020-08-31 22:05:53

Kubernetes微服務(wù)系統(tǒng)

2023-09-27 23:23:09

云原生K8sGPT

2022-10-31 09:05:18

Kubernetes自動(dòng)化

2014-03-11 11:10:10

PowerShell自動(dòng)化腳本

2024-05-06 08:08:31

2021-01-14 10:45:01

人工智能智慧醫(yī)療分子診斷

2013-05-16 11:07:37

Android開發(fā)Android應(yīng)用自動(dòng)化測(cè)試

2020-10-29 10:17:24

AnsibleKubernetes容器編排自動(dòng)化

2021-09-08 16:03:12

Kubernetes 安全開源

2017-12-17 21:58:18

2015-12-30 14:50:45

Kubernetes容器技術(shù)Docker

2021-01-24 11:46:26

自動(dòng)化Web 優(yōu)化

2022-02-18 13:12:49

人工智能自動(dòng)化技術(shù)

2022-06-09 13:45:18

vivoK8S集群Kubernetes

2014-05-13 13:41:51

iOS開發(fā)自動(dòng)化打渠道包

2023-03-01 19:03:35

K8s服務(wù)域名證書

2022-02-17 17:37:17

超級(jí)自動(dòng)化人工智能AI

2010-12-06 09:59:58

點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)