EUGENIO SOUZA CARVALHO 3 years ago
parent
commit
4ffe797ea0

+ 4 - 0
monitoring/001-namespace.yaml

@@ -0,0 +1,4 @@
+apiVersion: v1
+kind: Namespace
+metadata:
+ name: monitoring

+ 111 - 0
monitoring/002-prometheus-deploy.yaml

@@ -0,0 +1,111 @@
+---
+###################################################
+# Prometeus Service Account
+###################################################
+apiVersion: v1
+kind: ServiceAccount
+metadata:
+  name: prometheus
+  namespace: monitoring
+
+
+
+---
+###################################################
+# Prometeus Roles
+###################################################
+apiVersion: rbac.authorization.k8s.io/v1beta1
+kind: ClusterRole
+metadata:
+  name: prometheus
+  namespace: monitoring
+rules:
+- apiGroups: [""]
+  resources:
+  - nodes
+  - nodes/proxy
+  - services
+  - endpoints
+  - pods
+  verbs: ["get", "list", "watch"]
+- apiGroups:
+  - extensions
+  resources:
+  - ingresses
+  verbs: ["get", "list", "watch"]
+- nonResourceURLs: ["/metrics"]
+  verbs: ["get"]
+---
+apiVersion: rbac.authorization.k8s.io/v1beta1
+kind: ClusterRoleBinding
+metadata:
+  name: prometheus
+roleRef:
+  apiGroup: rbac.authorization.k8s.io
+  kind: ClusterRole
+  name: prometheus
+subjects:
+- kind: ServiceAccount
+  name: prometheus
+  namespace: monitoring
+
+
+---
+###################################################
+# Prometeus Deployment
+###################################################
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: prometheus
+  namespace: monitoring
+  labels:
+    #name: prometheus
+    app: prometheus
+spec:
+  replicas: 1
+  selector:
+    matchLabels:
+      app: prometheus
+  template:
+    metadata:
+      labels:
+        app: prometheus
+    spec:
+      serviceAccountName: prometheus
+      containers:
+      - name: prometheus
+        image: prom/prometheus:v2.1.0
+        imagePullPolicy: Always
+        ports:
+        - containerPort: 9090
+          protocol: TCP
+        volumeMounts:
+        - mountPath: "/etc/prometheus"
+          name: config-prometheus
+      volumes:
+      - name: config-prometheus
+        configMap:
+          name: prometheus-config
+
+
+
+
+---
+###################################################
+# Prometeus Service
+###################################################
+apiVersion: v1
+kind: Service
+metadata:
+  name: prometheus
+  namespace: monitoring
+spec:
+  type: ClusterIP
+  ports:
+  - port: 9090
+    targetPort: 9090
+  selector:
+    app: prometheus
+
+

+ 62 - 0
monitoring/003-prometheus-config.yaml

@@ -0,0 +1,62 @@
+apiVersion: v1
+kind: ConfigMap
+metadata:
+ name: prometheus-config
+ namespace: monitoring
+data:
+ prometheus.yml: |
+  global:
+  scrape_configs:
+   - job_name: 'kubernetes-kubelet'
+     scheme: https
+     tls_config:
+       ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
+       insecure_skip_verify: true
+     bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
+     kubernetes_sd_configs:
+     - role: node
+     relabel_configs:
+     - action: labelmap
+       regex: __meta_kubernetes_node_label_(.+)
+     - target_label: __address__
+       replacement: kubernetes.default.svc.cluster.local:443
+     - source_labels: [__meta_kubernetes_node_name]
+       regex: (.+)
+       target_label: __metrics_path__
+       replacement: /api/v1/nodes/${1}/proxy/metrics
+   - job_name: 'kubernetes-cadvisor'
+     scheme: https
+     tls_config:
+       ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
+       insecure_skip_verify: true
+     bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
+     kubernetes_sd_configs:
+     - role: node
+     relabel_configs:
+     - action: labelmap
+       regex: __meta_kubernetes_node_label_(.+)
+     - target_label: __address__
+       replacement: kubernetes.default.svc.cluster.local:443
+     - source_labels: [__meta_kubernetes_node_name]
+       regex: (.+)
+       target_label: __metrics_path__
+       replacement: /api/v1/nodes/${1}/proxy/metrics/cadvisor
+   - job_name: 'kubernetes-kube-state'
+     kubernetes_sd_configs:
+     - role: pod
+     relabel_configs:
+     - action: labelmap
+       regex: __meta_kubernetes_pod_label_(.+)
+     - source_labels: [__meta_kubernetes_namespace]
+       action: replace
+       target_label: kubernetes_namespace
+     - source_labels: [__meta_kubernetes_pod_name]
+       action: replace
+       target_label: kubernetes_pod_name
+     - source_labels: [__meta_kubernetes_pod_label_grafanak8sapp]
+       regex: .*true.*
+       action: keep
+     - source_labels: ['__meta_kubernetes_pod_label_daemon', '__meta_kubernetes_pod_node_name']
+       regex: 'node-exporter;(.*)'
+       action: replace
+       target_label: nodename

+ 45 - 0
monitoring/004-node-exporter.yaml

@@ -0,0 +1,45 @@
+kind: DaemonSet
+apiVersion: apps/v1 
+metadata: 
+  name: node-exporter
+  namespace: monitoring
+spec: 
+  selector: 
+    matchLabels: 
+      daemon: node-exporter
+      grafanak8sapp: "true"
+  template: 
+    metadata: 
+      name: node-exporter
+      labels: 
+        daemon: node-exporter
+        grafanak8sapp: "true"
+    spec: 
+      volumes: 
+      - name: proc
+        hostPath: 
+          path: /proc
+      - name: sys
+        hostPath: 
+          path: /sys
+      containers: 
+      - name: node-exporter
+        image: quay.io/prometheus/node-exporter:v0.15.0
+        args: 
+          - --path.procfs=/proc_host
+          - --path.sysfs=/host_sys
+        ports: 
+          - name: node-exporter
+            hostPort: 9100
+            containerPort: 9100
+        volumeMounts: 
+          - name: sys
+            readOnly: true
+            mountPath: /host_sys
+          - name: proc
+            readOnly: true
+            mountPath: /proc_host
+        imagePullPolicy: IfNotPresent
+      restartPolicy: Always
+      hostNetwork: true
+      hostPID: true

+ 147 - 0
monitoring/005-state-metrics-deploy.yaml

@@ -0,0 +1,147 @@
+
+---
+###################################################
+# kube-state-metrics Roles
+###################################################
+apiVersion: rbac.authorization.k8s.io/v1
+kind: Role
+metadata:
+  namespace: monitoring
+  name: kube-state-metrics
+rules:
+- apiGroups: [""]
+  resources:
+  - pods
+  verbs: ["get"]
+- apiGroups: ["extensions"]
+  resources:
+  - deployments
+  resourceNames: ["kube-state-metrics"]
+  verbs: ["get", "update"]
+---
+
+apiVersion: rbac.authorization.k8s.io/v1
+kind: RoleBinding
+metadata:
+  name: kube-state-metrics
+  namespace: monitoring
+roleRef:
+  apiGroup: rbac.authorization.k8s.io
+  kind: Role
+  name: kube-state-metrics
+subjects:
+- kind: ServiceAccount
+  name: kube-state-metrics
+  namespace: monitoring
+---
+
+apiVersion: rbac.authorization.k8s.io/v1
+kind: ClusterRole
+metadata:
+  name: kube-state-metrics
+  namespace: monitoring
+rules:
+- apiGroups: [""]
+  resources:
+  - nodes
+  - pods
+  - services
+  - resourcequotas
+  - replicationcontrollers
+  - limitranges
+  - persistentvolumeclaims
+  - persistentvolumes
+  - namespaces
+  - endpoints
+  verbs: ["list", "watch"]
+- apiGroups: ["extensions"]
+  resources:
+  - daemonsets
+  - deployments
+  - replicasets
+  verbs: ["list", "watch"]
+- apiGroups: ["apps"]
+  resources:
+  - statefulsets
+  verbs: ["list", "watch"]
+- apiGroups: ["batch"]
+  resources:
+  - cronjobs
+  - jobs
+  verbs: ["list", "watch"]
+- apiGroups: ["autoscaling"]
+  resources:
+  - horizontalpodautoscalers
+  verbs: ["list", "watch"]
+- apiGroups: ["policy"]
+  resources:
+  - poddisruptionbudgets
+  verbs: ["list", "watch"]
+---
+
+apiVersion: rbac.authorization.k8s.io/v1 
+kind: ClusterRoleBinding
+metadata:
+  name: kube-state-metrics
+  namespace: monitoring
+roleRef:
+  apiGroup: rbac.authorization.k8s.io
+  kind: ClusterRole
+  name: kube-state-metrics
+subjects:
+- kind: ServiceAccount
+  name: kube-state-metrics
+  namespace: monitoring
+
+
+
+
+---
+###################################################
+# kube-state-metrics ServiceAccount
+###################################################
+apiVersion: v1
+kind: ServiceAccount
+metadata:
+  name: kube-state-metrics
+  namespace: monitoring
+
+
+
+
+
+---
+###################################################
+# kube-state-metrics Deployment
+###################################################
+apiVersion: apps/v1
+kind: Deployment
+metadata: 
+  name: kube-state-metrics
+  namespace: monitoring
+spec: 
+  selector: 
+    matchLabels: 
+      app: kube-state-metrics 
+      grafanak8sapp: "true" 
+  replicas: 1
+  template: 
+    metadata: 
+      labels: 
+        app: kube-state-metrics 
+        grafanak8sapp: "true"
+    spec: 
+      serviceAccountName: kube-state-metrics
+      containers: 
+      - name: kube-state-metrics
+        image: quay.io/coreos/kube-state-metrics:v1.1.0
+        ports: 
+        - name: http-metrics
+          containerPort: 8080
+        readinessProbe: 
+          httpGet: 
+            path: /healthz
+            port: 8080
+          initialDelaySeconds: 5
+          timeoutSeconds: 5  
+

+ 45 - 0
monitoring/008-grafana.yaml

@@ -0,0 +1,45 @@
+
+
+---
+###################################################
+# Grafana Deployment
+###################################################
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: grafana
+  namespace: monitoring
+  labels:
+    app: grafana
+spec:
+  replicas: 1
+  selector:
+    matchLabels:
+      app: grafana
+
+  template:
+    metadata:
+     labels:
+       app: grafana
+
+    spec:
+      containers:
+      - name: grafana
+        image: grafana/grafana
+        ports:
+        - containerPort: 3000
+          protocol: TCP
+        env:
+        - name: GF_SERVER_HTTP_PORT
+          value: "3000"
+        - name: GF_INSTALL_PLUGINS
+          value: "grafana-kubernetes-app"
+        volumeMounts:
+        - mountPath: /var/lib/grafana
+          name: grafana-storage
+      volumes:
+      - name: grafana-storage
+        emptyDir: {}
+
+
+

+ 36 - 0
monitoring/009-grafana-ingress.yaml

@@ -0,0 +1,36 @@
+---
+###################################################
+# Grafana Service
+###################################################
+apiVersion: v1
+kind: Service
+metadata:
+  name: grafana
+  namespace: monitoring
+spec:
+  type: ClusterIP
+  ports:
+  - port: 3000
+    targetPort: 3000
+  selector:
+    app: grafana
+
+
+---
+###################################################
+# Grafana Ingres
+###################################################
+kind: Ingress
+apiVersion: networking.k8s.io/v1beta1
+metadata:
+  name: grafana
+  namespace: monitoring
+spec:
+  rules:
+  - host: grafana.k8s.eugeniocarvalho.dev
+    http:
+      paths:
+      - path: /
+        backend:
+          serviceName: grafana
+          servicePort: 3000

+ 21 - 0
monitoring/README.md

@@ -0,0 +1,21 @@
+# Monitoring
+
+This stack provides a Prometheus and a Grafana Service for monitoring the *Imixs-Cloud*. You can find general information about Imixs-Cloud monitoring [here](../../doc/MONITORING.md). 
+
+
+## Configuration
+
+Before you start edit the file 009-grafana-ingress.yaml and replace 
+
+replace *{YOUR-HOST-NAME}* with a Internet name pointing to your Master Node configured in your DNS 
+
+
+## Deployment
+
+Next run:
+
+	$ kubectl apply -f management/monitoring/
+
+to undeploy traefik.io run:
+
+	$ kubectl delete -f management/monitoring/

File diff suppressed because it is too large
+ 1574 - 0
monitoring/dashboards/imixs-cloud.json