apiVersion: v1
kind: Template
metadata:
  name: prometheus
parameters:
- description: Prometheus image to use
  displayName : Image name
  name: IMAGE_NAME
  value: prom/prometheus:v2.0.0
objects:
- apiVersion: extensions/v1beta1
  kind: Deployment
  metadata:
    name: prometheus
  spec:
    replicas: 1
    template:
      metadata:
        labels:
          name: prometheus
      spec:
        serviceAccount: prometheus-server
        containers:
        - name: prometheus
          image: ${IMAGE_NAME}
          imagePullPolicy: IfNotPresent
          ports:
          - name: prometheus
            containerPort: 9090
            protocol: TCP
          volumeMounts:
          - mountPath: /prometheus
            name: prometheus-data
          - mountPath: /etc/prometheus
            name: prometheus-config
        volumes:
        - name: prometheus-data
          emptyDir: {}
        - name: prometheus-config
          configMap:
            name: prometheus-config
- apiVersion: v1
  kind: ConfigMap
  metadata:
    name: prometheus-config
  data:
    prometheus.yml: |
      global:
        scrape_interval: 15s
        evaluation_interval: 15s
      scrape_configs:
        - job_name: 'kafka_job'
          kubernetes_sd_configs:
            - role: pod
          relabel_configs:
            - source_labels: [__meta_kubernetes_pod_container_port_name]
              action: keep
              regex: kafkametrics.*
            - source_labels: [__meta_kubernetes_pod_name]
              action: replace
              target_label: kubernetes_pod_name
- apiVersion: v1
  kind: Service
  metadata:
    name: prometheus
  spec:
    ports:
    - name: prometheus
      port: 9090
      targetPort: 9090
      protocol: TCP
    selector:
      name: prometheus
    type: ClusterIP
