Kubernetes cluster içinde çalışan, cluster'ın CPU, RAM ve pod kullanımını HTTP API olarak sunan read-only bir metrik servisi.
metrics.k8s.io) ve Kubernetes API'den okunur.kubectl top nodes çalışıyorsa hazırdır.| Değişken | Zorunlu | Varsayılan | Açıklama |
|---|---|---|---|
API_KEYS | Önerilir | (boş) | Virgülle ayrılmış API anahtarları. İstemciler X-API-Key header'ında bunlardan birini gönderir. Boş bırakılırsa kimlik doğrulama kapalıdır. Dışarı açılan kurulumlarda mutlaka doldurun. |
DATABASE_URL | Hayır | sqlite:////data/metrics.db | Geçmiş verinin yazılacağı veritabanı. PostgreSQL için: postgresql+psycopg://kullanici:sifre@host:5432/veritabani |
METRICS_COLLECTION_INTERVAL_SECONDS | Hayır | 60 | Geçmiş için metrik toplama aralığı (saniye). |
COLLECTOR_ENABLED | Hayır | true | false yapılırsa geçmiş toplanmaz, sadece anlık endpointler çalışır. |
LOG_LEVEL | Hayır | INFO | DEBUG, INFO, WARNING, ERROR |
Hassas değerleri (API_KEYS, DATABASE_URL) Kubernetes Secret üzerinden verin.
8080GET /health10001 (root değil), read-only root filesystem ile çalışabilir./data yazılabilir olmalıdır (ör. emptyDir). Pod yeniden başlarsa son 1 saatlik geçmiş sıfırlanır; kalıcılık için PostgreSQL kullanın.replicas: 1 kullanın.apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: metrics-api-reader
rules:
- apiGroups: [""]
resources: ["nodes", "pods", "namespaces"]
verbs: ["get", "list"]
- apiGroups: ["apps"]
resources: ["deployments", "statefulsets", "daemonsets", "replicasets"]
verbs: ["get", "list"]
- apiGroups: ["metrics.k8s.io"]
resources: ["nodes", "pods"]
verbs: ["get", "list"]
Bu ClusterRole'ü bir ClusterRoleBinding ile pod'un ServiceAccount'una bağlayın.
apiVersion: apps/v1
kind: Deployment
metadata:
name: metrics-api
namespace: monitoring
spec:
replicas: 1
strategy:
type: Recreate
selector:
matchLabels: { app: metrics-api }
template:
metadata:
labels: { app: metrics-api }
spec:
serviceAccountName: metrics-api
containers:
- name: api
image: furkanustcayir/metrics-api:1.0.0
ports:
- containerPort: 8080
env:
- name: METRICS_COLLECTION_INTERVAL_SECONDS
value: "60"
envFrom:
- secretRef:
name: metrics-api-secret # API_KEYS (+ opsiyonel DATABASE_URL)
readinessProbe:
httpGet: { path: /health, port: 8080 }
volumeMounts:
- { name: data, mountPath: /data }
volumes:
- name: data
emptyDir: {}
kubectl -n monitoring create secret generic metrics-api-secret \
--from-literal=API_KEYS="$(openssl rand -hex 32)"
Anlık:
GET /api/v1/summary
GET /api/v1/cluster
GET /api/v1/nodes
GET /api/v1/pods?namespace={namespace}
GET /api/v1/namespaces
GET /api/v1/namespaces/{namespace}
GET /api/v1/namespaces/{namespace}/pods
GET /api/v1/namespaces/{namespace}/workloads
GET /api/v1/namespaces/{namespace}/statefulsets
Geçmiş (?minutes=1..60, varsayılan 60):
GET /api/v1/history/cluster
GET /api/v1/history/nodes?node={node}
GET /api/v1/history/namespaces/{namespace}
GET /api/v1/history/workloads/{namespace}/{workload}?kind=StatefulSet
GET /api/v1/history/pods/{namespace}/{pod}
Swagger UI: /docs
curl -H "X-API-Key: <anahtar>" https://metrics.example.com/api/v1/summary
| Kod | Anlamı |
|---|---|
401 | API anahtarı eksik veya hatalı |
404 | Namespace bulunamadı |
503 | metrics-server veya Kubernetes API'ye erişilemiyor |
Content type
Image
Digest
sha256:439160315…
Size
73.6 MB
Last updated
about 1 month ago
docker pull furkanustcayir/metrics-api