🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
1、grafana出图部署 准备镜像 ``` docker pull grafana/grafana:5.4.2 docker tag 6f18ddf9e552 harbor.od.com/infra/grafana:v5.4.2 docker push harbor.od.com/infra/grafana:v5.4.2 ``` 准备目录 ``` mkdir /data/k8s-yaml/grafana cd /data/k8s-yaml/grafana ``` 准备rbac资源清单 cat rbac.yaml ``` apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: labels: addonmanager.kubernetes.io/mode: Reconcile kubernetes.io/cluster-service: "true" name: grafana rules: - apiGroups: - "*" resources: - namespaces - deployments - pods verbs: - get - list - watch --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: labels: addonmanager.kubernetes.io/mode: Reconcile kubernetes.io/cluster-service: "true" name: grafana roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: grafana subjects: - kind: User name: k8s-node ``` cat dp.yaml ``` apiVersion: extensions/v1beta1 kind: Deployment metadata: labels: app: grafana name: grafana name: grafana namespace: infra spec: progressDeadlineSeconds: 600 replicas: 1 revisionHistoryLimit: 7 selector: matchLabels: name: grafana strategy: rollingUpdate: maxSurge: 1 maxUnavailable: 1 type: RollingUpdate template: metadata: labels: app: grafana name: grafana spec: containers: - name: grafana image: harbor.od.com/infra/grafana:v5.4.2 imagePullPolicy: IfNotPresent ports: - containerPort: 3000 protocol: TCP volumeMounts: - mountPath: /var/lib/grafana name: data imagePullSecrets: - name: harbor securityContext: runAsUser: 0 volumes: - nfs: server: hdss-6.host.com path: /data/nfs-volume/grafana name: data ``` cat svc.yaml ``` apiVersion: v1 kind: Service metadata: name: grafana namespace: infra spec: ports: - port: 3000 protocol: TCP targetPort: 3000 selector: app: grafana ``` cat ingress.yaml ``` apiVersion: extensions/v1beta1 kind: Ingress metadata: name: grafana namespace: infra spec: rules: - host: grafana.od.com http: paths: - path: / backend: serviceName: grafana servicePort: 3000 ``` 域名解析 ``` vi /var/named/zq.com.zone grafana A 10.4.7.10 systemctl restart named ``` 应用资源配置清单 ``` kubectl apply -f http://k8s-yaml.od.com/grafana/rbac.yaml kubectl apply -f http://k8s-yaml.od.com/grafana/dp.yaml kubectl apply -f http://k8s-yaml.od.com/grafana/svc.yaml kubectl apply -f http://k8s-yaml.od.com/grafana/ingress.yaml ``` 进入容器安装插件 grafana确认启动好以后,需要进入grafana容器内部,安装以下插件 ``` kubectl -n infra exec -it grafana-d6588db94-xr4s6 /bin/bash # 以下命令在容器内执行 grafana-cli plugins install grafana-kubernetes-app grafana-cli plugins install grafana-clock-panel grafana-cli plugins install grafana-piechart-panel grafana-cli plugins install briangann-gauge-panel grafana-cli plugins install natel-discrete-panel ``` 添加数据源,依次点击:左侧锯齿图标-->add data source-->Prometheus ![](https://img.kancloud.cn/bd/d8/bdd8ca09fd5cc65a3a22685184b1208d_903x808.png) 添加完成后重启grafana ``` kubectl -n infra delete pod grafana-7dd95b4c8d-nj5cx ``` 添加K8S集群信息 启用K8S插件,依次点击:左侧锯齿图标-->Plugins-->kubernetes-->Enable 新建cluster,依次点击:左侧K8S图标-->New Cluster ![](https://img.kancloud.cn/f2/26/f226d8fd82a13c2ccb1100e7bf990bac_862x795.png) 添加完需要稍等几分钟,在没有取到数据之前,会报http forbidden,没关系,等一会就好。大概2-5分钟 ![](https://img.kancloud.cn/5f/0b/5f0b1c4830f0c0cdeba2141b4f48fcb9_931x700.png)