---
title: "Kubernetes thực chiến: Giám sát Kubernetes bằng Prometheus Grafana"
description: "Hướng dẫn triển khai kube-prometheus-stack trên Kubernetes: thu thập metrics node/pod, cấu hình Alertmanager gửi Telegram và tạo dashboard Grafana tối ưu."
canonical: "https://thuecloud.vn/kubernetes-thuc-chien-giam-sat-kubernetes-bang-prometheus-grafana"
markdown_url: "https://thuecloud.vn/kubernetes-thuc-chien-giam-sat-kubernetes-bang-prometheus-grafana.md"
locale: "vi"
kind: "article"
published_at: "2026-11-22T16:18:17.087Z"
updated_at: "2026-11-22T16:18:15.649Z"
site: "ThueCloud.Vn"
estimated_tokens: 1925
---
# Kubernetes thực chiến: Giám sát Kubernetes bằng Prometheus Grafana

> Hướng dẫn triển khai kube-prometheus-stack trên Kubernetes: thu thập metrics node/pod, cấu hình Alertmanager gửi Telegram và tạo dashboard Grafana tối ưu.

- Canonical HTML: https://thuecloud.vn/kubernetes-thuc-chien-giam-sat-kubernetes-bang-prometheus-grafana
- Markdown URL: https://thuecloud.vn/kubernetes-thuc-chien-giam-sat-kubernetes-bang-prometheus-grafana.md
- Organization: ThueCloud.Vn
- Support Email: support@thuecloud.vn
- Hotline: 03333 499 48
- Published: 2026-11-22
- Updated: 2026-11-22

## Mục lục

- Triển khai kube-prometheus-stack gọn nhẹ cho cụm VPS
- Bảng các chỉ số PromQL quan trọng cần đưa lên Dashboard Grafana
- Câu hỏi thường gặp (FAQ)
  - kube-prometheus-stack tiêu tốn khoảng bao nhiêu RAM trên cụm K8s?
  - Có nên truy cập Grafana qua NodePort công khai ngoài Internet không?
  - Làm sao để Prometheus tự động thu thập metrics từ ứng dụng Go hoặc Node.js của tôi?
  - Nếu cả cụm Kubernetes bị sập thì Alertmanager nằm trong cụm có gửi được cảnh báo không?

Vận hành cụm Kubernetes trên [VPS Việt Nam](https://thuecloud.vn/vps-viet-nam) mà không có hệ thống giám sát (Observability) giống như lái xe ban đêm không bật đèn: bạn chỉ biết có sự cố khi khách hàng báo website sập. Triển khai bộ đôi **Prometheus + Grafana** thông qua Helm chart `kube-prometheus-stack` là [giải pháp hạ tầng](https://thuecloud.vn/giai-phap) tiêu chuẩn giúp theo dõi sát sao từng CPU core, RAM của Pod, độ trễ API và nhận cảnh báo tức thì trước khi hệ thống quá tải.

> **Tóm tắt nhanh (TL;DR):**
> - Cài đặt trọn bộ Prometheus, Grafana, Alertmanager, `node-exporter` và `kube-state-metrics` chỉ bằng một lệnh Helm `kube-prometheus-stack`.
> - Giới hạn thời gian lưu trữ (`retention: 7d`) và `resources.limits` cho Prometheus để tránh công cụ giám sát tự ăn hết RAM/ổ đĩa của VPS.
> - Thiết lập **Alertmanager** bắn cảnh báo tự động về Telegram/Slack khi Pod bị `CrashLoopBackOff`, `OOMKilled` hoặc ổ đĩa đầy trên 85%.
> *Cập nhật: 11/2026*

## Triển khai `kube-prometheus-stack` gọn nhẹ cho cụm VPS

Sử dụng Helm để cài đặt vào namespace riêng `monitoring`:

```bash
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update

helm upgrade --install monitoring prometheus-community/kube-prometheus-stack \
  --namespace monitoring --create-namespace \
  --set prometheus.prometheusSpec.retention=7d \
  --set prometheus.prometheusSpec.resources.limits.memory=1Gi \
  --set grafana.adminPassword='StrongPassword2026!'
```

Sau khi cài xong, kiểm tra các Pod đã ở trạng thái `Running` chưa:

```bash
kubectl get pods -n monitoring
```

## Bảng các chỉ số PromQL quan trọng cần đưa lên Dashboard Grafana

| Chỉ số cần theo dõi | Câu truy vấn PromQL mẫu | Ngưỡng cảnh báo nên đặt |
| :--- | :--- | :--- |
| **Pod bị OOMKilled / Restart** | `increase(kube_pod_container_status_restarts_total[15m]) > 2` | Cảnh báo ngay lập tức |
| **CPU Node sử dụng (%)** | `100 - (avg by(instance)(rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100)` | Cảnh báo khi `> 85%` trong 5 phút |
| **Dung lượng đĩa còn trống** | `(node_filesystem_avail_bytes / node_filesystem_size_bytes) * 100` | Cảnh báo khẩn khi `< 15%` |
| **Container gần chạm trần RAM** | `container_memory_working_set_bytes / kube_pod_container_resource_limits{resource="memory"}` | Cảnh báo khi `> 90%` |

Nhờ hệ thống cảnh báo này, bạn có thể phát hiện sớm các lỗi ứng dụng như [SQLite bị database is locked khi nhiều user chat](https://thuecloud.vn/sua-loi-vibe-coding-khi-deploy-app-ai-len-vps-sqlite-bi-database-is-locked-khi-nhieu-user-chat) hoặc nghẽn mạng liên quan đến [lỗi cấu hình BGP Routing vs Static Routing](https://thuecloud.vn/nhung-loi-thuong-gap-khi-cau-hinh-bgp-routing-vs-static-routing-va-cach-toi-uu-hieu-nang). Hãy xem thêm các gói máy chủ phù hợp để dựng cụm K8s + Monitoring tại [bảng giá ThueCloud](https://thuecloud.vn/pricing).

---

> **Dựng cụm Kubernetes + Monitoring mượt mà trên ThueCloud.Vn**
> Hạ tầng **KVM Enterprise NVMe** tại `vn-hn` giúp Prometheus ghi time-series nhanh chóng với **VAT 0%**, **SLA 99,9%** và **hoàn tiền 07 ngày**:
> - **VPS VN 1:** `45.000đ` – `60.000đ`/tháng (chạy node giám sát độc lập bên ngoài cụm).
> - **VPS VN 2:** `78.000đ` – `90.000đ`/tháng (chạy Worker Node cho microservice).
> - **VPS VN 3:** `139.000đ` – `170.000đ`/tháng (chạy Control Plane + `kube-prometheus-stack`).
> - **Proxy VN/USA:** từ `70.000đ/tháng`.

## Câu hỏi thường gặp (FAQ)

### `kube-prometheus-stack` tiêu tốn khoảng bao nhiêu RAM trên cụm K8s?
Với cấu hình mặc định cho cụm nhỏ (3–5 node), toàn bộ stack gồm Prometheus, Grafana, Alertmanager và các exporter tiêu tốn khoảng 800MB – 1.2GB RAM. Bạn nên đặt `resources.limits.memory` rõ ràng và giới hạn `retention=7d` để giữ mức RAM ổn định.

### Có nên truy cập Grafana qua NodePort công khai ngoài Internet không?
Không nên mở NodePort trực tiếp. Hãy truy cập qua Ingress có bật HTTPS + xác thực SSO, hoặc dùng `kubectl port-forward -n monitoring svc/monitoring-grafana 3000:80` qua đường hầm SSH an toàn.

### Làm sao để Prometheus tự động thu thập metrics từ ứng dụng Go hoặc Node.js của tôi?
Bạn chỉ cần expose endpoint `/metrics` trong ứng dụng và tạo một tài nguyên `ServiceMonitor` trong cùng namespace (hoặc gắn label `release: monitoring`) để Prometheus Operator tự động phát hiện và scrape dữ liệu.

### Nếu cả cụm Kubernetes bị sập thì Alertmanager nằm trong cụm có gửi được cảnh báo không?
Nếu toàn bộ cụm sập (mất điện hoặc rớt mạng toàn cụm), Alertmanager bên trong cụm sẽ không gửi được tin. Do đó, các hệ thống quan trọng thường kết hợp thêm một trình kiểm tra uptime từ bên ngoài cụm (như Uptime Kuma chạy trên một VPS riêng).

## References / Sources

- https://prometheus.io/docs/introduction/overview/
- https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack

---

## Navigation & Machine-Readable Endpoints

- [Site Summary (llms.txt)](https://thuecloud.vn/llms.txt)
- [Full Technical Reference (llms-full.txt)](https://thuecloud.vn/llms-full.txt)
- [Pricing Catalog (Markdown)](https://thuecloud.vn/pricing.md)
- [Blog & Technical Guides (Markdown)](https://thuecloud.vn/blog.md)
- [XML Sitemap](https://thuecloud.vn/sitemap.xml)
