CC00025.CloudKubernetes——|Kubernetes&集群监控.V01|——|Prometheus&Grafana|

一、集群资源监控-监控品台搭建
二、实验环境部署
### --- 准备:下载下列文件并上传至服务器
~~~		configmap.yaml:存储相关的配置文件的存储
~~~		prometheus.deploy.yml:资源限制,端口号等信息点 
~~~		prometheus.svc.yml:对外暴露端口,进行外部访问
~~~		rbac-setup.yaml:分配访问权限
~~~		node-exporter.yaml:部署一个守护进程,

[root@k8s-master ~]# ls
三、部署守护进程
### --- 部署守护进程

[root@k8s-master ~]# vim node-exporter.yaml 

---
apiVersion: apps/v1                                     # 改一下版本
kind: DaemonSet
metadata:
  name: node-exporter
  namespace: kube-system
  labels:
    k8s-app: node-exporter
spec:
  selector:                                             # 添加这个模块
    matchLabels:
      k8s-app: node-exporter
  template:
    metadata:
      labels:
        k8s-app: node-exporter
    spec:
      containers:
      - image: prom/node-exporter
        name: node-exporter
        ports:
        - containerPort: 9100
          protocol: TCP
          name: http
---
apiVersion: v1
kind: Service
metadata:
  labels:
    k8s-app: node-exporter
  name: node-exporter
  namespace: kube-system
spec:
  ports:
  - name: http
    port: 9100
    nodePort: 31672
    protocol: TCP
  type: NodePort
  selector:
    k8s-app: node-exporter
~~~		创建执行

[root@k8s-master ~]# kubectl create -f node-exporter.yaml   
daemonset.apps/node-exporter created
service/node-exporter created
~~~		删除操作,不执行 

[root@k8s-master ~]# kubectl delete -f node-exporter.yaml   
daemonset.apps "node-exporter" deleted
service "node-exporter" deleted
### --- 部署其它的yaml文件
~~~		部署rbac

[root@k8s-master ~]# kubectl create -f rbac-setup.yaml 
clusterrole.rbac.authorization.k8s.io/prometheus created
serviceaccount/prometheus created
clusterrolebinding.rbac.authorization.k8s.io/prometheus created
~~~		部署configmap
 
[root@k8s-master ~]# kubectl create -f configmap.yaml 
configmap/prometheus-config created
四、部署prometheus
### --- 部署deployment

[root@k8s-master ~]# vim prometheus.deploy.yml 

---
apiVersion: apps/v1                             # 更改版本
kind: Deployment
metadata:
  labels:
    name: prometheus-deployment
  name: prometheus
  namespace: kube-system
spec:
  replicas: 1
  selector:
    matchLabels:
      app: prometheus
  template:
    metadata:
      labels:
        app: prometheus
    spec:
      containers:
      - image: prom/prometheus:v2.0.0
        name: prometheus
        command:
        - "/bin/prometheus"
        args:
        - "--config.file=/etc/prometheus/prometheus.yml"
        - "--storage.tsdb.path=/prometheus"
        - "--storage.tsdb.retention=24h"
        ports:
        - containerPort: 9090
          protocol: TCP
        volumeMounts:
        - mountPath: "/prometheus"
          name: data
        - mountPath: "/etc/prometheus"
          name: config-volume
        resources:
          requests:
            cpu: 100m
            memory: 100Mi
          limits:
            cpu: 500m
            memory: 2500Mi
      serviceAccountName: prometheus
      volumes:
      - name: data
        emptyDir: {}
      - name: config-volume
        configMap:
          name: prometheus-config
~~~		部署pod
[root@k8s-master ~]# kubectl create -f prometheus.deploy.yml 
deployment.apps/prometheus created
 
~~~		部署svc
[root@k8s-master ~]# kubectl create -f prometheus.svc.yml 
service/prometheus created
### --- 查看部署结果

[root@k8s-master ~]# kubectl get pods -n kube-system
prometheus-7486bf7f4b-88rvn          1/1     Running   0          92s
五、部署grafana
### --- 部署grafana:将下列文件上传至服务器
~~~		grafana-deploy.yaml:部署deploy应用
~~~		grafana-ing.yaml:对外暴露的端口  
~~~		grafana-svc.yaml:对外暴露的端口

[root@k8s-master ~]# ls
### --- 部署grafana-deploy

[root@k8s-master ~]# vim grafana-deploy.yaml 

apiVersion: apps/v1
kind: Deployment
metadata:
  name: grafana-core
  namespace: kube-system
  labels:
    app: grafana
    component: core
spec:
  replicas: 1
  selector:
    matchLabels:
        app: grafana
        component: core
  template:
    metadata:
      labels:
        app: grafana
        component: core
    spec:
      containers:
      - image: grafana/grafana:4.2.0
        name: grafana-core
        imagePullPolicy: IfNotPresent
        # env:
        resources:
          # keep request = limit to keep this container in guaranteed class
          limits:
            cpu: 100m
            memory: 100Mi
          requests:
            cpu: 100m
            memory: 100Mi
        env:
          # The following env variables set up basic auth twith the default admin user and admin password.
          - name: GF_AUTH_BASIC_ENABLED
            value: "true"
          - name: GF_AUTH_ANONYMOUS_ENABLED
            value: "false"
          # - name: GF_AUTH_ANONYMOUS_ORG_ROLE
          #   value: Admin
          # does not really work, because of template variables in exported dashboards:
          # - name: GF_DASHBOARDS_JSON_ENABLED
          #   value: "true"
        readinessProbe:
          httpGet:
            path: /login
            port: 3000
          # initialDelaySeconds: 30
          # timeoutSeconds: 1
        volumeMounts:
        - name: grafana-persistent-storage
          mountPath: /var
      volumes:
      - name: grafana-persistent-storage
        emptyDir: {}
~~~		部署grafana.pod

[root@k8s-master ~]# kubectl create -f grafana-deploy.yaml 
deployment.apps/grafana-core created
### --- 部署grafana-svc.yaml
[root@k8s-master ~]# kubectl create -f grafana-svc.yaml 
service/grafana created 
 
~~~		部署grafana-ing.yaml
[root@k8s-master ~]# kubectl create -f grafana-ing.yaml 
ingress.extensions/grafana created
### --- 查看

[root@k8s-master ~]# kubectl get pods -n kube-system
grafana-core-768b6bf79c-d4t6w        1/1     Running   0          73s
prometheus-7486bf7f4b-88rvn          1/1     Running   0          9m5s
### --- 打开Grafana,配置数据源,导入显示模板

[root@k8s-master ~]# kubectl get svc -n kube-system -o wide
grafana         NodePort    10.106.119.250   <none>        3000:30831/TCP           21s    app=grafana,component=core
prometheus      NodePort    10.111.81.144    <none>        9090:30003/TCP           48s    app=prometheus
六、grafana初始化配置
### --- grafana初始化配置 

~~~		通过Chrome访问:http://10.10.10.12:30831/login
~~~		# OR :http://10.10.10.13:32106/login
~~~		用户名:admin;密码:admin(图一)
### --- 添加初始配置(图二)

~~~		初始图标——>Data Sources——>Add data source:Name: mydb;
~~~		Type:prometheus;Url:http://10.111.81.144:9090:查看到prometheus的ip地址——>END
### --- 显示数据的模板

~~~		初始图标——>Dashboards——>Import——>Grafana.netDashboard:315(固定值)
~~~		——>Load——>Name:kubernetes cluster monitoring (via Promentheus)可以更改
~~~		——>Import——>Prometheus:mydb(刚才创建的数据源)——>Import——>END
~~~		若是ID导入失败可在官网下载*.json文件导入
~~~		官网地址:https://grafana.com/grafana/dashboards/1860?pg=dashboards&plcmt=featured-sub1
grafana初始界面
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

yanqi_vip

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值