【问题标题】:Kubernetes pod keeps crashing with no error in logsKubernetes pod 不断崩溃,日志中没有错误
【发布时间】:2021-09-20 01:05:06
【问题描述】:

我正在尝试在 Kubernetes 集群上使用 Terraform 部署 apache docker 映像

我尝试了以下命令,并成功从浏览器中访问了 URL localhost:8082

docker run -it --rm -d -p 8082:80 webservice

然后我使用 Terraform 创建了一个 kubernetes_deployment,但 pod 不断崩溃并且there's nothing in logs

resource "kubernetes_deployment" "api" {
  metadata {
    name = "ex-api"
    labels = {
      app       = "EX"
      component = "api"
    }
  }
  spec {
    replicas = 1
    selector {
      match_labels = {
        app = "EX"
      }
    }
    template {
      metadata {
        name = "ex-api"
        labels = {
          app       = "EX"
          component = "api"
        }
      }
      spec {
        container {
          image             = "${var.web_service_image}:${var.web_service_image_tag}"
          image_pull_policy = "IfNotPresent"
          name              = "api-image"

          # All the other configuration options should be here too.
          port {
            container_port = 80
            name           = "web"
          }
        }  # end of container block

      } # end of spec block
    } # end of template block
  } # end of spec out-block
}

Pod 的输出

kubectl get pod
NAME                      READY   STATUS             RESTARTS   AGE
ex-api-5458586bd8-ex6sp   0/1     CrashLoopBackOff   19         72m

我假设我应该添加一些command or daemonize(例如,使用 docker 时的 -itd)以便它继续运行。我这里可能错了

请告诉我该怎么做才能克服这个问题

【问题讨论】:

  • 你试过描述吗? kubectl describe po ex-api-5458586bd8-ex6sp 有时你会得到一些提示
  • 我试过了,但我没有看到任何错误。 kubectl logs -p 也没有产生任何日志
  • 您的部署需要使用 Dockerfile 中的命令。
  • 粘贴您的 Dockerfile、Deployment.yaml 和 describe 命令的输出。
  • 正如你提到的,我在我的 kubernetes 部署中添加了“command = [apache2-foreground]”,问题得到了解决。但是,我不明白为什么要在 K8S 部署中明确提及该命令,而 docker 映像本身具有“apache2-foreground”。感谢您指出帮助我解决问题的错误

标签: docker kubernetes terraform


【解决方案1】:

运行 describe 命令时未显示日志或未显示事件通常表明在 Dockerfile 中调用入口点存在问题。因此,您可能必须覆盖 deployment.yaml 中的命令

在您的情况下 - 您的部署可能需要使用您在 Dockerfile 中拥有或尝试使用的命令。显然,kubernetes pod 无法使用您在 Dockerfile 中定义的内容。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-27
    • 1970-01-01
    • 2021-05-05
    • 1970-01-01
    • 2018-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多