apiVersion: apps/v1
kind: Deployment
metadata:
  name: ecommerce-deployment-{{ include "fastapi-helm.fullname" . }}
  namespace: { { .Release.Namespace } }
  labels:
    app: ecommerce
    version: { { .Chart.AppVersion } }
spec:
  replicas: 8
  selector:
    matchLabels:
      app: ecommerce-app
  template:
    metadata:
      labels:
        app: ecommerce-app
    spec:
      initContainers:
        - name: init-postgres-service
          image: postgres:10.17
          command: [
              "sh",
              "-c",
              "until pg_isready -h postgres-service.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local -p 5432;
              do echo waiting for database; sleep 2; done;",
            ]
      containers:
        - image: mukulmantosh/ecommerce-fastapi:latest
          imagePullPolicy: Always
          name: sample-container
          envFrom:
            - secretRef:
                name: ecommerce-secret-{{ include "fastapi-helm.fullname" . }}
          ports:
            - containerPort: 5000
              name: fastapi
          readinessProbe:
            httpGet:
              port: 5000
              path: /docs
            initialDelaySeconds: 15
          livenessProbe:
            httpGet:
              port: 5000
              path: /docs
            initialDelaySeconds: 15
            periodSeconds: 15
          resources:
            requests:
              memory: "512Mi"
              cpu: "0.5"
            limits:
              memory: "1Gi"
              cpu: "1"
