Run container images on Kubernetes – CrashLoopBackOff

I don’t have much experience with kubernetes, but what I am essentially trying to do is run container images (django app) + (postgresql) on kubernetes cluster. I am constantly running into CrashLoopBackOff. I am using azure and I looked at the examples on the website but they are just not good enough. I have spent hours and not sure how to debug this. The docker containers work fine locally. All my code and results posted below.

kubectl logs project-app-7ccf657d8c-ktfn7 -p
(returns nothing)

kubectl get pods

project-app-5d954f9685-hjwvp           0/1     CrashLoopBackOff   16         59m
project-database-574978c8c6-skwgk      1/1     Running            0          3h59m

kubectl describe pod project-app-5d954f9685-hjwvp

Name:           project-app-5d954f9685-hjwvp
Namespace:      default
Priority:       0
Node:           aks-nodepool1-32957652-vmss000000/10.240.0.4
Start Time:     Wed, 12 Feb 2020 20:19:41 -0800
Labels:         app=project-app
                pod-template-hash=5d954f9685
Annotations:    <none>
Status:         Running
IP:             10.244.0.11
IPs:            <none>
Controlled By:  ReplicaSet/project-app-5d954f9685
Containers:
  project-app:
    Container ID:   docker://2ba6151dea44a42d417d43a7ea8ae90d8a5baa9e11042d0255c54981e4b7d673
    Image:          mentalhealth.azurecr.io/project-app4:v1
    Image ID:       docker-pullable://mentalhealth.azurecr.io/[email protected]:c2b74c304c08f4c55891fd439364f711743273b6f166b88f9a7b21d332f69752
    Port:           8000/TCP
    Host Port:      0/TCP
    State:          Waiting
      Reason:       CrashLoopBackOff
    Last State:     Terminated
      Reason:       Completed
      Exit Code:    0
      Started:      Wed, 12 Feb 2020 21:11:32 -0800
      Finished:     Wed, 12 Feb 2020 21:11:32 -0800
    Ready:          False
    Restart Count:  15
    Limits:
      cpu:  500m
    Requests:
      cpu:  250m
    Environment:
      postgres:  project-database
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-ztqqh (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             False 
  ContainersReady   False 
  PodScheduled      True 
Volumes:
  default-token-ztqqh:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-ztqqh
    Optional:    false
QoS Class:       Burstable
Node-Selectors:  beta.kubernetes.io/os=linux
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:
  Type     Reason     Age                  From                                        Message
  ----     ------     ----                 ----                                        -------
  Normal   Scheduled  55m                  default-scheduler                           Successfully assigned default/project-app-5d954f9685-hjwvp to aks-nodepool1-32957652-vmss000000
  Normal   Pulled     53m (x5 over 55m)    kubelet, aks-nodepool1-32957652-vmss000000  Container image "mentalhealth.azurecr.io/project-app4:v1" already present on machine
  Normal   Created    53m (x5 over 55m)    kubelet, aks-nodepool1-32957652-vmss000000  Created container project-app
  Normal   Started    53m (x5 over 55m)    kubelet, aks-nodepool1-32957652-vmss000000  Started container project-app
  Warning  BackOff    11s (x259 over 55m)  kubelet, aks-nodepool1-32957652-vmss000000  Back-off restarting failed container

azure-yaml

apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: project-database
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: project-database
    spec:
      terminationGracePeriodSeconds: 10
      containers:
      - name: project-database
        image: mentalhealth.azurecr.io/postgres:v1
        ports:
        - containerPort: 5432
        env:
        - name: MSSQL_PID
          value: "Developer"
        - name: ACCEPT_EULA
          value: "Y"
        - name: MSSQL_SA_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mssql
              key: SA_PASSWORD 
        volumeMounts:
        - name: mssqldb
          mountPath: /var/opt/mssql
      volumes:
      - name: mssqldb
        persistentVolumeClaim:
          claimName: postgres-data
---
apiVersion: v1
kind: Service
metadata:
  name: project-database
spec:
  selector:
    app: mssql
  ports:
    - protocol: TCP
      port: 1433
      targetPort: 1433
  type: LoadBalancer
---
apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: project-app
spec:
  replicas: 1
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
  minReadySeconds: 10 
  template:
    metadata:
      labels:
        app: project-app
    spec:
      nodeSelector:
        "beta.kubernetes.io/os": linux
      containers:
      - name: project-app
        image: mentalhealth.azurecr.io/project-app4:v1
        command: [ "sleep" ]
        args: [ "infinity" ]
        ports:
        - containerPort: 8000
        resources:
          requests:
            cpu: 250m
          limits:
            cpu: 500m
        env:
        - name: postgres
          value: "project-database"
---
apiVersion: v1
kind: Service
metadata:
  name: project-app
spec:
  type: LoadBalancer
  ports:
  - port: 8000
  selector:
    app: project-app

persistentVolume.yaml

kind: StorageClass
apiVersion: storage.k8s.io/v1beta1
metadata:
     name: azure-disk
provisioner: kubernetes.io/azure-disk
parameters:
  storageaccounttype: Standard_LRS
  kind: Managed
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: postgres-data
  annotations:
    volume.beta.kubernetes.io/storage-class: azure-disk
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 8Gi

Source: StackOverflow