Prometheus 监控多 k8s 集群
Prometheus 可以通过 node_exporter 来采集节点的监控指标数据,node_exporter 是抓取用于采集服务器节点的各种运行指标,目前 node_exporter 支持所有常见的监控点,如 conntrack,cpu,diskstats,filesystem,loadavg,meminfo,netstat 等。
https://blog.csdn.net/lovely_nn/article/details/122358361
Prometheus主要监控k8s哪些资源?
监控Kubernetes 集群是非常重要的,我们需要时时刻刻了解集群的运行状态,对于集群的监控一般我们需要考虑以下几个方面:
1) Kubernetes 节点的监控:比如节点的 cpu、load、disk、memory 等指标
2) 内部系统组件: kube-scheduler、kube-controller-manager、kubedns/coredns 的运行状态
3) 编排级的 metrics:比如Deployment的状态、资源请求、调度和 API 延迟等数据指标
部署 node-exporter:
通过 DaemonSet 控制器来部署node_exporter,这样每一个节点都会自动运行一个这样的 Pod,如果我们从集群中删除或者添加节点后,也会进行自动扩展,部署node_exporter资源清单如下:
$ cat node-exporter.yaml
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: node-exporter
namespace: kube-mon
labels:
app: node-exporter
spec:
selector:
matchLabels:
app: node-exporter
template:
metadata:
labels:
app: node-exporter
spec:
hostPID: true
hostIPC: true
hostNetwork: true
nodeSelector:
kubernetes.io/os: linux
containers:
- name: node-exporter
image: prom/node-exporter:v1.1.1
args:
- --web.listen-address=$(HOSTIP):9100
- --path.procfs=/host/proc
- --path.sysfs=/host/sys
- --path.rootfs=/host/root
- --collector.filesystem.ignored-mount-points=^/(dev|proc|sys|var/lib/docker/.+)($|/)
- --collector.filesystem.ignored-fs-types=^(autofs|binfmt_misc|cgroup|configfs|debugfs|devpts|devtmpfs|fusectl|hugetlbfs|mqueue|overlay|proc|procfs|pstore|rpc_pipefs|securityfs|sysfs|tracefs)$
ports:
- containerPort: 9100
env:
- name: HOSTIP
valueFrom:
fieldRef:
fieldPath: status.hostIP
resources:
requests:
cpu: 150m
memory: 180Mi
limits:
cpu: 150m
memory: 180Mi
securityContext:
runAsNonRoot: true
runAsUser: 65534
volumeMounts:
- name: proc
mountPath: /host/proc
- name: sys
mountPath: /host/sys
- name: root
mountPath: /host/root
mountPropagation: HostToContainer
readOnly: true
tolerations:
- operator: "Exists"
volumes:
- name: proc
hostPath:
path: /proc
- name: dev
hostPath:
path: /dev
- name: sys
hostPath:
path: /sys
- name: root
hostPath:
path: /
# 创建pod
$ kubectl apply -f node-exporter.yaml
https://blog.csdn.net/yuezhilangniao/article/details/120428915
1 prometheus采集当前k8s监控数据
2 prometheus采集其它k8s监控数据
从上述分析来看,假设其它k8s部署了node_exporter和kube-state-metrics,用prometheus采集其它k8s集群的监控数据也是可行的,只需要解决两个问题:
设置好kubernetes_sd_configs,让其可通过其它k8s集群的apiserver发现抓取的endpionts。
设置好relabel_configs,构造出访问其它k8s集群中的service, pod, node等endpoint URL。
为者常成,行者常至
自由转载-非商用-非衍生-保持署名(创意共享3.0许可证)