3

I want to build a troube shooting pod, this is my Dockerbuild file:

FROM alpine:3.11

MAINTAINER jiangxiaoqiang (jiangtingqiang@gmail.com)

ENV LANG=en_US.UTF-8 \
    LC_ALL=en_US.UTF-8 \
    TZ=Asia/Shanghai


RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime \
    && echo $TZ > /etc/timezone \
    && apk add --no-cache curl jq \
    nmap \
    bind-tools \
    busybox-extras \
    bash


CMD ["/bin/bash","-l"]

but when I start it in kubernetes cluster, it shows: Back-off restarting failed container, and always restart all the time. so simple docker container ,why give me this tips? this is the descibe output:

[root@k8smaster ~]# kubectl describe pod ts-7d754488b9-jqqh9
Name:         ts-7d754488b9-jqqh9
Namespace:    default
Priority:     0
Node:         k8sslave2/192.168.31.31
Start Time:   Wed, 02 Sep 2020 12:28:48 -0400
Labels:       k8s-app=ts
              pod-template-hash=7d754488b9
Annotations:  cni.projectcalico.org/podIP: 10.11.125.135/32
Status:       Running
IP:           10.11.125.135
IPs:
  IP:           10.11.125.135
Controlled By:  ReplicaSet/ts-7d754488b9
Containers:
  ts:
    Container ID:   docker://0c810ed8f8ec1cde6c0249edde59fc28a169d5730e87c423403f802cd12df6dd
    Image:          registry.cn-shanghai.aliyuncs.com/jiangxiaoqiang/dolphin/k8s-ts:v0.0.1
    Image ID:       docker-pullable://registry.cn-shanghai.aliyuncs.com/jiangxiaoqiang/dolphin/k8s-ts@sha256:68edaed45c1fadee71abbe7bdaad23f2400f352f1b6309142689a197367f3ae9
    Port:           <none>
    Host Port:      <none>
    State:          Waiting
      Reason:       CrashLoopBackOff
    Last State:     Terminated
      Reason:       Completed
      Exit Code:    0
      Started:      Wed, 02 Sep 2020 12:30:13 -0400
      Finished:     Wed, 02 Sep 2020 12:30:13 -0400
    Ready:          False
    Restart Count:  4
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-79w95 (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             False 
  ContainersReady   False 
  PodScheduled      True 
Volumes:
  default-token-79w95:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-79w95
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:
  Type     Reason     Age                  From                Message
  ----     ------     ----                 ----                -------
  Normal   Scheduled  <unknown>            default-scheduler   Successfully assigned default/ts-7d754488b9-jqqh9 to k8sslave2
  Normal   Created    96s (x4 over 2m17s)  kubelet, k8sslave2  Created container ts
  Normal   Started    95s (x4 over 2m16s)  kubelet, k8sslave2  Started container ts
  Warning  BackOff    69s (x7 over 2m15s)  kubelet, k8sslave2  Back-off restarting failed container
  Normal   Pulling    54s (x5 over 2m17s)  kubelet, k8sslave2  Pulling image "registry.cn-shanghai.aliyuncs.com/jiangxiaoqiang/dolphin/k8s-ts:v0.0.1"
  Normal   Pulled     54s (x5 over 2m17s)  kubelet, k8sslave2  Successfully pulled image "registry.cn-shanghai.aliyuncs.com/jiangxiaoqiang/dolphin/k8s-ts:v0.0.1"
Dolphin
  • 29,069
  • 61
  • 260
  • 539

1 Answers1

4

The container is completed means it is finished it's execution task. If you wish the container should run for specific time then pass eg . sleep 3600 as argument or you can use restartPolicy: Never in your deployment file.

something like this

spec:
  containers:
  - image: alpine
    command:
      - /bin/sh
      - "-c"
      - "sleep 60m"
    imagePullPolicy: Always
    restartPolicy: Never
    name: alpine
Dashrath Mundkar
  • 7,956
  • 2
  • 28
  • 42