0
点赞
收藏
分享

微信扫一扫

prometheus + consul 实现服务自动发现

岁月不饶人老不正经 2022-02-21 阅读 78

prometheus + consul 实现服务自动发现

一. 为什么要引入consul

在没有使用 consul 服务自动发现的时候,我们需要频繁对 Prometheus 配置文件进行修改,无疑给运维人员带来很大的负担,还有可能直接变成一个"配置达人",即使是配置达人也会存在人为失误的情况。

二. 安装consul

  1. 添加其所需要的helm repo源

    helm repo add bitnami  https://charts.bitnami.com/bitnami
    
  2. 将chart 文件拉取下来进行修改,并进行安装

    helm pull bitnami/consul 
    helm install -f values.yaml  consul --n consul .
    
  3. 查看其pod状态是否running

    [baozx@VM_192_5_centos ~]$ kubectl get pods -n consul
    NAME                                      READY   STATUS    RESTARTS   AGE
    consul-server-0                           1/1     Running   0          5d22h
    consul-server-1                           1/1     Running   0          5d22h
    consul-server-2                           1/1     Running   0          5d22h
    
  4. 查看其svc的状态

    [baozx@VM_192_5_centos ~]$ kubectl get svc  -n consul
    NAME                     TYPE           CLUSTER-IP       EXTERNAL-IP    PORT(S)                                                       AGE
    consul-server            LoadBalancer   172.19.255.19    10.1.193.63    8500:30736/TCP,8301:31655/TCP,8302:31793/TCP,8300:31421/TCP   
    consul-ui                ClusterIP      172.19.253.231   <none>         80/TCP                                               
    

三. 安装Prometheus

  1. 添加其所需要的helm repo 源

    helm repo add prometheus-community 	https://prometheus-community.github.io/helm-charts
    
  2. 将chart文件拉取本地修改value文件进行安装(这里只展示所需要的consul配置)

    helm pull prometheus-community/prometheus 
    
     - job_name: 'consul'
            consul_sd_configs:
              - server: '10.1.193.63:8500'
                services: []
            relabel_configs:
              - source_labels: ['__meta_consul_service']
                regex: "consul"  #匹配为"consul" 的service
                action: drop       # 执行的动作
    
     helm install prometheus  -f values.yaml  . -n prometheus
    
  3. 查看其pod状态是否running

    [baozx@VM_192_5_centos prometheus.bak]$ kubectl get pods -n prometheus
    NAME                                 READY   STATUS    RESTARTS   AGE
    prometheus-server-5f4b5599d4-sn7wk   2/2     Running   0          2d20h
    
  4. 为其配置ingress 可以通过外网访问

    [baozx@VM_192_5_centos ~]$ kubectl get ingress -n prometheus prometheus -o yaml
    apiVersion: extensions/v1beta1
    kind: Ingress
    metadata:
      annotations:
        kubernetes.io/ingress.class: nginx
      name: prometheus
      namespace: prometheus
    spec:
      rules:
      - host: prometheus.prod.weike.fm
        http:
          paths:
          - backend:
              serviceName: prometheus-server
              servicePort: 80
            path: /
    
  5. 查看consul 数据源是否已经被发现

举报

相关推荐

0 条评论