简体   繁体   中英

failed Kubernetes pod of a test docker container

I have been trying out to deploy a test container with the dockerfile for my test container as below which when deployed on the Kubernetes the Pod goes into CrashLoopBackOff. What would be the possible reasons for the failure ?

Dockerfile for my test container:

FROM docker.asdfasdf.com/alpine:3.14
RUN apk add netcat-openbsd
ENTRYPOINT ["/bin/sh", "-c", "nc -l 8080 &"]

State of the container when deployed on kubernetes (describe pod info)

main:
    Container ID:   docker://d845d4fb4asdf78sdfasdf8asdfasdf9asdfasda7
    Image:          asdf.sdfad.com/xyz/test1:asdfasdfasdfasdf
    Image ID:       docker-pullable://asdf.sdfad.com/xyz/test1:asdfasdfasdfasdf@sha256:a643c0e227a27ds5d4e78a9b50b894e1c934d95f88ddsdswvbc
    Ports:          8080/TCP, 8081/TCP
    Host Ports:     0/TCP, 0/TCP
    State:          Waiting
      Reason:       CrashLoopBackOff
    Last State:     Terminated
      Reason:       Completed
      Exit Code:    0
      Started:      Thu, 26 May 2022 00:01:55 +0100
      Finished:     Thu, 26 May 2022 00:01:55 +0100
    Ready:          False
    Restart Count:  6
    Limits:
      memory:  1Gi
    Requests:
      cpu:      1
      memory:   500Mi
    Liveness:   http-get http://:8080/sadf/healthcheck delay=30s timeout=1s period=15s #success=1 #failure=3
    Readiness:  http-get http://:8080/asdf/healthcheck delay=20s timeout=1s period=5s #success=1 #failure=3
Events:
  Type     Reason               Age                From               Message
  ----     ------               ----               ----               -------

Normal   Created              10m (x2 over 10m)  kubelet            Created container main
  Warning  FailedPreStopHook    10m (x2 over 10m)  kubelet            Exec lifecycle hook ([sh -c rm heartbeat.txt && sleep 30]) for Container "main" in Pod "test1--avi--default-76b6d7c76b-s9jdt_test1-dev(asdfc-ava45-45ae-78d-fgghh7765532)" failed - error: rpc error: code = Unknown desc = container not running (main), message: ""
  Normal   Killing              10m (x2 over 10m)  kubelet            FailedPostStartHook
  Warning  FailedPostStartHook  10m (x2 over 10m)  kubelet            Exec lifecycle hook ([sh -c dirname heartbeat.txt | xargs mkdir -p && touch heartbeat.txt
]) for Container "main" in Pod "test1--avi--default-76b6d7c76b-s9jdt_test1-dev(asdfc-ava45-45ae-78d-fgghh7765532)" failed - error: rpc error: code = Unknown desc = container not running (main), message: ""
  Normal   Started  10m (x2 over 10m)   kubelet  Started container main
  Warning  BackOff  21s (x58 over 10m)  kubelet  Back-off restarting failed container

Entrypoint is: "nc -l 8080 &"

netcat behavior is: handle request → print it into stdout → exit

So your first healthcheck: http-get http://:8080/sadf/healthcheck delay=30s timeout=1s period=15s #success=1 #failure=3 doing this first request and after that nc exiting. Because of it: #success=1 #failure=3

For example you may set entrypoint as

["/bin/sh", "-c", "while true; do nc -l 8080; echo 'restarting netcat'; done"]

while loop will restart nc anytime it exit

Another (better) option is to use -k ( --keep-open ) argument to keep nc connection open:

ENTRYPOINT ["nc", "-k", "-l", "8080"]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM