|
| 1 | +apiVersion: v1 |
| 2 | +kind: Namespace |
| 3 | +metadata: |
| 4 | + name: ${KUBE_NAMESPACE} |
| 5 | +--- |
| 6 | +apiVersion: rbac.authorization.k8s.io/v1beta1 |
| 7 | +kind: ClusterRole |
| 8 | +metadata: |
| 9 | + name: prometheus |
| 10 | +rules: |
| 11 | +- apiGroups: [""] |
| 12 | + resources: |
| 13 | + - nodes |
| 14 | + - nodes/proxy |
| 15 | + - services |
| 16 | + - endpoints |
| 17 | + - pods |
| 18 | + verbs: ["get", "list", "watch"] |
| 19 | +- apiGroups: |
| 20 | + - extensions |
| 21 | + resources: |
| 22 | + - ingresses |
| 23 | + verbs: ["get", "list", "watch"] |
| 24 | +- nonResourceURLs: ["/metrics"] |
| 25 | + verbs: ["get"] |
| 26 | +--- |
| 27 | +apiVersion: v1 |
| 28 | +kind: ServiceAccount |
| 29 | +metadata: |
| 30 | + name: prometheus |
| 31 | + namespace: ${KUBE_NAMESPACE} |
| 32 | +--- |
| 33 | +apiVersion: rbac.authorization.k8s.io/v1beta1 |
| 34 | +kind: ClusterRoleBinding |
| 35 | +metadata: |
| 36 | + name: prometheus |
| 37 | +roleRef: |
| 38 | + apiGroup: rbac.authorization.k8s.io |
| 39 | + kind: ClusterRole |
| 40 | + name: prometheus |
| 41 | +subjects: |
| 42 | +- kind: ServiceAccount |
| 43 | + name: prometheus |
| 44 | + namespace: ${KUBE_NAMESPACE} |
| 45 | +--- |
| 46 | +apiVersion: v1 |
| 47 | +kind: Service |
| 48 | +metadata: |
| 49 | + labels: |
| 50 | + app: prometheus-k8s |
| 51 | + annotations: |
| 52 | + prometheus.io/scrape: 'true' |
| 53 | + prometheus.io/port: '9090' |
| 54 | + prometheus.io/port2: '9091' |
| 55 | + name: prometheus-k8s |
| 56 | + namespace: ${KUBE_NAMESPACE} |
| 57 | +spec: |
| 58 | + type: LoadBalancer |
| 59 | + externalTrafficPolicy: Cluster |
| 60 | + ports: |
| 61 | + - name: prometheus |
| 62 | + nodePort: 32387 |
| 63 | + port: 9090 |
| 64 | + protocol: TCP |
| 65 | + targetPort: 9090 |
| 66 | + - name: sidecar |
| 67 | + nodePort: 30182 |
| 68 | + port: 9091 |
| 69 | + protocol: TCP |
| 70 | + targetPort: 9091 |
| 71 | + selector: |
| 72 | + app: prometheus |
| 73 | + prometheus: k8s |
| 74 | + sessionAffinity: None |
| 75 | +--- |
| 76 | +apiVersion: apps/v1beta2 |
| 77 | +kind: Deployment |
| 78 | +metadata: |
| 79 | + name: prometheus-k8s |
| 80 | + namespace: ${KUBE_NAMESPACE} |
| 81 | + labels: |
| 82 | + app: prometheus |
| 83 | + prometheus: k8s |
| 84 | +spec: |
| 85 | + replicas: 1 |
| 86 | + selector: |
| 87 | + matchLabels: |
| 88 | + app: prometheus |
| 89 | + prometheus: k8s |
| 90 | + template: |
| 91 | + metadata: |
| 92 | + labels: |
| 93 | + app: prometheus |
| 94 | + prometheus: k8s |
| 95 | + spec: |
| 96 | + serviceAccount: prometheus |
| 97 | + securityContext: |
| 98 | + runAsUser: 0 |
| 99 | + containers: |
| 100 | + - name: prometheus |
| 101 | + image: quay.io/prometheus/prometheus:v2.4.3 |
| 102 | + imagePullPolicy: Always |
| 103 | + args: |
| 104 | + - "--config.file=/etc/prometheus/config/prometheus.yaml" |
| 105 | + - "--storage.tsdb.path=/data" |
| 106 | + - "--storage.tsdb.min-block-duration=15m" |
| 107 | + - "--storage.tsdb.max-block-duration=4h" |
| 108 | + - "--storage.tsdb.retention=48h" |
| 109 | + ports: |
| 110 | + - name: prometheus |
| 111 | + containerPort: 9090 |
| 112 | + volumeMounts: |
| 113 | + - name: config-volume |
| 114 | + mountPath: /etc/prometheus/config |
| 115 | + - name: data-volume |
| 116 | + mountPath: /data |
| 117 | + volumes: |
| 118 | + - name: config-volume |
| 119 | + configMap: |
| 120 | + name: prometheus-k8s |
| 121 | + - name: data-volume |
| 122 | + emptyDir: {} |
| 123 | + terminationGracePeriodSeconds: 300 |
| 124 | +--- |
| 125 | +apiVersion: v1 |
| 126 | +kind: ConfigMap |
| 127 | +metadata: |
| 128 | + name: prometheus-k8s |
| 129 | + namespace: ${KUBE_NAMESPACE} |
| 130 | +data: |
| 131 | + prometheus.yaml: | |
| 132 | + scrape_configs: |
| 133 | + - job_name: kubernetes-apiservers |
| 134 | + kubernetes_sd_configs: |
| 135 | + - role: endpoints |
| 136 | + relabel_configs: |
| 137 | + - action: keep |
| 138 | + regex: default;kubernetes;https |
| 139 | + source_labels: |
| 140 | + - __meta_kubernetes_namespace |
| 141 | + - __meta_kubernetes_service_name |
| 142 | + - __meta_kubernetes_endpoint_port_name |
| 143 | + scheme: https |
| 144 | + tls_config: |
| 145 | + ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt |
| 146 | + insecure_skip_verify: true |
| 147 | + bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token |
| 148 | +
|
| 149 | + - job_name: kubernetes-nodes-kubelet |
| 150 | + kubernetes_sd_configs: |
| 151 | + - role: node |
| 152 | + relabel_configs: |
| 153 | + - target_label: __address__ |
| 154 | + regex: "(.+):10250" |
| 155 | + source_labels: [__address__] |
| 156 | + replacement: "${1}:10255" |
| 157 | +
|
| 158 | + - job_name: kubernetes-nodes-cadvisor |
| 159 | + kubernetes_sd_configs: |
| 160 | + - role: node |
| 161 | + relabel_configs: |
| 162 | + - target_label: __metrics_path__ |
| 163 | + replacement: /metrics/cadvisor |
| 164 | + - target_label: __address__ |
| 165 | + regex: "(.+):10250" |
| 166 | + source_labels: [__address__] |
| 167 | + replacement: "${1}:10255" |
| 168 | +
|
| 169 | + # Configuration for the first port (prometheus.io/port) that service |
| 170 | + # endpoints are annotated with. |
| 171 | + - job_name: kubernetes-service-endpoints1 |
| 172 | + kubernetes_sd_configs: |
| 173 | + - role: endpoints |
| 174 | + relabel_configs: |
| 175 | + - action: keep |
| 176 | + regex: true |
| 177 | + source_labels: |
| 178 | + - __meta_kubernetes_service_annotation_prometheus_io_scrape |
| 179 | + - action: replace |
| 180 | + regex: (https?) |
| 181 | + source_labels: |
| 182 | + - __meta_kubernetes_service_annotation_prometheus_io_scheme |
| 183 | + target_label: __scheme__ |
| 184 | + - action: replace |
| 185 | + regex: (.+) |
| 186 | + source_labels: |
| 187 | + - __meta_kubernetes_service_annotation_prometheus_io_path |
| 188 | + target_label: __metrics_path__ |
| 189 | + - action: replace |
| 190 | + regex: ([^:]+)(?::\d+)?;(\d+) |
| 191 | + replacement: $1:$2 |
| 192 | + source_labels: |
| 193 | + - __address__ |
| 194 | + - __meta_kubernetes_service_annotation_prometheus_io_port |
| 195 | + target_label: __address__ |
| 196 | + - action: replace |
| 197 | + source_labels: |
| 198 | + - __meta_kubernetes_namespace |
| 199 | + target_label: k8s_namespace |
| 200 | + - action: replace |
| 201 | + source_labels: |
| 202 | + - __meta_kubernetes_service_name |
| 203 | + target_label: k8s_service |
| 204 | + - action: replace |
| 205 | + source_labels: |
| 206 | + - __meta_kubernetes_pod_name |
| 207 | + target_label: k8s_pod |
| 208 | +
|
| 209 | + # Configuration for the seocnd port (prometheus.io/port2) that service |
| 210 | + # endpoints are annotated with. |
| 211 | + - job_name: kubernetes-service-endpoints2 |
| 212 | + kubernetes_sd_configs: |
| 213 | + - role: endpoints |
| 214 | + relabel_configs: |
| 215 | + - action: keep |
| 216 | + regex: true |
| 217 | + source_labels: |
| 218 | + - __meta_kubernetes_service_annotation_prometheus_io_scrape |
| 219 | + - action: replace |
| 220 | + regex: (https?) |
| 221 | + source_labels: |
| 222 | + - __meta_kubernetes_service_annotation_prometheus_io_scheme |
| 223 | + target_label: __scheme__ |
| 224 | + - action: replace |
| 225 | + regex: (.+) |
| 226 | + source_labels: |
| 227 | + - __meta_kubernetes_service_annotation_prometheus_io_path |
| 228 | + target_label: __metrics_path__ |
| 229 | + - action: keep |
| 230 | + source_labels: |
| 231 | + - __meta_kubernetes_service_annotation_prometheus_io_port2 |
| 232 | + regex: .+ |
| 233 | + - action: replace |
| 234 | + regex: ([^:]+)(?::\d+)?;(\d+) |
| 235 | + replacement: $1:$2 |
| 236 | + source_labels: |
| 237 | + - __address__ |
| 238 | + - __meta_kubernetes_service_annotation_prometheus_io_port2 |
| 239 | + target_label: __address__ |
| 240 | + - action: replace |
| 241 | + source_labels: |
| 242 | + - __meta_kubernetes_namespace |
| 243 | + target_label: k8s_namespace |
| 244 | + - action: replace |
| 245 | + source_labels: |
| 246 | + - __meta_kubernetes_service_name |
| 247 | + target_label: k8s_service |
| 248 | + - action: replace |
| 249 | + source_labels: |
| 250 | + - __meta_kubernetes_pod_name |
| 251 | + target_label: k8s_pod |
0 commit comments