k8s--基础--26.5--监控告警系统--Grafana--安装和配置
k8s的各个master节点和node节点都要操作。
·
k8s–基础–26.5–监控告警系统–Grafana–安装和配置
1、安装前
k8s的各个master节点和node节点都要操作
1.1、上传镜像文件
mkdir -p /root/k8s/monitor/
cd /root/k8s/monitor/
1.2、解压缩
# 解压缩
docker load -i /root/k8s/monitor/heapster-grafana-amd64_v5_0_4.tar.gz
# 删除
rm -rf /root/k8s/monitor/heapster-grafana-amd64_v5_0_4.tar.gz
2、安装Grafana
- 在k8s的master1节点操作
2.1、脚本
vi /root/k8s/monitor/grafana.yaml
内容
apiVersion: apps/v1
kind: Deployment
metadata:
# Deployment名称
name: monitoring-grafana
# Deployment名称空间
namespace: kube-system
spec:
# 副本数量
replicas: 1
# 标签选择器,选择对应标签的模板
selector:
matchLabels:
task: monitoring
k8s-app: grafana
# 模板定义
template:
metadata:
labels:
task: monitoring
k8s-app: grafana
# 容器定义
spec:
containers:
- name: grafana
image: k8s.gcr.io/heapster-grafana-amd64:v5.0.4
ports:
- containerPort: 3000
protocol: TCP
# 挂载点
volumeMounts:
- mountPath: /etc/ssl/certs
name: ca-certificates
readOnly: true
- mountPath: /var
name: grafana-storage
# 环境变量
env:
- name: INFLUXDB_HOST
value: monitoring-influxdb
- name: GF_SERVER_HTTP_PORT
value: "3000"
# The following env variables are required to make Grafana accessible via
# the kubernetes api-server proxy. On production clusters, we recommend
# removing these env variables, setup auth for grafana, and expose the grafana
# service using a LoadBalancer or a public IP.
- name: GF_AUTH_BASIC_ENABLED
value: "false"
- name: GF_AUTH_ANONYMOUS_ENABLED
value: "true"
- name: GF_AUTH_ANONYMOUS_ORG_ROLE
value: Admin
- name: GF_SERVER_ROOT_URL
# If you're only using the API Server proxy, set this value instead:
# value: /api/v1/namespaces/kube-system/services/monitoring-grafana/proxy
value: /
# 存储卷设置
volumes:
- name: ca-certificates
hostPath:
path: /etc/ssl/certs
- name: grafana-storage
emptyDir: {}
---
apiVersion: v1
kind: Service
metadata:
# Service 标签
labels:
# For use as a Cluster add-on (https://github.com/kubernetes/kubernetes/tree/master/cluster/addons)
# If you are NOT using this as an addon, you should comment out this line.
kubernetes.io/cluster-service: 'true'
kubernetes.io/name: monitoring-grafana
# Service 名称
name: monitoring-grafana
# Service 名称空间
namespace: kube-system
spec:
# In a production setup, we recommend accessing Grafana through an external Loadbalancer
# or through a public IP.
# type: LoadBalancer
# You could also use NodePort to expose the service at a randomly-generated port
# type: NodePort
ports:
- port: 80
targetPort: 3000
selector:
k8s-app: grafana
# 浏览器访问
type: NodePort
2.2、执行
kubectl apply -f /root/k8s/monitor/grafana.yaml
# 查看
kubectl get pods -n kube-system -o wide | grep grafana
kubectl get svc -n kube-system | grep grafana
3、Grafan 操作
3.1、登陆
http://192.168.187.154:30416
默认账号:admin
默认密码:admin
3.2、配置数据源
Name值:Prometheus
Type值:Prometheus
URL值:http://prometheus.monitor-sa.svc:9090
3.3、导入监控模板
3.3.1、位置
- node_exporter.json监控模板:可以把node节点指标显示出来
- docker_rev1.json监控模板:可以把容器相关的数据展示出来
3.3.2、导入的步骤
这里已导入node_exporter.json为例
选择导入
选择导入文件
修改和导入
3.3.3、导入其他监控模板
参考3.3.2,将docker_rev1.json导入进去。
更多推荐
已为社区贡献55条内容
所有评论(0)