apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: postgis
  namespace: farm
spec:
  serviceName: "postgis"
  replicas: 1
  selector:
    matchLabels:
      app: postgis
  template:
    metadata:
      labels:
        app: postgis
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: kubernetes.io/hostname
                operator: In
                values:
                - vmi3045103.contaboserver.net
      containers:
      - name: postgis
        image: postgis/postgis:14-3.3
        ports:
        - containerPort: 5432
        env:
        - name: POSTGRES_USER
          valueFrom:
            secretKeyRef:
              name: farm-db-credentials
              key: POSTGRES_USER
        - name: POSTGRES_PASSWORD
          valueFrom:
            secretKeyRef:
              name: farm-db-credentials
              key: POSTGRES_PASSWORD
        - name: POSTGRES_DB
          valueFrom:
            secretKeyRef:
              name: farm-db-credentials
              key: POSTGRES_DB
        resources:
          requests:
            memory: "256Mi"
            cpu: "100m"
          limits:
            memory: "1Gi"
        volumeMounts:
        - name: data
          mountPath: /var/lib/postgresql/data
      volumes:
      - name: data
        persistentVolumeClaim:
          claimName: postgis-data-pvc
---
apiVersion: v1
kind: Service
metadata:
  name: postgis
  namespace: farm
spec:
  ports:
  - port: 5432
  selector:
    app: postgis
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: timescaledb
  namespace: farm
spec:
  serviceName: "timescaledb"
  replicas: 1
  selector:
    matchLabels:
      app: timescaledb
  template:
    metadata:
      labels:
        app: timescaledb
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: kubernetes.io/hostname
                operator: In
                values:
                - vmi3045103.contaboserver.net
      containers:
      - name: timescaledb
        image: timescale/timescaledb:latest-pg14
        ports:
        - containerPort: 5432
        env:
        - name: POSTGRES_USER
          valueFrom:
            secretKeyRef:
              name: farm-db-credentials
              key: TIMESCALE_USER
        - name: POSTGRES_PASSWORD
          valueFrom:
            secretKeyRef:
              name: farm-db-credentials
              key: TIMESCALE_PASSWORD
        - name: POSTGRES_DB
          valueFrom:
            secretKeyRef:
              name: farm-db-credentials
              key: TIMESCALE_DB
        resources:
          requests:
            memory: "256Mi"
            cpu: "100m"
          limits:
            memory: "1Gi"
        volumeMounts:
        - name: data
          mountPath: /var/lib/postgresql/data
      volumes:
      - name: data
        persistentVolumeClaim:
          claimName: timescaledb-data-pvc
---
apiVersion: v1
kind: Service
metadata:
  name: timescaledb
  namespace: farm
spec:
  ports:
  - port: 5432
  selector:
    app: timescaledb
