From f868bc22cdb45eb49098a1accb9ae43c760ba118 Mon Sep 17 00:00:00 2001 From: Edward Cheng Date: Thu, 18 Jul 2024 23:15:45 +1000 Subject: [PATCH] add infra app prometheus --- .../env/k3s-cluster/cluster-role-binding.yaml | 12 +++ .../env/k3s-cluster/cluster-role.yaml | 20 +++++ .../prometheus/env/k3s-cluster/config.json | 12 +++ .../env/k3s-cluster/deployment.yaml | 87 +++++++++++++++++++ .../env/k3s-cluster/kustomization.yaml | 7 ++ .../prometheus/env/k3s-cluster/service.yaml | 22 +++++ 6 files changed, 160 insertions(+) create mode 100644 infrastructures/prometheus/env/k3s-cluster/cluster-role-binding.yaml create mode 100644 infrastructures/prometheus/env/k3s-cluster/cluster-role.yaml create mode 100644 infrastructures/prometheus/env/k3s-cluster/config.json create mode 100644 infrastructures/prometheus/env/k3s-cluster/deployment.yaml create mode 100644 infrastructures/prometheus/env/k3s-cluster/kustomization.yaml create mode 100644 infrastructures/prometheus/env/k3s-cluster/service.yaml diff --git a/infrastructures/prometheus/env/k3s-cluster/cluster-role-binding.yaml b/infrastructures/prometheus/env/k3s-cluster/cluster-role-binding.yaml new file mode 100644 index 0000000..cc961cb --- /dev/null +++ b/infrastructures/prometheus/env/k3s-cluster/cluster-role-binding.yaml @@ -0,0 +1,12 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: prometheus +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: prometheus +subjects: + - kind: ServiceAccount + name: prometheus + namespace: prometheus \ No newline at end of file diff --git a/infrastructures/prometheus/env/k3s-cluster/cluster-role.yaml b/infrastructures/prometheus/env/k3s-cluster/cluster-role.yaml new file mode 100644 index 0000000..90bb838 --- /dev/null +++ b/infrastructures/prometheus/env/k3s-cluster/cluster-role.yaml @@ -0,0 +1,20 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: prometheus +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"] diff --git a/infrastructures/prometheus/env/k3s-cluster/config.json b/infrastructures/prometheus/env/k3s-cluster/config.json new file mode 100644 index 0000000..6ce2e6f --- /dev/null +++ b/infrastructures/prometheus/env/k3s-cluster/config.json @@ -0,0 +1,12 @@ +{ + "appName": "prometheus", + "userGivenName": "prometheus", + "namespace": "prometheus", + "destNamespace": "prometheus", + "destServer": "https://kubernetes.default.svc", + "srcPath": "infrastructures/prometheus/env/k3s-cluster", + "srcRepoURL": "https://github.com/3dwardch3ng/home-cluster-ops.git", + "srcTargetRevision": "", + "labels": null, + "annotations": null +} \ No newline at end of file diff --git a/infrastructures/prometheus/env/k3s-cluster/deployment.yaml b/infrastructures/prometheus/env/k3s-cluster/deployment.yaml new file mode 100644 index 0000000..d83c555 --- /dev/null +++ b/infrastructures/prometheus/env/k3s-cluster/deployment.yaml @@ -0,0 +1,87 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: prometheus + namespace: prometheus + labels: + app: prometheus +spec: + strategy: + rollingUpdate: null + type: Recreate + selector: + matchLabels: + app: prometheus + template: + metadata: + labels: + app: prometheus + spec: + securityContext: + runAsUser: 0 + runAsGroup: 0 + containers: + - name: prometheus + image: prom/prometheus:v2.53.0 + args: + - "--storage.tsdb.retention.time=14d" + - "--config.file=/etc/prometheus/prometheus.yaml" + - "--storage.tsdb.path=/prometheus/" + ports: + - containerPort: 9090 + resources: + requests: + cpu: 500m + memory: 500M + limits: + cpu: "1" + memory: 2Gi + volumeMounts: + - name: prometheus-config-volume + mountPath: /etc/prometheus/ + - name: prometheus-storage-volume + mountPath: /prometheus/ + - name: grafana + image: grafana/grafana:11.0.1 + ports: + - containerPort: 3000 + volumeMounts: + - name: grafana-config-volume + mountPath: /etc/grafana + - name: grafana-data-volume + mountPath: /var/lib/grafana + - name: grafana-logs-volume + mountPath: /var/log/grafana + - name: grafana-plugins-volume + mountPath: /var/lib/grafana/plugins + - name: grafana-provisioning-volume + mountPath: /etc/grafana/provisioning + volumes: + - name: prometheus-config-volume + hostPath: + path: /mnt/nfs/AppData/prometheus/conf + type: Directory + - name: prometheus-storage-volume + hostPath: + path: /mnt/nfs/AppData/prometheus/storage + type: Directory + - name: grafana-config-volume + hostPath: + path: /mnt/nfs/AppData/grafana/config + type: Directory + - name: grafana-data-volume + hostPath: + path: /mnt/nfs/AppData/grafana/data + type: Directory + - name: grafana-logs-volume + hostPath: + path: /mnt/nfs/AppData/grafana/logs + type: Directory + - name: grafana-plugins-volume + hostPath: + path: /mnt/nfs/AppData/grafana/plugins + type: Directory + - name: grafana-provisioning-volume + hostPath: + path: /mnt/nfs/AppData/grafana/provisioning + type: Directory \ No newline at end of file diff --git a/infrastructures/prometheus/env/k3s-cluster/kustomization.yaml b/infrastructures/prometheus/env/k3s-cluster/kustomization.yaml new file mode 100644 index 0000000..fb6c309 --- /dev/null +++ b/infrastructures/prometheus/env/k3s-cluster/kustomization.yaml @@ -0,0 +1,7 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - ./cluster-role.yaml + - ./cluster-role-binding.yaml + - ./deployment.yaml + - ./service.yaml \ No newline at end of file diff --git a/infrastructures/prometheus/env/k3s-cluster/service.yaml b/infrastructures/prometheus/env/k3s-cluster/service.yaml new file mode 100644 index 0000000..04105b9 --- /dev/null +++ b/infrastructures/prometheus/env/k3s-cluster/service.yaml @@ -0,0 +1,22 @@ +apiVersion: v1 +kind: Service +metadata: + name: prometheus + namespace: prometheus + annotations: + prometheus.io/scrape: 'true' + prometheus.io/port: '9999' +spec: + selector: + app: prometheus + type: NodePort + ports: + - port: 9999 + targetPort: 9090 + nodePort: 30999 + protocol: TCP + name: http + - name: grafana-port + port: 3030 + nodePort: 30303 + targetPort: 3000 \ No newline at end of file