2017-02-12 133 views
3

我正在用一個init容器創建一個複製控制器。然而,起始容器無法啓動,並在吊艙的現狀是:kubernetes init容器CrashLoopBackOff

NAME      READY  STATUS    RESTARTS AGE 
testcontainer 0/1  CrashLoopBackOff 12   37m 

我不知道哪一部分是失敗的準確,並且日誌沒有幫助。 我kubectl服務器版本是1.4(從客戶端版本不同),所以我使用:

annotations: 
     pod.beta.kubernetes.io/init-containers: 

這裏是我使用的複製控制器YAML文件。 我現在用的是「你好,世界」的圖像(而不是nginx的,使其更快)

apiVersion: v1 
kind: ReplicationController 
metadata: 
    name: testcontainer 
spec: 
    replicas: 1 
    selector: 
    app: nginx 
    template: 
    metadata: 
     labels: 
     app: nginx 
     annotations: 
     pod.beta.kubernetes.io/init-containers: '[ 
      { 
       "name": "install", 
       "image": "hello-world" 
      } 
     ]' 
    spec: 
     containers: 
     - name: nginx 
     image: hello-world 
     dnsPolicy: Default 
     nodeName: x.x.x.x 

原木kubectl描述莢:

Warning FailedSync  Error syncing pod, skipping: failed to "StartContainer" for "nginx" with CrashLoopBackOff: "Back-off 5m0s restarting failed container=nginx pod=testcontainer()" 

    32m 16s  145  {kubelet x.x.x.x} spec.containers{nginx} Warning BackOff Back-off restarting failed docker container 

當我檢查兩個容器的日誌( nginx和testcontainer),它顯示了運行hello-world圖像的輸出,所以我猜圖像已經下載併成功啓動。我不知道什麼失敗後(我甚至嘗試創建一個單一的莢,使用https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-initialization/#creating-a-pod-that-has-an-init-container提供的例子,但仍然失敗)

謝謝!

回答

1

我認爲這裏的問題不是init容器。 hello-world圖像打印文本並立即退出。由於該機架的.spec.restartPolicy默認爲Always,因此每次只重新啓動一次機架。

該錯誤消息可能有點令人困惑,但由於pod旨在永久運行,因此即使退出代碼爲0,但顯示錯誤也是非常有意義的。

如果您只想一次運行一個窗格,則應該使用job API


既然你有興趣爲init-容器的例子,我定你的例子:

apiVersion: v1 
kind: ReplicationController 
metadata: 
    name: testcontainer 
spec: 
    replicas: 1 
    selector: 
    app: nginx 
    template: 
    metadata: 
     labels: 
     app: nginx 
     annotations: 
     pod.beta.kubernetes.io/init-containers: '[ 
      { 
       "name": "install", 
       "image": "hello-world" 
      } 
     ]' 
    spec: 
     containers: 
     - name: nginx 
     image: nginx # <--- this image shouldn't be a single shot application 
     dnsPolicy: Default 
     nodeName: x.x.x.x 
+0

嗨svenwltr 我想在init cotainer(安裝)將運行,如果成功了應用程序容器(nginx)將啓動。如果init容器成功,爲什麼它會重新啓動? (不應該「總是」重新啓動策略,只有當它失敗時才適用) 我也嘗試過這個例子,並且init容器仍然失敗: https://kubernetes.io/docs/tasks/configure-pod-container/configure -pod-initialization /#created-a-pod-that-has-an-init-container 我看到「PodInitializig」,但它永遠不會完成。 – greg

+0

換句話說,我如何擁有一個用hello-world映像運行的複製控制器(不是作業)的init容器? – greg

+0

你的init容器運行正常,但在你的init容器後,名爲'nginx'的容器就會啓動。這個容器也使用hello-world圖像。你需要更換這張圖片。 – svenwltr