apiVersion: apps/v1
kind: Deployment
metadata:
  name: pastebin-app
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      app: pastebin
  template:
    metadata:
      labels:
        app: pastebin
    spec:
      initContainers:
        - name: fix-permissions
          image: busybox
          command: ["sh", "-c", "chown -R 1000:1000 /app/uploads"]
          volumeMounts:
            - name: uploads
              mountPath: /app/uploads
      containers:
        - name: pastebin-container
          image: prietus/pastebin-app:1.65
          ports:
            - containerPort: 5000
          env:
            - name: DB_ENGINE
              value: "postgres"
            - name: POSTGRES_HOST
              value: "pastebin-postgres"
            - name: VALID_USER
              valueFrom:
                configMapKeyRef:
                  name: pastebin-config
                  key: VALID_USER
            - name: VALID_PASS
              valueFrom:
                configMapKeyRef:
                  name: pastebin-config
                  key: VALID_PASS
            - name: POSTGRES_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: pastebin-secret
                  key: POSTGRES_PASSWORD
            - name: DATABASE_URL
              value: "postgresql://mypasteuser:$(POSTGRES_PASSWORD)@pastebin-postgres:5432/mypastedb?connect_timeout=10"
            - name: SMTP_USE_TLS
              valueFrom:
                configMapKeyRef:
                  name: pastebin-config
                  key: SMTP_USE_TLS
            - name: SMTP_USE_SSL
              valueFrom:
                configMapKeyRef:
                  name: pastebin-config
                  key: SMTP_USE_SSL
            - name: SMTP_SERVER
              value: "priet.us"
            - name: SMTP_PORT
              valueFrom:
                configMapKeyRef:
                  name: pastebin-config
                  key: SMTP_PORT
            - name: SMTP_USERNAME
              valueFrom:
                secretKeyRef:
                  name: pastebin-secret
                  key: SMTP_USERNAME
            - name: SMTP_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: pastebin-secret
                  key: SMTP_PASSWORD
          volumeMounts:
            - name: uploads
              mountPath: /app/uploads
      volumes:
        - name: uploads
          persistentVolumeClaim:
            claimName: uploads-pvc
---
apiVersion: v1
kind: Service
metadata:
  name: pastebin-service
  namespace: default
spec:
  ports:
    - port: 80
      targetPort: 5000
  selector:
    app: pastebin
  type: ClusterIP

