Could the status be "Running" if I run "kubectl get pod freebox"?

12/5/2020

Apply the following YAML file into a Kubernetes cluster:

apiVersion: v1
kind: Pod
metadata:
  name: freebox
spec:
  containers:
  - name: busybox
    image: busybox:latest
    imagePullPolicy: IfNotPresent

Could the status be "Running" if I run kubectl get pod freebox? Why?

-- qqwenwenti
kubernetes

2 Answers

12/5/2020

If formatting errors are ignored , no pod wont be in running status :

controlplane $ kubectl get pods freebox
NAME      READY   STATUS             RESTARTS   AGE
freebox   0/1     CrashLoopBackOff   3          81s

Becuase if you look at Dockerfile of busy box , The CMD argument "sh" which will complete immediately so pod gets restarted ( becuase default restart policy is always')

https://hub.docker.com/layers/busybox/library/busybox/latest/images/sha256-bc02457f8f5a4a3cd931028ec76c7468cfa8b44d7d89c4a91df1fd82285da681?context=explore

ADD file ... in /708.51 KB
CMD ["sh"]

see the describe of the pod as following :

Events:
  Type     Reason     Age              From               Message
  ----     ------     ----             ----               -------
  Normal   Scheduled  8s               default-scheduler  Successfully assigned default/freebox to node01
  Normal   Pulled     7s (x2 over 8s)  kubelet, node01    Container image "busybox:latest" already present on machine
  Normal   Created    6s (x2 over 7s)  kubelet, node01    Created container busybox
  Normal   Started    6s (x2 over 7s)  kubelet, node01    Started container busybox
  Warning  BackOff    5s (x2 over 6s)  kubelet, node01    Back-off restarting failed container
-- confused genius
Source: StackOverflow

12/5/2020

the busybox image need to run a command for running.

add the command in the .spec.containers section under the busybox container

apiVersion: v1
kind: Pod
metadata:
  name: freebox
spec:
  containers:
  - name: busybox
    command:
    - sleep
    - 4800
    image: busybox:latest
    imagePullPolicy: IfNotPresent
-- SAEED mohassel
Source: StackOverflow