kubectl get pods显示CrashLoopBackoff

时间:2019-03-28 09:09:30

标签: kubernetes kubectl minikube

我正在尝试使用本地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获取豆荚日志

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');
    });

3 个答案:

答案 0 :(得分:2)

尝试使用命令kubectl logs -f my-first-pod

检查日志

答案 1 :(得分:1)

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" ]

我认为您的Pod在index.js内执行脚本后会终止

答案 2 :(得分:1)

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

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映像的很好的解释。

相关问题