diff --git a/deployment-proxy.yml b/kube-manifests/deployment-proxy.yml similarity index 100% rename from deployment-proxy.yml rename to kube-manifests/deployment-proxy.yml diff --git a/kube-manifests/deployment.yml b/kube-manifests/deployment.yml new file mode 100644 index 0000000..7425b48 --- /dev/null +++ b/kube-manifests/deployment.yml @@ -0,0 +1,567 @@ +# This create a namespace for monitoring +apiVersion: v1 +kind: Namespace +metadata: + name: satisfactory-monitoring + labels: + name: satisfactory-monitoring +--- +# Deployment for satisfactory-metrics +apiVersion: apps/v1 +kind: Deployment +metadata: + name: satisfactory-metrics + namespace: satisfactory-monitoring +spec: + selector: + matchLabels: + app: satisfactory-metrics + template: + metadata: + name: satisfactory-metrics + namespace: satisfactory-monitoring + labels: + app: satisfactory-metrics + spec: + containers: + - name: exporter + image: ghcr.io/justereseau/satisfactory-exporter:latest + imagePullPolicy: Always + args: + - -web.listen-address=:9100 + - -frm.listen-address=http://DJLS-Desktop.coloc.djls.space:8080 + ports: + - containerPort: 9100 + name: metrics + livenessProbe: + httpGet: + path: /-/healthy + port: metrics + initialDelaySeconds: 15 + timeoutSeconds: 5 + readinessProbe: + httpGet: + path: /-/healthy + port: metrics + initialDelaySeconds: 5 + timeoutSeconds: 5 + securityContext: + seccompProfile: + type: RuntimeDefault + runAsNonRoot: true + allowPrivilegeEscalation: false + runAsUser: 999 + runAsGroup: 999 + capabilities: + drop: + - ALL +--- +# Service for satisfactory-metrics +apiVersion: v1 +kind: Service +metadata: + name: satisfactory-metrics + namespace: satisfactory-monitoring + labels: + app: satisfactory-metrics +spec: + type: ClusterIP + ports: + - port: 9100 + targetPort: metrics + name: metrics + selector: + app: satisfactory-metrics +--- +# This create a configmap for Prometheus +apiVersion: v1 +kind: ConfigMap +metadata: + name: prometheus-server-conf + namespace: satisfactory-monitoring + labels: + app: prometheus +data: + prometheus.yml: | + global: + scrape_interval: 5s + evaluation_interval: 4s + scrape_configs: + - job_name: ficsit_power + params: + collect: + - production,power,factory_building,player + static_configs: + - targets: + - satisfactory-metrics:9100 +--- +# Create an headless service for Prometheus +apiVersion: v1 +kind: Service +metadata: + name: prometheus-headless + namespace: satisfactory-monitoring + labels: + app: prometheus +spec: + clusterIP: None + ports: + - port: 9090 + targetPort: 9090 + selector: + app: prometheus +--- +# Create a service for Prometheus +apiVersion: v1 +kind: Service +metadata: + name: prometheus + namespace: satisfactory-monitoring + labels: + app: prometheus +spec: + type: ClusterIP + ports: + - port: 9090 + targetPort: 9090 + name: http + selector: + app: prometheus +--- +# This create a statefulset with 1 replica of Prometheus +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: prometheus + namespace: satisfactory-monitoring + labels: + app: prometheus +spec: + replicas: 1 + serviceName: prometheus-headless + selector: + matchLabels: + app: prometheus + volumeClaimTemplates: + - metadata: + name: prometheus-storage + spec: + accessModes: ["ReadWriteOnce"] + resources: + requests: + storage: 1Gi + template: + metadata: + labels: + app: prometheus + spec: + securityContext: + fsGroup: 999 + containers: + - name: prometheus + image: prom/prometheus:latest + args: + - "--config.file=/etc/prometheus/prometheus.yml" + - "--storage.tsdb.path=/prometheus/data" + - "--storage.tsdb.retention.time=365d" + ports: + - containerPort: 9090 + volumeMounts: + - name: prometheus-config + mountPath: /etc/prometheus/ + - name: prometheus-storage + mountPath: /prometheus/data + livenessProbe: + httpGet: + path: /-/healthy + port: 9090 + initialDelaySeconds: 30 + timeoutSeconds: 5 + readinessProbe: + httpGet: + path: /-/ready + port: 9090 + initialDelaySeconds: 30 + timeoutSeconds: 5 + securityContext: + seccompProfile: + type: RuntimeDefault + runAsNonRoot: true + allowPrivilegeEscalation: false + runAsUser: 999 + runAsGroup: 999 + capabilities: + drop: + - ALL + volumes: + - name: prometheus-config + configMap: + name: prometheus-server-conf +--- +# Create an headless service for Postgres +apiVersion: v1 +kind: Service +metadata: + name: postgres-headless + namespace: satisfactory-monitoring + labels: + app: postgres +spec: + clusterIP: None + ports: + - port: 5432 + targetPort: postgres + selector: + app: postgres +--- +# This create a service for Postgres database +apiVersion: v1 +kind: Service +metadata: + name: postgres + namespace: satisfactory-monitoring + labels: + app: postgres +spec: + type: ClusterIP + ports: + - port: 5432 + targetPort: postgres + name: postgres + selector: + app: postgres +--- +# This create a StatefulSet for Postgres database +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: postgres + namespace: satisfactory-monitoring + labels: + app: postgres +spec: + replicas: 1 + serviceName: postgres + selector: + matchLabels: + app: postgres + volumeClaimTemplates: + - metadata: + name: postgres-storage + spec: + accessModes: ["ReadWriteOnce"] + resources: + requests: + storage: 1Gi + template: + metadata: + labels: + app: postgres + spec: + securityContext: + fsGroup: 999 + containers: + - name: postgres + image: postgres:latest + ports: + - containerPort: 5432 + name: postgres + volumeMounts: + - name: postgres-storage + mountPath: /var/lib/postgresql + env: + - name: POSTGRES_PASSWORD + value: secretpassword + - name: POSTGRES_USER + value: postgres + - name: POSTGRES_DB + value: postgres + livenessProbe: + exec: + command: + - pg_isready + - -U + - postgres + initialDelaySeconds: 30 + timeoutSeconds: 5 + readinessProbe: + exec: + command: + - pg_isready + - -U + - postgres + initialDelaySeconds: 30 + timeoutSeconds: 5 + securityContext: + seccompProfile: + type: RuntimeDefault + runAsNonRoot: true + allowPrivilegeEscalation: false + runAsUser: 999 + runAsGroup: 999 + capabilities: + drop: + - ALL +--- +# This create the configuration for Grafana +apiVersion: v1 +kind: ConfigMap +metadata: + name: grafana-configuration + namespace: satisfactory-monitoring +data: + grafana.ini: | + app_mode = production + instance_name = Ficsit + [paths] + data = /var/lib/grafana + logs = /var/log/grafana + [security] + disable_initial_admin_creation = false + admin_user = admin + admin_password = admin + disable_gravatar = true + [snapshots] + enabled = false + [dashboards] + versions_to_keep = 1 + # Path to the default home dashboard. If this value is empty, then Grafana uses StaticRootPath + "dashboards/home.json" + ;default_home_dashboard_path = + [users] + allow_sign_up = false + [auth] + disable_login = true + disable_login_form = true + [auth.anonymous] + enabled = true + org_role = Admin +# This create the configuration for Grafana Datasources +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: grafana-datasources + namespace: satisfactory-monitoring +data: + prometheus.yaml: | + apiVersion: 1 + datasources: + - uid: PBFA97CFB590B2093 + name: Prometheus + type: prometheus + access: proxy + orgId: 1 + url: http://prometheus:9090 + isDefault: true + postgres.yaml: | + apiVersion: 1 + datasources: + - name: Postgres + type: postgres + uid: GhzMNppVk + url: postgres:5432 + database: postgres + user: postgres + secureJsonData: + password: 'secretpassword' + jsonData: + sslmode: 'disable' # disable/require/verify-ca/verify-full + maxOpenConns: 0 + maxIdleConns: 2 + connMaxLifetime: 14400 + postgresVersion: 1500 # 903=9.3, 904=9.4, 905=9.5, 906=9.6, 1000=10 + timescaledb: false +--- +# Create an headless service for Grafana +apiVersion: v1 +kind: Service +metadata: + name: grafana-headless + namespace: satisfactory-monitoring + labels: + app: grafana +spec: + clusterIP: None + ports: + - port: 3000 + targetPort: 3000 + selector: + app: grafana +--- +# This create a service for Grafana +apiVersion: v1 +kind: Service +metadata: + name: grafana + namespace: satisfactory-monitoring + labels: + app: grafana +spec: + type: ClusterIP + ports: + - port: 3000 + targetPort: 3000 + name: http + selector: + app: grafana +--- +# This create a deployment for Grafana +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: grafana + namespace: satisfactory-monitoring + labels: + app: grafana +spec: + replicas: 1 + serviceName: grafana-headless + selector: + matchLabels: + app: grafana + volumeClaimTemplates: + - metadata: + name: grafana-storage + spec: + accessModes: ["ReadWriteOnce"] + resources: + requests: + storage: 2Gi + template: + metadata: + labels: + app: grafana + spec: + securityContext: + fsGroup: 999 + containers: + - name: grafana + image: grafana/grafana:latest + ports: + - containerPort: 3000 + name: http + volumeMounts: + - name: grafana-configuration + mountPath: /etc/grafana/grafana.ini + subPath: grafana.ini + readOnly: true + - name: grafana-datasources + mountPath: /etc/grafana/provisioning/datasources + readOnly: true + - name: grafana-storage + mountPath: /var/lib/grafana + subPath: data + livenessProbe: + httpGet: + path: /api/health + port: http + initialDelaySeconds: 30 + timeoutSeconds: 5 + readinessProbe: + httpGet: + path: /api/health + port: http + initialDelaySeconds: 30 + timeoutSeconds: 5 + securityContext: + seccompProfile: + type: RuntimeDefault + runAsNonRoot: true + allowPrivilegeEscalation: false + runAsUser: 999 + runAsGroup: 999 + capabilities: + drop: + - ALL + volumes: + - name: grafana-configuration + configMap: + name: grafana-configuration + - name: grafana-datasources + configMap: + name: grafana-datasources +--- +# Create a configfile for the metadata configuration +apiVersion: v1 +kind: ConfigMap +metadata: + name: satisfactory-metadata-config + namespace: satisfactory-monitoring +data: + config.csv: | + factory,getFactory + extractor,getExtractor + storageInv,getStorageInv + worldInv,getWorldInv + generators,getGenerators + trainStation,getTrainStation + truckStation,getTruckStation + radar,getRadarTower +--- +# This create a cronjob that do the migration of the database +apiVersion: batch/v1 +kind: CronJob +metadata: + name: satisfactory-metadata-sync + namespace: satisfactory-monitoring + labels: + app: postgres +spec: + schedule: "*/1 * * * *" + successfulJobsHistoryLimit: 1 + failedJobsHistoryLimit: 3 + jobTemplate: + spec: + template: + spec: + restartPolicy: OnFailure + volumes: + - name: config + configMap: + name: satisfactory-metadata-config + containers: + - name: satisfactory-metadata-sync + image: ghcr.io/justereseau/satisfactory-metadata:latest + imagePullPolicy: Always + args: + - -frm.listen-address=http://DJLS-Desktop.coloc.djls.space:8080 + - -db.pghost=postgres + - -db.pgport=5432 + - -db.pguser=postgres + - -db.pgpassword=secretpassword + - -db.pgdb=postgres + - -metrics.file=/config/config.csv + volumeMounts: + - name: config + mountPath: /config + securityContext: + seccompProfile: + type: RuntimeDefault + runAsNonRoot: true + allowPrivilegeEscalation: false + runAsUser: 999 + runAsGroup: 999 + capabilities: + drop: + - ALL +--- +# Create an Ingress for the monitoring +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: satisfactory-monitoring + namespace: satisfactory-monitoring + annotations: + nginx.ingress.kubernetes.io/rewrite-target: / +spec: + rules: + - host: satisfactory-monitoring.coloc.djls.space + http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: grafana + port: + number: 3000