# --------------------------
# Persistent Volume Claims
# --------------------------
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: ccm-data
spec:
  accessModes: ["ReadWriteOnce"]
  resources:
    requests:
      storage: 5Gi
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: es-data
spec:
  accessModes: ["ReadWriteOnce"]
  resources:
    requests:
      storage: 20Gi
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: es-snapshots
spec:
  accessModes: ["ReadWriteOnce"]
  resources:
    requests:
      storage: 10Gi
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mon-data
spec:
  accessModes: ["ReadWriteOnce"]
  resources:
    requests:
      storage: 5Gi

# --------------------------
# CCM
# --------------------------
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: ccm
spec:
  replicas: 1
  selector:
    matchLabels:
      app: ccm
  template:
    metadata:
      labels:
        app: ccm
    spec:
      containers:
        - name: ccm
          image: registry.frafos.net/abc/ccm:5.5
          ports:
            - containerPort: 443
            - containerPort: 444
          volumeMounts:
            - name: ccm-storage
              mountPath: /data
          securityContext:
            capabilities:
              add: ["AUDIT_CONTROL", "AUDIT_WRITE"]
          resources:
            limits:
              memory: "512Mi"
              cpu: "500m"
            requests:
              memory: "256Mi"
              cpu: "250m"
      volumes:
        - name: ccm-storage
          persistentVolumeClaim:
            claimName: ccm-data
---
apiVersion: v1
kind: Service
metadata:
  name: ccm
spec:
  selector:
    app: ccm
  ports:
    - name: https
      port: 443
      targetPort: 443
    - name: https2
      port: 444
      targetPort: 444
  type: ClusterIP

# --------------------------
# Elasticsearch
# --------------------------
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: elastic
spec:
  replicas: 1
  selector:
    matchLabels:
      app: elastic
  template:
    metadata:
      labels:
        app: elastic
    spec:
      containers:
        - name: elastic
          image: docker.elastic.co/elasticsearch/elasticsearch:7.17.28
          ports:
            - containerPort: 9200
            - containerPort: 9300
          env:
            - name: discovery.type
              value: "single-node"
            - name: network.host
              value: "_local_,_site_"
            - name: path.repo
              value: "/usr/share/elasticsearch/snapshots"
            - name: xpack.ml.enabled
              value: "false"
            - name: xpack.security.enabled
              value: "false"
            - name: xpack.security.http.ssl.enabled
              value: "false"
          resources:
            limits:
              memory: "4Gi"
              cpu: "1000m"
            requests:
              memory: "2Gi"
              cpu: "500m"
          volumeMounts:
            - name: es-data
              mountPath: /usr/share/elasticsearch/data
            - name: es-snapshots
              mountPath: /usr/share/elasticsearch/snapshots
      volumes:
        - name: es-data
          persistentVolumeClaim:
            claimName: es-data
        - name: es-snapshots
          persistentVolumeClaim:
            claimName: es-snapshots
---
apiVersion: v1
kind: Service
metadata:
  name: elastic
spec:
  selector:
    app: elastic
  ports:
    - name: http
      port: 9200
      targetPort: 9200
    - name: transport
      port: 9300
      targetPort: 9300

# --------------------------
# Chrome
# --------------------------
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: chrome
spec:
  replicas: 1
  selector:
    matchLabels:
      app: chrome
  template:
    metadata:
      labels:
        app: chrome
    spec:
      containers:
        - name: chrome
          image: zenika/alpine-chrome:latest
          args:
            - "--no-sandbox"
            - "--remote-debugging-address=::"
            - "--remote-debugging-port=9222"
          ports:
            - containerPort: 9222
          resources:
            limits:
              memory: "512Mi"
              cpu: "500m"
            requests:
              memory: "128Mi"
              cpu: "100m"
---
apiVersion: v1
kind: Service
metadata:
  name: chrome
spec:
  selector:
    app: chrome
  ports:
    - name: debug
      port: 9222
      targetPort: 9222

# --------------------------
# MON
# --------------------------
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mon
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mon
  template:
    metadata:
      labels:
        app: mon
    spec:
      containers:
        - name: mon
          image: registry.frafos.net/abc/mon:10.1
          ports:
            - containerPort: 5000
            - containerPort: 5044
            - containerPort: 3042
            - containerPort: 1873
            - containerPort: 3000
          volumeMounts:
            - name: mon-storage
              mountPath: /data
          tty: true
          stdin: true
          resources:
            limits:
              memory: "1Gi"
              cpu: "500m"
            requests:
              memory: "512Mi"
              cpu: "250m"
      volumes:
        - name: mon-storage
          persistentVolumeClaim:
            claimName: mon-data
---
apiVersion: v1
kind: Service
metadata:
  name: mon
spec:
  selector:
    app: mon
  ports:
    - name: server
      port: 5000
      targetPort: 5000
    - name: logstash
      port: 5044
      targetPort: 5044
    - name: upload-api
      port: 3042
      targetPort: 3042
    - name: upload-rsync
      port: 1873
      targetPort: 1873
    - name: ui
      port: 3000
      targetPort: 3000

# --------------------------
# Redis
# --------------------------
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: redis
spec:
  replicas: 1
  selector:
    matchLabels:
      app: redis
  template:
    metadata:
      labels:
        app: redis
    spec:
      securityContext:
        runAsNonRoot: true
        capabilities:
          drop: ["MKNOD", "NET_RAW", "AUDIT_WRITE"]
      containers:
        - name: redis
          image: registry.frafos.net/fril/redis-stack-server:latest
          ports:
            - containerPort: 6379
          livenessProbe:
            exec:
              command: ["redis-cli", "ping"]
            initialDelaySeconds: 10
            periodSeconds: 10
            timeoutSeconds: 5
            failureThreshold: 3
          resources:
            limits:
              memory: "1Gi"
              cpu: "500m"
            requests:
              memory: "512Mi"
              cpu: "250m"
---
apiVersion: v1
kind: Service
metadata:
  name: redis
spec:
  selector:
    app: redis
  ports:
    - name: redis
      port: 6379
      targetPort: 6379

# --------------------------
# Alerts
# --------------------------
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: alerts
spec:
  replicas: 1
  selector:
    matchLabels:
      app: alerts
  template:
    metadata:
      labels:
        app: alerts
    spec:
      containers:
        - name: alerts
          image: registry.frafos.net/fril/alerts:10.1
          ports:
            - containerPort: 80
          env:
            - name: REDIS_HOST
              value: "redis"
            - name: elasticConfigUrl
              value: "http://elastic:9200/"
          securityContext:
            capabilities:
              add: ["AUDIT_CONTROL", "NET_RAW", "AUDIT_WRITE"]
          readinessProbe:
            httpGet:
              path: /api/alertapi/help
              port: 80
            initialDelaySeconds: 15
            periodSeconds: 15
            timeoutSeconds: 5
            failureThreshold: 20
          resources:
            limits:
              memory: "1Gi"
              cpu: "500m"
            requests:
              memory: "512Mi"
              cpu: "250m"
---
apiVersion: v1
kind: Service
metadata:
  name: alerts
spec:
  selector:
    app: alerts
  ports:
    - name: http
      port: 80
      targetPort: 80

# --------------------------
# rq2rest
# --------------------------
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: rq2rest
spec:
  replicas: 1
  selector:
    matchLabels:
      app: rq2rest
  template:
    metadata:
      labels:
        app: rq2rest
    spec:
      containers:
        - name: rq2rest
          image: registry.frafos.net/fril/rq2rest:latest
          command:
            - "/bin/sh"
            - "-c"
            - >
              rq2rest -c /etc/rq2rest.ini -d 5
              --redis_url=redis:6379
              --http_url=http://alerts:80/ingestion/logstash/00000000-0000-0000-0000-000000000000
          tty: true
          resources:
            limits:
              memory: "1Gi"
              cpu: "500m"
            requests:
              memory: "512Mi"
              cpu: "250m"
---
apiVersion: v1
kind: Service
metadata:
  name: rq2rest
spec:
  selector:
    app: rq2rest
  ports:
    - name: rq
      port: 8080
      targetPort: 8080
