kubernetes pods keep crashing with “CrashLoopBackOff” {GKE}

As in my last blog www.openwriteup.com/create-gke-pod-from-local-image/

I have deployed the pod, deployed using local image on GKE. It is failing with CrashLoopBackOff error. It was not giving any logs as well.

kubectl logs <pod name>
//no log message is reporting

After I have added the command block in the pod yaml

apiVersion: v1
kind: Pod
metadata:
  labels:
    run: ubuntu
  name: ubuntu
  namespace: default
spec:
  containers:
  - image: gcr.io/openwriteup/hellokubernetes/ubuntu
    imagePullPolicy: Never
    name: ubuntu
    resources:
      requests:
        cpu: 100m
    command: ["/bin/sh"]
    args: ["-c", "while true; do echo hello; sleep 10;done"]
  dnsPolicy: ClusterFirst
  enableServiceLinks: true

#command and args has added in the yaml file
Now I have executed
kubectl apply -f pod.yaml
[root@target-1 ~]# kubectl get pods
NAME     READY   STATUS    RESTARTS   AGE
ubuntu   1/1     Running   0          9m30s

Create GKE pod from local image

This blog, I will be covering following:

  • create gke cluster from gcloud sdk
  • few gcloud command line option
  • create container registry in google cloud
  • Push local image to google cloud registry
  • using kubectl create pod using that image

Prerequisites:

My environment is centos 7

sudo tee -a /etc/yum.repos.d/google-cloud-sdk.repo << EOM
[google-cloud-sdk]
name=Google Cloud SDK
baseurl=https://packages.cloud.google.com/yum/repos/cloud-sdk-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
       https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOM
yum install google-cloud-sdk
yum install docker

yum install kubectl
gcloud auth login
gcloud config set project <project name>
//for login and set the project name

create and explore google kubernetes engine (GKE) from gcloud

gcloud container clusters create example-cluster --zone us-central1-c
gcloud container clusters get-credentials  example-cluster   --zone us-central1-c
gcloud container clusters describe  example-cluster --zone us-central1-c

Enable and create container registry on google cloud

create tag and push the docker image on google container registry (gcr)

docker tag openwriteup:ubuntu  gcr.io/openwriteup/hellokubernetes/ubuntu
docker images
docker push gcr.io/openwriteup/hellokubernetes/ubuntu

yaml file to create pod

apiVersion: v1
kind: Pod
metadata:
  labels:
    run: ubuntu
  name: ubuntu
  namespace: default
  resourceVersion: "34418"
  selfLink: /api/v1/namespaces/default/pods/ubuntu
  uid: 7ee750fe-52a3-41f8-90be-5310270debad
spec:
  containers:
  - image: gcr.io/openwriteup/hellokubernetes/ubuntu
    imagePullPolicy: Always
    name: ubuntu
    resources:
      requests:
        cpu: 100m
    terminationMessagePath: /dev/termination-log
    terminationMessagePolicy: File
    volumeMounts:
    - mountPath: /var/run/secrets/kubernetes.io/serviceaccount
      name: default-token-jpglv
      readOnly: true
  dnsPolicy: ClusterFirst
  enableServiceLinks: true
//kubectl apply -f <.yaml file>
//kubectl get pods
//kubectl logs <pod name>

First look to GCP console

This blog I will be sharing the screenshots, once we sign-up the google cloud platform. We get the option go to the console. Once we go to console we get the below screen

On the console screen we get lot of option, As we need to start we need to create a project.

We have created one project, “ow-project”. As we are just starting, its good to go in “getting started option” of the panel.

This getting started option has option regarding compute,storage,billing,api etc.

We need to enable billing, provide your credit card info to create vm instances, I will me covering vm instances in next part