k8s v1.14 prometheus

Prometheus、Grafana 部署

        Grafana是一个开源的度量分析与可视化套件。经常被用作基础设施的时间序列数据和应用程序分析的可视化,我们这里用它来做Kubernetes集群监控数据的可视化。

准备工作

        截至当前,prometheus、grafana均采用最新的镜像包,在在第一次部署的时候grafana报了一个错误mkdir: cannot create directory '/var/lib/grafana/plugins': No such file or directory,这是因为Grafana启动使用的用户和用户组都是472,造成对外挂存储没有权限。参考官方

开始部署

新建yaml文件

  • monitor-namespace.yaml
    1
    2
    3
    4
    5
    # cat  monitor-namespace.yaml 
    apiVersion: v1
    kind: Namespace
    metadata:
    name: monitoring

其他的文件均采用以前历史的,然后稍加修改,其他yaml文件,移除grafana-ingress.yamlprometheus-ingress.yaml

文件修改

  • grafana-deploy.yaml

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    apiVersion: extensions/v1beta1
    kind: Deployment
    metadata:
    name: grafana-core
    namespace: monitoring
    labels:
    app: grafana
    component: core
    spec:
    replicas: 1
    template:
    metadata:
    labels:
    app: grafana
    component: core
    spec:
    containers:
    - image: grafana/grafana:latest
    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/lib/grafana
    volumes:
    - name: grafana-persistent-storage
    emptyDir: {}
  • prometheus-deploy.yaml

    1
    2
    3
    4
    5
    6
    spec:
    containers:
    - image: prom/prometheus:latest
    name: prometheus
    command:
    - "/bin/prometheus"
  • prometheus-svc.yaml

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    ---
    kind: Service
    apiVersion: v1
    metadata:
    labels:
    app: prometheus
    name: prometheus
    namespace: monitoring
    spec:
    #type: NodePort
    ports:
    - port: 9090
    targetPort: 9090
    #nodePort: 30005
    selector:
    app: prometheus
  • grafana-svc.yaml

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    # cat grafana-svc.yaml
    apiVersion: v1
    kind: Service
    metadata:
    name: grafana
    namespace: monitoring
    labels:
    app: grafana
    component: core
    spec:
    #type: NodePort
    ports:
    - port: 3000
    selector:
    app: grafana
    component: core

执行创建

1
2
3
# kubectl apply -f ./

# 多执行几次

检查部署

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# kubectl get pod,svc,deploy -n monitoring
NAME READY STATUS RESTARTS AGE
pod/grafana-core-7b5989cf9d-snbk5 1/1 Running 0 2m31s
pod/node-exporter-dddv7 1/1 Running 0 12m
pod/node-exporter-fhfp6 1/1 Running 0 12m
pod/node-exporter-m46bf 1/1 Running 0 12m
pod/node-exporter-xkrzp 1/1 Running 0 12m
pod/node-exporter-zfcxh 1/1 Running 0 12m
pod/prometheus-67bcf457db-999ns 1/1 Running 0 12m

NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/grafana ClusterIP 10.254.95.151 <none> 3000/TCP 12m
service/node-exporter ClusterIP 10.254.114.12 <none> 9100/TCP 12m
service/prometheus ClusterIP 10.254.104.216 <none> 9090/TCP 12m

NAME READY UP-TO-DATE AVAILABLE AGE
deployment.extensions/grafana-core 1/1 1 1 12m
deployment.extensions/prometheus 1/1 1 1 12m

创建Ingress

prometheus Ingress

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# cat prometheus-Ingress.yaml 
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: prometheus-web-ui
namespace: monitoring
annotations:
kubernetes.io/ingress.class: traefik
spec:
rules:
- host: prometheus.xxlaila.cn
http:
paths:
- path: /
backend:
serviceName: prometheus
servicePort: 9090

grafana Ingress

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# cat grafana-Ingress.yaml 
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: grafana-web-ui
namespace: monitoring
annotations:
kubernetes.io/ingress.class: traefik
spec:
rules:
- host: grafana.xxlaila.cn
http:
paths:
- path: /
backend:
serviceName: grafana
servicePort: 3000

执行创建

1
2
3
4
5
# kubectl apply -f prometheus-Ingress.yaml 
ingress.extensions/prometheus-web-ui created

# kubectl apply -f grafana-Ingress.yaml
ingress.extensions/grafana-web-ui created

在浏览器输入prometheus.xxlaila.cn访问prometheus,输入grafana.xxlaila.cn访问grafana。

访问prometheus

img

配置grafana

img

到grafana的官方下载对应的模版文件导入,就可以出图啦
img

后续利用pvc

坚持原创技术分享,您的支持将鼓励我继续创作!
0%