这就是我一直得到的答案:

[root@centos-master ~]# kubectl get pods
NAME               READY     STATUS             RESTARTS   AGE
nfs-server-h6nw8   1/1       Running            0          1h
nfs-web-07rxz      0/1       CrashLoopBackOff   8          16m
nfs-web-fdr9h      0/1       CrashLoopBackOff   8          16m

下面是描述pods的输出 Kubectl描述了豆荚

Events:
  FirstSeen LastSeen    Count   From                SubobjectPath       Type        Reason      Message
  --------- --------    -----   ----                -------------       --------    ------      -------
  16m       16m     1   {default-scheduler }                    Normal      Scheduled   Successfully assigned nfs-web-fdr9h to centos-minion-2
  16m       16m     1   {kubelet centos-minion-2}   spec.containers{web}    Normal      Created     Created container with docker id 495fcbb06836
  16m       16m     1   {kubelet centos-minion-2}   spec.containers{web}    Normal      Started     Started container with docker id 495fcbb06836
  16m       16m     1   {kubelet centos-minion-2}   spec.containers{web}    Normal      Started     Started container with docker id d56f34ae4e8f
  16m       16m     1   {kubelet centos-minion-2}   spec.containers{web}    Normal      Created     Created container with docker id d56f34ae4e8f
  16m       16m     2   {kubelet centos-minion-2}               Warning     FailedSync  Error syncing pod, skipping: failed to "StartContainer" for "web" with CrashLoopBackOff: "Back-off 10s restarting failed container=web pod=nfs-web-fdr9h_default(461c937d-d870-11e6-98de-005056040cc2)"

我有两个pod: nfs-web-07rxz, nfs-web-fdr9h,但如果我做kubectl日志nfs-web-07rxz或带-p选项,我在两个pod中都看不到任何日志。

[root@centos-master ~]# kubectl logs nfs-web-07rxz -p
[root@centos-master ~]# kubectl logs nfs-web-07rxz

这是我的replicationController yaml文件: replicationController yaml文件

apiVersion: v1 kind: ReplicationController metadata:   name: nfs-web spec:   replicas: 2   selector:
    role: web-frontend   template:
    metadata:
      labels:
        role: web-frontend
    spec:
      containers:
      - name: web
        image: eso-cmbu-docker.artifactory.eng.vmware.com/demo-container:demo-version3.0
        ports:
          - name: web
            containerPort: 80
        securityContext:
          privileged: true

我的Docker镜像是由这个简单的Docker文件制作的:

FROM ubuntu
RUN apt-get update
RUN apt-get install -y nginx
RUN apt-get install -y nfs-common

我在CentOs-1611上运行我的kubernetes集群,kube版本:

[root@centos-master ~]# kubectl version
Client Version: version.Info{Major:"1", Minor:"3", GitVersion:"v1.3.0", GitCommit:"86dc49aa137175378ac7fba7751c3d3e7f18e5fc", GitTreeState:"clean", BuildDate:"2016-12-15T16:57:18Z", GoVersion:"go1.6.3", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"3", GitVersion:"v1.3.0", GitCommit:"86dc49aa137175378ac7fba7751c3d3e7f18e5fc", GitTreeState:"clean", BuildDate:"2016-12-15T16:57:18Z", GoVersion:"go1.6.3", Compiler:"gc", Platform:"linux/amd64"}

如果我通过docker run运行docker映像,我能够运行映像而没有任何问题,只有通过kubernetes我得到了崩溃。

有人能帮我一下吗,我怎么调试而不看到任何日志?


当前回答

在你的yaml文件中,添加命令行和参数行:

...
containers:
      - name: api
        image: localhost:5000/image-name 
        command: [ "sleep" ]
        args: [ "infinity" ]
...

对我有用。

其他回答

当我执行'docker run xxx '命令时,我终于找到了解决方案,然后我得到了错误。这是由于平台不完整造成的。

在这个页面中,容器在正确运行一切之后死亡,但由于所有命令结束而崩溃。要么让服务在前台运行,要么创建一个keep alive脚本。通过这样做,Kubernetes将显示您的应用程序正在运行。我们必须注意到,在Docker环境中,不会遇到这个问题。只有Kubernetes想要一个可运行的应用程序。

更新(示例):

下面是如何在启动Netshoot容器时避免CrashLoopBackOff:

kubectl run netshoot --image nicolaka/netshoot -- sleep infinity

在我的例子中,问题是错误的命令行参数列表。我在我的部署文件中这样做:

...
args:
  - "--foo 10"
  - "--bar 100"

而不是正确的方法:

...
args:
  - "--foo"
  - "10"
  - "--bar"
  - "100"

如果您的应用程序启动速度较慢,这可能与就绪/活动探测的初始值有关。我通过将initialDelaySeconds的值增加到120s来解决我的问题,因为我的SpringBoot应用程序要处理大量的初始化。文档中没有提到默认的0 (https://kubernetes.io/docs/api-reference/v1.9/#probe-v1-core)

service:
  livenessProbe:
    httpGet:
      path: /health/local
      scheme: HTTP
      port: 8888
    initialDelaySeconds: 120
    periodSeconds: 5
    timeoutSeconds: 5
    failureThreshold: 10
  readinessProbe:
    httpGet:
      path: /admin/health
      scheme: HTTP
      port: 8642
    initialDelaySeconds: 150
    periodSeconds: 5
    timeoutSeconds: 5
    failureThreshold: 10

对于这些值,initialDelaySeconds的默认值是什么给出了一个很好的解释。

运行状况或就绪状态检查算法的工作方式如下: 等待initialDelaySeconds 执行check并等待timeoutSeconds超时 如果连续成功的次数大于successThreshold返回成功 如果连续失败的次数大于failureThreshold,则返回失败,否则等待periodSeconds并开始新的检查

在我的例子中,我的应用程序现在可以以一种非常清晰的方式引导,因此我知道我不会得到周期性的崩溃回退,因为有时它会达到这些速率的极限。

正如@Sukumar评论的那样,你需要让你的Dockerfile有一个命令来运行,或者让你的ReplicationController指定一个命令。

吊舱崩溃是因为它启动后立即退出,因此Kubernetes重新启动,循环继续。