
Cập nhật lần cuối: 01/02/2026 17:00
Tài liệu này hướng dẫn cấu hình để thu thập Metrics, Logs, Events từ Kubernetes
curl -L -o k8s-monitoring-3.7.1.tgz https://s3hn.smartcloud.vn/agent/helm-charts/k8s-monitoring-3.7.1.tgzCác helm chart cần thiết bao gồm:
STT | Helm Chart | Chart Version |
1 | kube-prometheus-stack | 80.3.0 |
2 | k8s-monitoring | 3.7.1 |
kubectl create namespace monitoring kubectl create secret generic secret-token \
-n monitoring \
--from-literal=token=<token_dịch_vụ_APM>helm install kube-prometheus-stack prometheus-community/kube-prometheus-stack \
--namespace monitoring \
--create-namespace \
--version 80.3.0 \
--set prometheus.prometheusSpec.retentionSize=5Gi \
--set prometheus.prometheusSpec.retention=1d \
--set prometheus.prometheusSpec.storageSpec.volumeClaimTemplate.spec.resources.requests.storage=10Gi \
--set alertmanager.alertmanagerSpec.storage.volumeClaimTemplate.spec.resources.requests.storage=2Gi \
--set grafana.ingress.enabled=true \
--set grafana.ingress.ingressClassName=<class_name> \
--set grafana.ingress.hosts[0]=<host_domain> \
--set prometheus.prometheusSpec.remoteWrite[0].url=<endpoint_dịch_vụ_APM> \
--set prometheus.prometheusSpec.remoteWrite[0].authorization.type=Bearer \
--set prometheus.prometheusSpec.remoteWrite[0].authorization.credentials.name=secret-token \
--set prometheus.prometheusSpec.remoteWrite[0].authorization.credentials.key=token \
--set prometheus.prometheusSpec.remoteWrite[0].writeRelabelConfigs[0].sourceLabels[0]=job \
--set prometheus.prometheusSpec.remoteWrite[0].writeRelabelConfigs[0].targetLabel=job \
--set-string prometheus.prometheusSpec.remoteWrite[0].writeRelabelConfigs[0].regex="(integrations/(node_exporter|unix))|.*node-exporter.*" \
--set prometheus.prometheusSpec.remoteWrite[0].writeRelabelConfigs[0].replacement=integrations/unixThay các trường ở file cấu hình sau, trong đó:
| Trường | Ý nghĩa | Giá trị mẫu |
| endpoint_dịch_vụ_APM | Endpoint của dịch vụ APM trên giao diện Console | https://metrics-0qcs3dsvvva.apm.vnptplatform.vn/api/v1/push |
| token_dịch_vụ_APM | Token của dịch vụ APM trên giao diện Console | a5130b91-ff9b-41ef-8722-9d923a574123 |
| class_name | Class của Ingress Controller | nginx |
| host_domain | Domain truy cập Prometheus | monitor-apm01.obs.vnptplatform.vn |
helm install -n monitoring kube-prometheus-stack . Thay các trường ở file cấu hình trên, trong đó:
| endpoint_dịch_vụ_APM | Endpoint của dịch vụ APM trên giao diện Console | https://logs-w3fl36b8ok.obs.vnptplatform.vn/loki/api/v1/push |
| token_dịch_vụ_APM | Token của dịch vụ APM trên giao diện Console | a5130b91-ff9b-41ef-8722-9d923a574123 |
| destinations_name | Xác định điểm đích tiếp nhận log | loki |
| destinations_name | Danh sách namespace cần thu thập logs pod | - kube-system - monitoring |
Thực hiện thay đổi các cấu hình sau để thu thập kubernetes events, logs.
clusterEvents:
enabled: true
destinations:
- <destinations_name>
collector: alloy-singletonnodeLogs:
enabled: true
destinations:
- <destinations_name>
collector: alloy-logspodLogs:
enabled: true
destinations:
- <destinations_name>
collector: alloy-logsdestinations:
- name: loki
type: <destinations_name>
url: <endpoint_dịch_vụ_APM>
auth:
type: bearerToken
bearerToken: "<token_dịch_vụ_APM>"
secret:
embed: truepodLogs:
namespace: [<namespace_list>]alloy-logs):alloy-logs:
enabled: true
resources:
limits:
cpu: 500m
memory: 1024Mi
requests:
cpu: 1m
memory: 5Mialloy-singleton:
enabled: true
alloy-logs:
enabled: true
alloy:
podSecurityContext:
runAsUser: 0
runAsGroup: 0
runAsNonRoot: false
securityContext:
privileged: true
allowPrivilegeEscalation: true
extraVolumes:
- name: varlog
hostPath:
path: /var/log
type: Directory
extraVolumeMounts:
- name: varlog
mountPath: /var/log
readOnly: true
extraConfig: |
loki.source.file "syslog" {
path_targets = [
{
__path__ = "/var/log/syslog*",
job = "syslog"
}]
labels = {
job = "integrations/node_exporter",
instance = sys.env("HOSTNAME"),
}
max_age = "30m"
forward_to = [loki.write.loki.receiver] helm install -n monitoring k8s-monitoring .Thực hiện lệnh sau:
helm list -n monitoring
kubectl get po,svc -n monitoringKết quả helm release, pod running:
Một số dashboard mẫu khi tích hợp thành công: