---
# System prepended metadata

title: Karpor on k8s
tags: [工具]

---

# Karpor on k8s

Karpor 是一個專為 Kubernetes 叢集治理 與 最佳實踐分析 所設計的可視化工具，它會收集並分析叢集中各種資源的設定與狀態，並結合 AI 協助你發現安全性、穩定性、資源配置上的潛在問題，並提供最佳化建議。


## 部署

### 安裝 Local Path Provisioner
```
$ wget -O - https://raw.githubusercontent.com/rancher/local-path-provisioner/v0.0.22/deploy/local-path-storage.yaml | kubectl apply -f -


$ kubectl get storageclass
NAME         PROVISIONER             RECLAIMPOLICY   VOLUMEBINDINGMODE      ALLOWVOLUMEEXPANSION   AGE
local-path   rancher.io/local-path   Delete          WaitForFirstConsumer   false                  38h
```

### 安裝 helm

```
$ curl -fsSL https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash

$ helm version
version.BuildInfo{Version:"v3.17.1", GitCommit:"980d8ac1939e39138101364400756af2bdee1da5", GitTreeState:"clean", GoVersion:"go1.23.5"}
```

### 安裝 karpor

```
$ helm repo add kusionstack https://kusionstack.github.io/charts

$ helm repo update
```


* 設定 openai api key，以及要使用的對應模型
```
$ nano karpor.yaml
server:
  name: karpor-server
  port: 7443
  serviceType: NodePort
  ai:
    authToken: "xxxxxxxxxxxxxx"
    baseUrl: "https://api.openai.com/v1"
    backend: "openai"
    model: "gpt-4o-mini-2024-07-18"
    
$ helm install karpor kusionstack/karpor -f karpor.yaml 
```
### 環境檢查


```
$ kubectl -n karpor get pod -owide
NAME                             READY   STATUS    RESTARTS        AGE   IP               NODE   NOMINATED NODE   READINESS GATES
elasticsearch-6dd794f48-c87m9    1/1     Running   0               10m   10.244.190.69    w1     <none>           <none>
etcd-0                           1/1     Running   0               10m   10.244.245.175   w4     <none>           <none>
karpor-server-59469854f6-gdhbm   1/1     Running   4 (8m56s ago)   10m   10.244.80.220    w2     <none>           <none>
karpor-syncer-5d6fd8b776-j5z4p   1/1     Running   5 (8m6s ago)    10m   10.244.193.205   w3     <none>           <none>


$ kubectl -n karpor get svc
NAME            TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)          AGE
elasticsearch   ClusterIP   10.98.0.209   <none>        9200/TCP         23m
etcd            ClusterIP   10.98.0.164   <none>        2379/TCP         23m
karpor-server   NodePort    10.98.0.163   <none>        7443:32124/TCP   23m
```

### 進入 karpor UI
* 透過 NodePort 訪問 karpor UI


![image](https://hackmd.io/_uploads/Sk0AeQRBee.png)



### 註冊叢集到 karpor


![image](https://hackmd.io/_uploads/B1nYZQAHeg.png)


![image](https://hackmd.io/_uploads/B1h9-70Hee.png)


* 設定叢集名稱與貼上 kubeconfig 檔

![image](https://hackmd.io/_uploads/Syt1MXCHxx.png)


### 可以使用 AI 分析叢集狀況


![image](https://hackmd.io/_uploads/rkHkXIRSgx.png)


## 參考

https://github.com/KusionStack/karpor