grafana-svc.yaml
apiVersion: v1 kind: Service metadata: name: grafana namespace: kube-system labels: app: grafana component: core spec: type: NodePort ports: - port: 3000 selector: app: grafana component: coregrafana-ing.yaml
apiVersion: extensions/v1beta1 kind: Ingress metadata: name: grafana namespace: kube-system spec: rules: - host: k8s.grafana http: paths: - path: / backend: serviceName: grafana servicePort: 3000 [root@master pgmonitor]# cd grafana/ [root@master grafana]# ls grafana-deploy.yaml grafana-ing.yaml grafana-svc.yaml [root@master grafana]# vim grafana-deploy.yaml [root@master grafana]# kubectl create -f grafana-deploy.yaml deployment.apps/grafana-core created [root@master grafana]# kubectl create -f grafana-svc.yaml service/grafana created [root@master grafana]# kubectl create -f grafana-ing.yaml Warning: extensions/v1beta1 Ingress is deprecated in v1.14+, unavailable in v1.22+; use networking.k8s.io/v1 Ingress ingress.extensions/grafana created [root@master grafana]# kubectl get pods -n kube-system NAME READY STATUS RESTARTS AGE coredns-7f89b7bc75-jx925 1/1 Running 3 7d19h coredns-7f89b7bc75-pml7q 1/1 Running 3 7d19h etcd-master 1/1 Running 9 7d19h grafana-core-6d6fb7566-fzmfz 1/1 Running 0 13m kube-apiserver-master 1/1 Running 9 7d19h kube-controller-manager-master 1/1 Running 0 5d kube-flannel-ds-7kmgr 1/1 Running 3 7d19h kube-flannel-ds-hmqcw 1/1 Running 4 7d19h kube-flannel-ds-mql8h 1/1 Running 11 7d19h kube-flannel-ds-x565h 1/1 Running 3 7d19h kube-proxy-cgh25 1/1 Running 3 7d19h kube-proxy-lt5d7 1/1 Running 5 7d19h kube-proxy-nlqrt 1/1 Running 3 7d19h kube-proxy-vw255 1/1 Running 10 7d19h kube-scheduler-master 1/1 Running 0 5d node-exporter-5cdp9 1/1 Running 0 38m node-exporter-ggnxc 1/1 Running 0 38m node-exporter-tv8ld 1/1 Running 0 38m prometheus-68546b8d9-zwd4h 1/1 Running 0 27m [root@master grafana]#第三步 打开Granfana,配置数据源,导入显示模板
[root@master grafana]# kubectl get svc -n kube-system NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE grafana NodePort 10.100.244.146 <none> 3000:30181/TCP 17m kube-dns ClusterIP 10.96.0.10 <none> 53/UDP,53/TCP,9153/TCP 7d19h node-exporter NodePort 10.99.111.152 <none> 9100:31672/TCP 43m prometheus NodePort 10.102.170.71 <none> 9090:30003/TCP 31m [root@master grafana]# kubectl get svc -n kube-system -o wide NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR grafana NodePort 10.100.244.146 <none> 3000:30181/TCP 22m app=grafana,component=core kube-dns ClusterIP 10.96.0.10 <none> 53/UDP,53/TCP,9153/TCP 7d20h k8s-app=kube-dns node-exporter NodePort 10.99.111.152 <none> 9100:31672/TCP 48m k8s-app=node-exporter prometheus NodePort 10.102.170.71 <none> 9090:30003/TCP 36m app=prometheus通过查看端口号访问:
默认的用户名和密码都是admin
配置数据源,使用prometheus
设置显示数据的模板 315固定的值