kube-ops-view 是支援 Kubernetes 的 Monitor 工具,其特性是輕量又能簡單地查看 Cluster、Nodes 和 Pods 的分佈狀態,尤其是在 HPA, VPA, Cluster Autoscaler 作動時提供一個很容易查看的介面,雖然在 Monitor 的生態系中 Grafana + Prometheus 幾乎打死所有功能,但在比較簡單的情境下 kube-ops-view 這種簡單輕量的工具仍然提供不錯的使用場景。
Helm Install kube-ops-view
最簡單就是用 Helm 搞定,kube-ops-view 已經支援用 Helm 的方法安裝
# helm install kube-ops-view
stable/kube-ops-view \
--set rbac.create=true
基於安全因素,這類型的 Dashboard 都用 kubectl proxy
來訪問比較安全
# kubectl proxy --port=8001
kube-ops-view proxy access uri
http://127.0.0.1:8001/api/v1/namespaces/default/services/http:kube-ops-view:/proxy/
基於研究的角度跑一下 dry-run 看一下 kube-ops-view 到底裝了哪些東西
RBAC:Service Account、Cluster Role
kube-ops-view 需要向 Cluster 拿 nodes, pods 的資訊,所以需要建立 rbac 權限
---
# Source: kube-ops-view/templates/serviceaccount.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: kube-ops-view
---
# Source: kube-ops-view/templates/clusterrole.yaml
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRole
metadata:
name: kube-ops-view
rules:
- apiGroups: [""]
resources: ["nodes", "pods"]
verbs: ["list"]
- apiGroups: ["metrics.k8s.io"]
resources: ["nodes", "pods"]
---
# Source: kube-ops-view/templates/clusterrolebinding.yaml
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
name: kube-ops-view
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: kube-ops-view
subjects:
- kind: ServiceAccount
name: kube-ops-view
namespace: default
Deployment:deployment、service
kube-ops-view Pod 引用 kube-ops-view 這個 service account,內建 container 內有 :8080/health
用來檢測健康狀態,和 resource limitation 限制能跑的資源,但 limit 仍然是依據有多少 Clusters、Nodes 和 Pods 決定佔用資源。
# Source: kube-ops-view/templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: kube-ops-view
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: kube-ops-view
template:
spec:
serviceAccountName: kube-ops-view
containers:
- name: kube-ops-view
image: "hjacobs/kube-ops-view:20.4.0"
imagePullPolicy: IfNotPresent
env:
ports:
- containerPort: 8080
livenessProbe:
httpGet:
path: /health
port: 8080
readinessProbe:
httpGet:
path: /health
port: 8080
resources:
limits:
cpu: 100m
memory: 128Mi
requests:
cpu: 80m
memory: 64Mi
Container 預設是聽 8080/tcp port,以 kube-ops-view 這種輕量的 Monitor 工具通常更建議跑在 Cluster or Pod 這種層級就好,更詳細的資訊採用 Grafana + Prometheus 專業的套件。
# Source: kube-ops-view/templates/service.yaml
apiVersion: v1
kind: Service
metadata:
name: kube-ops-view
labels:
app.kubernetes.io/name: kube-ops-view
spec:
type: ClusterIP
ports:
- port: 80
targetPort: 8080
protocol: TCP
selector:
app.kubernetes.io/name: kube-ops-view
除此之外 kube-ops-view 也支援 Multiple Cluster 這對於更大型的環境時提供 One View 有很大的幫助。