apiVersion: apps/v1
kind: Deployment

metadata:
  namespace: singouins-dev
  name: sep-backend-nginx
  labels:
    tier: sep-backend
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
      tier: sep-backend
  strategy:
    type: Recreate
  template:
    metadata:
      annotations:
        prometheus.io/scrape: "true"
        prometheus.io/port: "9113"
      labels:
        app: nginx
        tier: sep-backend
    spec:

      containers:
      - name: sep-backend-nginx
        image: nginx:1.20-alpine
        resources:
          requests:
            memory: 32Mi
            cpu: 100m
        ports:
        - containerPort: 80
        - containerPort: 443
        volumeMounts:
        - name: config
          mountPath: /etc/nginx/conf.d
        - name: htpasswd
          mountPath: /etc/nginx/htpasswd
        - name: www
          mountPath: /var/www/certbot
        - name: certs
          mountPath: /etc/letsencrypt
        - name: websites
          mountPath: /var/www/websites
      - name: sep-backend-nginx-certbot
        image: certbot/certbot
        resources:
          limits:
            memory: 128Mi
            cpu: 50m
          requests:
            memory: 16Mi
            cpu: 10m
        command: ["/bin/sh"]
        args: ["-c", "trap exit TERM; while :; do certbot renew; sleep 12h & wait $${!}; done;"]
        volumeMounts:
         - name: www
           mountPath: /var/www/certbot
         - name: certs
           mountPath: /etc/letsencrypt
      - name: nginx-exporter
        image: nginx/nginx-prometheus-exporter
        resources:
          limits:
            memory: 32Mi
            cpu: 50m
          requests:
            memory: 16Mi
            cpu: 10m

      restartPolicy: Always

      volumes:
      - name: config
        configMap:
          name: sep-backend-nginx
          items:
          - key: config
            path: site.conf
      - name: htpasswd
        configMap:
          name: sep-backend-nginx-htpasswd
          items:
          - key: htpasswd
            path: htpasswd
      - name: certs
        persistentVolumeClaim:
          claimName: sep-backend-certbot-certs
      - name: www
        persistentVolumeClaim:
          claimName: sep-backend-certbot-www
      - name: websites
        persistentVolumeClaim:
          claimName: sep-backend-code-websites
