본문 바로가기
클라우드/prometheus

kubernetes service discover 설정

by "뭉치" 2021. 10. 4.
728x90
Prometheus 이미지 빌드
https://prometheus.io/docs/prometheus/latest/configuration/configuration/

 

Dockerfile

 

FROM prom/prometheus:v2.19.0
ADD prometheus.yml /etc/prometheus/prometheus.yml

 

prometheus.yml

 

# my global config
global:
  scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).
 
# Alertmanager configuration
alerting:
  alertmanagers:
  - static_configs:
    - targets:
      # - alertmanager:9093
 
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"
 
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'prometheus'
 
    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.
 
    static_configs:
    - targets: ['localhost:9090']
 
  - job_name: 'keycloak'
 
    metrics_path: '/auth/realms/master/metrics'
    scheme: 'https'
 
    static_configs:
    - targets: ['sso.multi.com']
 
  - job_name: 'kubernetes-replicas-keycloak'
    metrics_path: '/auth/realms/master/metrics'
    kubernetes_sd_configs:
    - api_server: '{serverIP}.com'
      role: pod
      tls_config:
        insecure_skip_verify: true
    relabel_configs:
#    - action: labelmap
#      regex: __meta_kubernetes_node_label_(.+)
    - source_labels: [__meta_kubernetes_namespace]
      action: keep
      regex: default
    - source_labels: [__meta_kubernetes_pod_name]
      target_label: pod
      action: keep
      regex: replicas-test-keycloak(.*)
prometheus 실행

deployments.yaml

 

# kubectl create -f deployments.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: prometheus-test
  namespace: default
  labels:
    app: prometheus-test
spec:
  replicas: 1
  selector:
    matchLabels:
      app: prometheus-test
  template:
    metadata:
      labels:
        app: prometheus-test
    spec:
      containers:
      - name: prometheus-test
        image: jonghunparksk/prometheus-v2_19_0-dt:0.0.1
        imagePullPolicy: Always
prometheus 관리(확인)용 Service 생성
# kubectl create -f service.yaml

apiVersion: v1
kind: Service
metadata:
  name: prometheus-test
  labels:
    app: prometheus-test
spec:
  ports:
  - name: http
    port: 9090
    targetPort: 9090
  selector:
    app: prometheus-test
  type: LoadBalancer

 

728x90

댓글