简体   繁体   English

httpd Docker 图像 CrashLoopBackOff 在 Kubernetes

[英]httpd Docker image CrashLoopBackOff on Kubernetes

I have a simple docker image which is working fine locally.我有一个简单的 docker 图像,它在本地运行良好。 It is basically the same as the example on apache's httpd page.它与 apache 的httpd 页面上的示例基本相同。

FROM httpd:2.4
COPY ./public-html/ /usr/local/apache2/htdocs/

As per the page example, I can build and run my image as follows:根据页面示例,我可以按如下方式构建和运行我的图像:

$ docker build -t gcr.io/${PROJECT_ID}/hello-app:v1.

$ docker run -dit --name my-running-app -p 8080:80 <img_id>

I then head over to http://localhost:8080, and everything seems to be working as it should.然后我前往 http://localhost:8080,一切似乎都在正常工作。

However, when I try to create a deployment for my Google Cloud Kubernetes instance, my pod fails and gets to the state of CrashLoopBackOff .但是,当我尝试为我的 Google Cloud Kubernetes 实例创建部署时,我的 pod 失败并到达 CrashLoopBackOff 的CrashLoopBackOff (This is after I have pushed the image to Google Cloud Registry, so that the deployment may grab the image from there.) (这是在我将图像推送到 Google Cloud Registry 之后,以便部署可以从那里获取图像。)

I think that this CrashLoopBackOff problem is happening due to me not having an ENTRYPOINT to my container;我认为这个CrashLoopBackOff问题是由于我的容器没有ENTRYPOINT而发生的; ie, the pod spawns, no command is issued, and then it is completed and crashes.即,pod 生成,没有发出任何命令,然后它完成并崩溃。

I have 2 questions then:那我有2个问题:

  1. What command should I add to my Dockerfile to get the http server up and running on the pod (assuming my assessment of the problem is indeed correct)?我应该向我的 Dockerfile 添加什么命令来启动 http 服务器并在 pod 上运行(假设我对问题的评估确实正确)?
  2. How is this running locally?这是如何在本地运行的? Locally I simply $ docker run -dit --name my-running-app -p 8080:80 <img_id> .在本地,我只是$ docker run -dit --name my-running-app -p 8080:80 <img_id> I do not specify that the container should run httpd, yet it does?我没有指定容器应该运行 httpd,但它可以吗? How is this happening?这是怎么回事?

Edit - additional information:编辑 - 附加信息:

I deployed onto K8's by doing the following:我通过执行以下操作部署到 K8 上:

$ kubectl create deployment hello-app --image=gcr.io/${PROJECT_ID}/hello-app:v1

Kubectl logs: Kubectl 日志:

$ kubectl logs <pod_name>

standard_init_linux.go:211: exec user process caused "exec format error"

kubectl describe: kubectl 描述:

$ kubectl describe pod hello-app-6b89cd98f6-gn65p

Name:         <name>
Namespace:    default
Priority:     0
Node:         <my_node>
Start Time:   Mon, 22 Mar 2021 12:32:51 +0200
Labels:       app=hello-app
              pod-template-hash=6b89cd98f6
Annotations:  <none>
Status:       Running
IP:           10.12.1.13
IPs:
  IP:           10.12.1.13
Controlled By:  <replica_set>
Containers:
  hello-app:
    Container ID:   <cid>
    Image:          <img>
    Image ID:       <img_id>
    Port:           <none>
    Host Port:      <none>
    State:          Waiting
      Reason:       CrashLoopBackOff
    Last State:     Terminated
      Reason:       Error
      Exit Code:    1
      Started:      Mon, 22 Mar 2021 15:12:18 +0200
      Finished:     Mon, 22 Mar 2021 15:12:18 +0200
    Ready:          False
    Restart Count:  36
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-b8p9t (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             False 
  ContainersReady   False 
  PodScheduled      True 
Volumes:
  default-token-b8p9t:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-b8p9t
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                 node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type     Reason   Age                    From     Message
  ----     ------   ----                   ----     -------
  Warning  BackOff  4m9s (x741 over 164m)  kubelet  Back-off restarting failed container

CrashLoopBackOff error means the pod keeps crashing and kubernetes has given up on it. CrashLoopBackOff错误意味着 pod 不断崩溃,并且 kubernetes 已放弃它。 You have to determine what is causing the crash.您必须确定导致崩溃的原因。 Overally the cause of problem may be that:总的来说,问题的原因可能是:

You can type watch kubectl describe <pod-name> to check events as the pod is being created.您可以键入watch kubectl describe <pod-name>在创建 pod 时检查事件。 But if the pod crashes after it starts up, you need to get the container logs kubectl logs -f <your-pod-name> .但是如果 Pod 启动后崩溃了,你需要获取容器日志kubectl logs -f <your-pod-name>

Read more: kubernetes-crashloopbackoff .阅读更多: kubernetes-crashloopbackoff

As @ Krishna Chaurasia said check the thread which is implying that the default command being run is not an executable - executable formats could be different for different platforms.正如@ Krishna Chaurasia所说,检查暗示正在运行的默认命令不是可执行文件的线程- 不同平台的可执行格式可能不同。 As @ Sagar Velankar mentioned use in Docker file in FROM line --platform flag to specify linux/amd64 as the target architecture.正如@Sagar Velankar提到的,在FROM行中的 Docker 文件中使用--platform标志指定 linux/amd64 作为目标架构。 See: dockerfile-from .请参阅: dockerfile-from

You can use docker buildx docs.docker.com/docker-for-mac/multi-arch to build and push multi architecture images and kubelet will pull the image with correct architecture.您可以使用docker buildx docs.docker.com/docker-for-mac/multi-arch来构建和推送多架构镜像,kubelet 将使用正确架构拉取镜像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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