How to fix CrashLoopBackOff status in Kubernetes when trying to create a pod?

546 views Asked by At

Context: I'm using Kubernetes to create a deployment (a pod) via kubectl apply command that has a MySql container inside. The deployment file also configs a cluster IP and a load balancer to use for the same pod.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: fplms-discussiondb-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: fplms-discussiondb
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: fplms-discussiondb
    spec:
      terminationGracePeriodSeconds: 30
      securityContext:
        fsGroup: 1000
      containers:
        - name: fplms-discussiondb
          image: mysql
          ports:
            - containerPort: 3306
          resources:
            limits:
              memory: 128Mi
              cpu: 500m
          env:
            - name: MYSQL_ROOT_PASSWORD
              value: "fplms"
            - name: MYSQL_DATABASE
              value: "discussiondb"
          volumeMounts:
            - mountPath: /var/lib/mysql
              name: fplms-discussiondb
      volumes:
        - name: fplms-discussiondb
          persistentVolumeClaim:
            claimName: fplms-discussiondb-claim
---
apiVersion: v1
kind: Service
metadata:
  name: fplms-discussiondb-clusterip
spec:
  type: ClusterIP
  selector:
    app: fplms-discussiondb
  ports:
    - name: fplms-discussiondb
      protocol: TCP
      port: 3306
      targetPort: 3306
---
apiVersion: v1
kind: Service
metadata:
  name: fplms-discussiondb-loadbalancer
spec:
  type: LoadBalancer
  selector:
    app: fplms-discussiondb
  ports:
    - protocol: TCP
      port: 3306
      targetPort: 3306

Problem: When I applied the deployment file, it keeps getting the CrashLoopBackOff status (see last image).

Can anyone help me fix this problem? Thank you so much.

Describe 1/2

Describe 2/2

Logs

512Mi: enter image description here

1

There are 1 answers

3
Preet Sindhal On

The reason for termination is OOMKilled (1st screenshot), that means Out Of Memory you can try by increasing the memory limits.