测试docker容器的Kubernetes pod 失败



我一直在尝试为我的测试容器部署dockerfile,如下所示,当部署在Kubernetes上时,Pod进入CrashLoopBackOff。失败的可能原因是什么?

Dockerfile for my test container:

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

在kubernetes上部署容器时的状态(描述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

入口点为:"nc -l 8080 &"

netcat的行为是:处理请求→打印到stdout→退出

所以你的第一个健康检查:http-get http://:8080/sadf/healthcheck delay=30s timeout=1s period=15s #success=1 #failure=3做这个第一个请求,之后nc退出。因为它:#success=1 #failure=3

例如,你可以设置entrypoint为

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

while循环将重启nc当它退出

另一个(更好的)选择是使用-k(--keep-open)参数来保持nc连接打开:

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

相关内容

  • 没有找到相关文章