---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: postamates-django
  namespace: spatial
  labels:
    app.kubernetes.io/name: postamates-django
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: postamates-django
  template:
    metadata:
      labels:
        app.kubernetes.io/name: postamates-django
    spec:
      containers:
      - name: django
        image: DEPLOY_IMAGE_TAG
        command: ["sh", "-c", "python manage.py delete_views && python manage.py create_procedures && python manage.py migrate && python manage.py create_views && python manage.py kill_update && python manage.py runserver 0.0.0.0:${DJANGO_PORT}"]
        ports:
          - containerPort: 8000
            name: django-port
        envFrom:
          - configMapRef:
              name: postamates-configmap
        resources:
          requests:
            memory: "3000Mi"
            cpu: "500m"
          limits:
            memory: "3000Mi"
            cpu: "500m"
        # readinessProbe:
        #   httpGet:
        #     path: /api/ao_rayons
        #     port: django-port
        #   initialDelaySeconds: 3
        #   periodSeconds: 3
        # livenessProbe:
        #   httpGet:
        #     path: /api/ao_rayons
        #     port: django-port
        #   initialDelaySeconds: 3
        #   periodSeconds: 3
        volumeMounts:
          - mountPath: "/code/django_media"
            name: django-nginx-data
      volumes:
        - name: django-nginx-data
          persistentVolumeClaim:
            claimName: django-nginx-pvc
---
apiVersion: v1
kind: Service
metadata:
  name: postamates-django
spec:
  selector:
    app.kubernetes.io/name: postamates-django
  ports:
    - protocol: TCP
      port: 8000
      targetPort: 8000
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: postamates-django
  namespace: spatial
spec:
  ingressClassName: nginx-internal
  rules:
  - host: ADDRESS_INGRESS_HOST
    http:
      paths:
      - backend:
          service:
            name: postamates-django
            port:
              number: 8000
        path: /api/
        pathType: ImplementationSpecific
      - backend:
          service:
            name: postamates-django
            port:
              number: 8000
        path: /admin/
        pathType: ImplementationSpecific
      - backend:
          service:
            name: postamates-django
            port:
              number: 8000
        path: /accounts/
        pathType: ImplementationSpecific