【问题标题】:kubectl get pods shows CrashLoopBackoffkubectl get pods 显示 CrashLoopBackoff
【发布时间】:2019-04-02 22:02:27
【问题描述】:

我正在尝试使用我的本地 docker 映像创建一个 pod,如下所示。

1.首先我在终端运行这个命令

eval $(minikube docker-env)

2.我创建了一个docker镜像如下

sudo docker image build -t my-first-image:3.0.0 .

3.我创建了如下所示的 pod.yml 并运行此命令

kubectl -f create pod.yml.

4.然后我尝试运行这个命令

kubectl get pods

但它显示以下错误


NAME                                  READY   STATUS             RESTARTS   AGE
multiplication-6b6d99554-d62kk        0/1     CrashLoopBackOff   9          22m
multiplication2019-5b4555bcf4-nsgkm   0/1     CrashLoopBackOff   8          17m
my-first-pod                          0/1     CrashLoopBackOff   4          2m51

5.i 获取 pod 日志

kubectl describe pod my-first-pod 

Events:
  Type     Reason     Age                    From               Message
  ----     ------     ----                   ----               -------
  Normal   Scheduled  6m22s                  default-scheduler  Successfully assigned default/my-first-pod to minikube
  Normal   Pulled     5m20s (x4 over 6m17s)  kubelet, minikube  Successfully pulled image "docker77nira/myfirstimage:latest"
  Normal   Created    5m20s (x4 over 6m17s)  kubelet, minikube  Created container
  Normal   Started    5m20s (x4 over 6m17s)  kubelet, minikube  Started container
  Normal   Pulling    4m39s (x5 over 6m21s)  kubelet, minikube  pulling image "docker77nira/myfirstimage:latest"
  Warning  BackOff    71s (x26 over 6m12s)   kubelet, minikube  Back-off restarting failed container


Dockerfile

    FROM node:carbon
    WORKDIR /app
    COPY . .
    CMD [ "node", "index.js" ]

pods.yml

    kind: Pod
    apiVersion: v1
    metadata:
     name: my-first-pod
    spec:
     containers:
     - name: my-first-container
       image: my-first-image:3.0.0

index.js

    var http = require('http');
    var server = http.createServer(function(request, response) {
     response.statusCode = 200;
     response.setHeader('Content-Type', 'text/plain');
     response.end('Welcome to the Golden Guide to Kubernetes
    Application Development!');
    });
    server.listen(3000, function() {
     console.log('Server running on port 3000');
    });

【问题讨论】:

    标签: kubernetes kubectl minikube


    【解决方案1】:

    尝试使用命令kubectl logs -f my-first-pod检查日志

    【讨论】:

    • 详细一点,CrashLoopBackOff 表示每次创建容器时你的服务都会崩溃,所以你需要在启动时找出你的服务出了什么问题。
    【解决方案2】:

    我通过执行以下步骤成功运行了您的图像:

    docker build -t foo .

    然后检查容器是否工作docker run -it foo

    /app/index.js:5
    response.end('Welcome to the Golden Guide to Kubernetes
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    
    SyntaxError: Invalid or unexpected token
        at createScript (vm.js:80:10)
        at Object.runInThisContext (vm.js:139:10)
        at Module._compile (module.js:617:28)
        at Object.Module._extensions..js (module.js:664:10)
        at Module.load (module.js:566:32)
        at tryModuleLoad (module.js:506:12)
        at Function.Module._load (module.js:498:3)
        at Function.Module.runMain (module.js:694:10)
        at startup (bootstrap_node.js:204:16)
        at bootstrap_node.js:625:3
    

    不确定这是否是您想要看到的结果,容器本身会运行。但在 Kubernetes 中,它进入了 ErrImagePull

    然后在编辑受@Harsh Manvar 启发的 Pod.yaml 之后,它可以正常工作。因此,完成命令后退出的问题只是问题的一部分。

    apiVersion: v1
    kind: Pod
    metadata:
      name: hello-pod
    spec:
      restartPolicy: Never
      containers:
      - name: hello
        image: "foo"
        imagePullPolicy: Never
        command: [ "sleep" ]
        args: [ "infinity" ]
    

    这是 Minikube,因此您可以重复使用图像,但如果您有更多节点,这可能根本不起作用。你可以找到关于在 Kubernetes here 中使用本地 docker 镜像的很好的解释。

    【讨论】:

      【解决方案3】:
      kind: Pod
          apiVersion: v1
          metadata:
           name: my-first-pod
          spec:
           containers:
           - name: my-first-container
             image: my-first-image:3.0.0
             command: [ "sleep" ]
             args: [ "infinity" ]
      

      我认为在 index.js 中执行脚本后,您的 pod 将被终止

      【讨论】:

        猜你喜欢
        • 2021-10-06
        • 1970-01-01
        • 1970-01-01
        • 2021-11-05
        • 2020-09-15
        • 1970-01-01
        • 2019-04-02
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多