apiVersion: apps/v1
kind: Deployment
metadata:
  name: django-deployment
  labels:
    app: django
spec:
  # Number of pods in the deployment's replica set
  replicas: 2
  selector:
    matchLabels:
      app: django
  template:
    metadata:
      labels:
        app: django
    spec:
      containers:
      - name: django
        # Notice the tag is also included in the image
        image: kubernetes101/django_image:09f1419
        ports:
        - containerPort: 8000
        # Minimum and maximum resources allocated to the container.
        resources:
          requests:
            memory: "64Mi"
            cpu: "200m"
          limits:
            memory: "128Mi"
            cpu: "400m"
        # Add envconfigmap configmap variables to the environment
        envFrom:
          - configMapRef:
              name: postgres-config
        env:
          # POSTGRES_PASSWORD are defined in a secret called "db-password".
          # These hold the database access information that is injected as environment variables
          # into the django pod
          - name: POSTGRES_PASSWORD
            valueFrom:
              secretKeyRef:
                name: db-password
                key: db-password
          # The AWS credentials are needed for Django to put static files into an S3 bucket for the
          # production deployment. Used by django-storages
          - name: AWS_STORAGE_BUCKET_NAME
            valueFrom:
              secretKeyRef:
                name: s3-secrets
                key: s3bucket
          - name: AWS_ACCESS_KEY_ID
            valueFrom:
              secretKeyRef:
                name: s3-secrets
                key: s3accesskey
          - name: AWS_SECRET_ACCESS_KEY
            valueFrom:
              secretKeyRef:
                name: s3-secrets
                key: s3secretkey
