OpenShift 4.11以后在产品中移除了grafana的console,集成到产品的监控界面中去了,这对于我们想要看到原生的以及需要定制的人来说不太方便。
本文就在OpenShift 4.12的环境中安装和部署一个grafana
1.在Operator Hub中安装Grafana Operator,过程略
2.建立Grafana instance, 在yaml中输入(需求修改的地方是password那行)
apiVersion: integreatly.org/v1alpha1 kind: Grafana metadata: name: example-grafana namespace: test01 spec: ingress: enabled: true config: auth: disable_signout_menu: true auth.anonymous: enabled: true log: level: warn mode: console security: admin_password: secret admin_user: root dashboardLabelSelector: - matchExpressions: - key: app operator: In values: - grafana
部署完成后会看到
[lab-user@bastion ~]$ oc get pods -n my-grafana NAME READY STATUS RESTARTS AGE grafana-deployment-54df498bcb-fptf9 1/1 Running 0 41m grafana-operator-controller-manager-6cb659f7d9-bxptz 2/2 Running 0 76m
同时在route中看到路由
3. 添加权限并建立DataSource Object
oc adm policy add-cluster-role-to-user cluster-monitoring-view -z grafana-serviceaccount oc create token grafana-serviceaccount --duration=8760h -n my-grafana
创建DataSource Object,用上面建立的token替换${BEARER_TOKEN}
apiVersion: integreatly.org/v1alpha1 kind: GrafanaDataSource metadata: name: prometheus-grafanadatasource namespace: my-grafana spec: datasources: - access: proxy editable: true isDefault: true jsonData: httpHeaderName1: 'Authorization' timeInterval: 5s tlsSkipVerify: true name: Prometheus secureJsonData: httpHeaderValue1: 'Bearer ${BEARER_TOKEN}' type: prometheus url: 'https://thanos-querier.openshift-monitoring.svc.cluster.local:9091' name: prometheus-grafanadatasource.yaml
建立完成后看到
4. 登录进入grafana,然后添加相应的json
这一块一直没有找到之前OCP自带的那些json文件,需要找一个以前的环境把图标导出来。当然也有github中的一些例子,但我导入后数据没有
正确显示,参考
https://medium.com/@dotdc/a-set-of-modern-grafana-dashboards-for-kubernetes-4b989c72a4b2
https://github.com/dotdc/grafana-dashboards-kubernetes
标签:4.12,name,oc,grafana,true,OpenShift From: https://www.cnblogs.com/ericnie/p/17475012.html