<p>I have my image hosted on GCR.
I want to create Kubernetes Cluster on my local system(mac).</p>

<p>Steps I followed :</p>

<ol>
<li>Create a imagePullSecretKey</li>
<li>Create generic key to communicate with GCP. (kubectl create secret generic gcp-key --from-file=key.json)</li>
<li>I have deployment.yaml file</li>
</ol>

<blockquote>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: sv-premier
spec:
  selector:
    matchLabels:
      app: sv-premier
  template:
    metadata:
      labels:
        app: sv-premier
    spec:
      volumes:
      - name: google-cloud-key
        secret:
          secretName: gcp-key
      containers:
      - name: sv-premier
        image: gcr.io/proto/premiercore1:latest
        imagePullPolicy: Always
        command: ["echo", "Done deploying sv-premier"]
        volumeMounts:
        - name: google-cloud-key
          mountPath: /var/secrets/google
        env:
        - name: GOOGLE_APPLICATION_CREDENTIALS
          value: /var/secrets/google/key.json
        ports:
        - containerPort: 8080
      imagePullSecrets:
      - name: imagepullsecretkey
</code></pre>
</blockquote>

<p>When I execute the command - kubectl apply -f deployment.yaml , I get <strong>CrashLoopBackOff</strong> Error</p>

<p>Logs for - </p>

<blockquote>
  <p>kubectl describe pods podname</p>
</blockquote>

<p>=======================</p>

<blockquote>
  <p>Name:           sv-premier-6b77ddd747-cvdr5</p>
  
  <p>Namespace:      default</p>
  
  <p>Priority:       0</p>
  
  <p>Node:           docker-desktop/192.168.65.3</p>
  
  <p>Start Time:     Tue, 04 Feb 2020 14:18:47 +0530</p>
  
  <p>Labels:         app=sv-premier</p>
  
  <p>pod-template-hash=6b77ddd747</p>
  
  <p>Annotations:    </p>
  
  <p>Status:         Running</p>
  
  <p>IP:             10.1.0.43</p>
  
  <p>IPs:            </p>
  
  <p>Controlled By:  ReplicaSet/sv-premier-6b77ddd747</p>
  
  <p>Containers:</p>
  
  <p>sv-premierleague:</p>

<pre><code>Container ID:  docker://141126d732409427fe39b405865f88856ac4e1d8586112797fc5bf4fdfbe317c

Image:         gcr.io/proto/premiercore1:latest

Image ID:      docker-pullable://gcr.io/proto/premiercore1@sha256:b3800ccca3f30725d5c9235dd349548f0fcfe309f51883d8af16397aef2c3953

Port:          8080/TCP

Host Port:     0/TCP

Command:

  echo

  Done deploying sv-premier

State:          Waiting

  Reason:       CrashLoopBackOff

Last State:     Terminated

  Reason:       Completed

  Exit Code:    0

  Started:      Tue, 04 Feb 2020 15:00:51 +0530

  Finished:     Tue, 04 Feb 2020 15:00:51 +0530

Ready:          False

Restart Count:  13

Environment:

  GOOGLE_APPLICATION_CREDENTIALS:  /var/secrets/google/key.json

Mounts:

  /var/run/secrets/kubernetes.io/serviceaccount from default-token-s4jgd (ro)

  /var/secrets/google from google-cloud-key (rw)
</code></pre>
  
  <p>Conditions:</p>
  
  <p>Type              Status</p>
  
  <p>Initialized       True </p>
  
  <p>Ready             False </p>
  
  <p>ContainersReady   False </p>
  
  <p>PodScheduled      True </p>
  
  <p>Volumes:</p>
  
  <p>google-cloud-key:</p>

<pre><code>Type:        Secret (a volume populated by a Secret)

SecretName:  gcp-key

Optional:    false
</code></pre>
  
  <p>default-token-s4jgd:</p>

<pre><code>Type:        Secret (a volume populated by a Secret)

SecretName:  default-token-s4jgd

Optional:    false
</code></pre>
  
  <p>QoS Class:       BestEffort</p>
  
  <p>Node-Selectors:  </p>
  
  <p>Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s</p>

<pre><code>             node.kubernetes.io/unreachable:NoExecute for 300s
</code></pre>
  
  <p>Events:</p>
  
  <p>Type     Reason     Age                  From<br>
  Message</p>
  
  <h2>  ----     ------     ----                 ----</h2>
  
  <p>Normal   Scheduled  46m                  default-scheduler<br>
  Successfully assigned default/sv-premier-6b77ddd747-cvdr5 to
  docker-desktop</p>
  
  <p>Normal   Pulled     45m (x4 over 46m)    kubelet, docker-desktop 
  Successfully pulled image
  "gcr.io/proto/premiercore1:latest"</p>
  
  <p>Normal   Created    45m (x4 over 46m)    kubelet, docker-desktop 
  Created container sv-premier</p>
  
  <p>Normal   Started    45m (x4 over 46m)    kubelet, docker-desktop 
  Started container sv-premier</p>
  
  <p>Normal   Pulling    45m (x5 over 46m)    kubelet, docker-desktop 
  Pulling image "gcr.io/proto/premiercore1:latest"</p>
  
  <p>Warning  BackOff    92s (x207 over 46m)  kubelet, docker-desktop 
  Back-off restarting failed container</p>
</blockquote>

<p>=======================</p>

<p>And output for - </p>

<blockquote>
  <p>kubectl logs podname --> <em>Done Deploying sv-premier</em></p>
</blockquote>

<p>I am confused why my container is exiting. not able to start.</p>

<p>Kindly guide please.</p>

<p>Update your deployment.yaml with a long running task example.</p>

<pre><code>command: ["/bin/sh"]
args: ["-c", "while true; do echo Done Deploying sv-premier; sleep 3600;done"]
</code></pre>

<p>This will put your container to sleep after deployment and every hour it will log the message.</p>

<p>Read more about <a href="https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/" rel="nofollow noreferrer">pod lifecycle</a> container states <a href="https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#container-states" rel="nofollow noreferrer">here</a></p>
