0

我執行了以下步驟。Kubernetes複製控制器在CrashLoopBackOff狀態

創建了以下配置文件複製控制器:

{ 
    "kind":"ReplicationController", 
    "apiVersion":"v1", 
    "metadata":{ 
     "name":"fsharp-service", 
     "labels":{ 
     "app":"fsharp-service" 
     } 
    }, 
    "spec":{ 
     "replicas":1, 
     "selector":{ 
     "app":"fsharp-service" 
     }, 
     "template":{ 
     "metadata":{ 
      "labels":{ 
       "app":"fsharp-service" 
      } 
     }, 
     "spec":{ 
      "containers":[ 
       { 
        "name":"fsharp-service", 
        "image":"fsharp/fsharp:latest", 
        "ports":[ 
        { 
         "name":"http-server", 
         "containerPort":3000 
        } 
        ] 
       } 
      ] 
     } 
     } 
    } 
} 

運行命令:

kubectl create -f fsharp-controller.json 

這裏是輸出:

$ kubectl get rc 
CONTROLLER  CONTAINER(S)  IMAGE(S)        SELECTOR    REPLICAS 
cassandra  cassandra  gcr.io/google-samples/cassandra:v8 app=cassandra  3 
fsharp-service fsharp-service fsharp/fsharp:latest     app=fsharp-service 1 
$ kubectl get pods 
NAME     READY  REASON RESTARTS AGE 
cassandra    1/1  Running 0   28m 
cassandra-ch1br  1/1  Running 0   28m 
cassandra-xog49  1/1  Running 0   27m 
fsharp-service-7lrq8 0/1  Error  2   31s 
$ kubectl logs fsharp-service-7lrq8 

F# Interactive for F# 4.0 (Open Source Edition) 
Freely distributed under the Apache 2.0 Open Source License 

For help type #help;; 

$ kubectl get pods 
NAME     READY  REASON    RESTARTS AGE 
cassandra    1/1  Running   0   28m 
cassandra-ch1br  1/1  Running   0   28m 
cassandra-xog49  1/1  Running   0   28m 
fsharp-service-7lrq8 0/1  CrashLoopBackOff 3   1m 
$ kubectl describe po fsharp-service-7lrq8 
W0417 15:52:36.288492 11461 request.go:302] field selector: v1 - events - involvedObject.name - fsharp-service-7lrq8: need to check if this is versioned correctly. 
W0417 15:52:36.289196 11461 request.go:302] field selector: v1 - events - involvedObject.namespace - default: need to check if this is versioned correctly. 
W0417 15:52:36.289204 11461 request.go:302] field selector: v1 - events - involvedObject.uid - d4dab099-04ee-11e6-b7f9-0a11c670939b: need to check if this is versioned correctly. 
Name:    fsharp-service-7lrq8 
Image(s):   fsharp/fsharp:latest 
Node:    ip-172-20-0-228.us-west-2.compute.internal/172.20.0.228 
Labels:    app=fsharp-service 
Status:    Running 
Replication Controllers: fsharp-service (1/1 replicas created) 
Containers: 
    fsharp-service: 
    Image:  fsharp/fsharp:latest 
    State:  Waiting 
     Reason:  CrashLoopBackOff 
    Ready:  False 
    Restart Count: 3 
Conditions: 
    Type  Status 
    Ready  False 
Events: 
    FirstSeen    LastSeen   Count From       SubobjectPath   Reason  Message 
    Sun, 17 Apr 2016 15:50:50 -0700 Sun, 17 Apr 2016 15:50:50 -0700 1 {default-scheduler }         Scheduled Successfully assigned fsharp-service-7lrq8 to ip-172-20-0-228.us-west-2.compute.internal 
    Sun, 17 Apr 2016 15:50:51 -0700 Sun, 17 Apr 2016 15:50:51 -0700 1 {kubelet ip-172-20-0-228.us-west-2.compute.internal} spec.containers{fsharp-service} Created  Created container with docker id d44c288ea67b 
    Sun, 17 Apr 2016 15:50:51 -0700 Sun, 17 Apr 2016 15:50:51 -0700 1 {kubelet ip-172-20-0-228.us-west-2.compute.internal} spec.containers{fsharp-service} Started  Started container with docker id d44c288ea67b 
    Sun, 17 Apr 2016 15:50:55 -0700 Sun, 17 Apr 2016 15:50:55 -0700 1 {kubelet ip-172-20-0-228.us-west-2.compute.internal} spec.containers{fsharp-service} Started  Started container with docker id 688a3ed122d2 
    Sun, 17 Apr 2016 15:50:55 -0700 Sun, 17 Apr 2016 15:50:55 -0700 1 {kubelet ip-172-20-0-228.us-west-2.compute.internal} spec.containers{fsharp-service} Created  Created container with docker id 688a3ed122d2 
    Sun, 17 Apr 2016 15:50:58 -0700 Sun, 17 Apr 2016 15:50:58 -0700 1 {kubelet ip-172-20-0-228.us-west-2.compute.internal}     FailedSync Error syncing pod, skipping: failed to "StartContainer" for "fsharp-service" with CrashLoopBackOff: "Back-off 10s restarting failed container=fsharp-service pod=fsharp-service-7lrq8_default(d4dab099-04ee-11e6-b7f9-0a11c670939b)" 

    Sun, 17 Apr 2016 15:51:15 -0700 Sun, 17 Apr 2016 15:51:15 -0700 1 {kubelet ip-172-20-0-228.us-west-2.compute.internal} spec.containers{fsharp-service} Started  Started container with docker id c2e348e1722d 
    Sun, 17 Apr 2016 15:51:15 -0700 Sun, 17 Apr 2016 15:51:15 -0700 1 {kubelet ip-172-20-0-228.us-west-2.compute.internal} spec.containers{fsharp-service} Created  Created container with docker id c2e348e1722d 
    Sun, 17 Apr 2016 15:51:17 -0700 Sun, 17 Apr 2016 15:51:31 -0700 2 {kubelet ip-172-20-0-228.us-west-2.compute.internal}     FailedSync Error syncing pod, skipping: failed to "StartContainer" for "fsharp-service" with CrashLoopBackOff: "Back-off 20s restarting failed container=fsharp-service pod=fsharp-service-7lrq8_default(d4dab099-04ee-11e6-b7f9-0a11c670939b)" 

    Sun, 17 Apr 2016 15:50:50 -0700 Sun, 17 Apr 2016 15:51:44 -0700 4 {kubelet ip-172-20-0-228.us-west-2.compute.internal} spec.containers{fsharp-service} Pulling  pulling image "fsharp/fsharp:latest" 
    Sun, 17 Apr 2016 15:51:45 -0700 Sun, 17 Apr 2016 15:51:45 -0700 1 {kubelet ip-172-20-0-228.us-west-2.compute.internal} spec.containers{fsharp-service} Created  Created container with docker id edaea97fb379 
    Sun, 17 Apr 2016 15:50:51 -0700 Sun, 17 Apr 2016 15:51:45 -0700 4 {kubelet ip-172-20-0-228.us-west-2.compute.internal} spec.containers{fsharp-service} Pulled  Successfully pulled image "fsharp/fsharp:latest" 
    Sun, 17 Apr 2016 15:51:46 -0700 Sun, 17 Apr 2016 15:51:46 -0700 1 {kubelet ip-172-20-0-228.us-west-2.compute.internal} spec.containers{fsharp-service} Started  Started container with docker id edaea97fb379 
    Sun, 17 Apr 2016 15:50:58 -0700 Sun, 17 Apr 2016 15:52:27 -0700 7 {kubelet ip-172-20-0-228.us-west-2.compute.internal} spec.containers{fsharp-service} BackOff  Back-off restarting failed docker container 
    Sun, 17 Apr 2016 15:51:48 -0700 Sun, 17 Apr 2016 15:52:27 -0700 4 {kubelet ip-172-20-0-228.us-west-2.compute.internal}     FailedSync Error syncing pod, skipping: failed to "StartContainer" for "fsharp-service" with CrashLoopBackOff: "Back-off 40s restarting failed container=fsharp-service pod=fsharp-service-7lrq8_default(d4dab099-04ee-11e6-b7f9-0a11c670939b)" 

有什麼不對?

如何找出控制器無法正確啓動的原因?

UPDATE。

我試圖將簡單的「fsharp/fsharp:latest」圖像更改爲另一個圖像,其中將有一個服務監聽端口,這是我想要如何使用容器。

的圖像被稱爲「用戶名/ someservice:mytag」,並有服務偵聽的端口3000

我運行的服務爲:

mono Service.exe 

當我看到我看到的日誌這樣的:

$ kubectl logs -p fsharp-service-wjmpv 
Running on http://127.0.0.1:3000 
Press enter to exit 

因此,容器處於相同的狀態,即使過程中不要退出:

$ kubectl get pods 
NAME     READY  REASON    RESTARTS AGE 
fsharp-service-wjmpv 0/1  CrashLoopBackOff 9   25m 

我也試圖從我的形象和-i標誌運行容器,使容器不會退出,但kubectl似乎並沒有認識到-i標誌:\

有什麼想法?

回答

0

我加入以下行到我的F#服務(Unix的特定代碼),以確保過程不會退出:

let signals = [| new UnixSignal (Signum.SIGINT); 
       new UnixSignal (Signum.SIGTERM); 
       new UnixSignal (Signum.SIGQUIT) 
       |] 

let which = UnixSignal.WaitAny (signals, -1); 

後,我複製控制器運行一般。

3

您正在啓動一個立即退出的容器。 kubelet注意到,重新啓動它,然後再次退出。發生這種情況幾次之後,kubelet會降低它嘗試啓動容器的速率(這是CrashLoopBackOff狀態)。

fsharp documentation表示運行帶有-i標誌的容器,該標誌提供交互式提示。如果你只是做

docker run fsharp/fsharp:latest 

你會注意到容器立即退出並將你轉儲回你的本地shell。這是您嘗試在羣集中調用容器的方式,並且它也會立即退出。

+0

我已更新我的問題。添加了我的嘗試結果與另一個圖像(我運行基於fsharp圖像偵聽端口3000的服務的圖像) – experimenter

3

我會用kubectl logs,試圖找出發生了什麼事,您的容器,就像這樣:

kubectl logs -p fsharp-service-7lrq8 

-p標誌讓你得到日誌之前的啓動是必要的,這種情況下,由於容器正在崩潰。

的更多信息:http://kubernetes.io/docs/user-guide/kubectl/kubectl_logs/

+0

謝謝,但日誌是空的,只是一個F#交互式提示消息 – experimenter

+0

你想實現什麼?從端口來看,你已經添加了你打算運行某種Web服務,但對我來說,沒有這樣的Web服務似乎存在於容器中,因爲你只是執行了香草F#容器。 –

+1

我對F#一無所知,所以請原諒我的無知。根據@RobertBaily,你看起來像所有的圖像都是啓動交互式提示,然後退出,除非以交互模式啓動。你爲什麼要開始一個在Kubernetes內部什麼都不做的容器?如果你真的這樣做,我會建議開始你的無限睡眠的容器。例如。添加類似於你的容器定義的東西:'command:[「bin/bash」,「-c」,「sleep」,「10000d」]' –

相關問題