处于 CrashLoopBackOff 状态的 Kubernetes 复制控制器
Kubernetes replication controller in CrashLoopBackOff state
我执行了以下步骤。
使用以下配置文件创建了复制控制器:
{
"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)"
怎么了?
如何找出控制器无法正常启动的原因?
更新。
我已经尝试将简单的 "fsharp/fsharp:latest" 图像更改为另一个图像,其中将有一个服务侦听端口,这就是我想要使用容器的方式。
图像名为 "username/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 标志:\
有什么想法吗?
您正在启动一个立即退出的容器。 kubelet 注意到,重新启动它,然后再次退出。这种情况发生几次后,kubelet 会减慢它尝试启动容器的速度(这是 CrashLoopBackOff 状态)。
fsharp documentation 向 运行 带有 -i
标志的容器发出交互式提示。如果你只是做
docker run fsharp/fsharp:latest
您会注意到容器立即退出并将您转储到本地 shell。这是您尝试在集群中调用容器的方式,它同样会立即退出。
我会使用 kubectl logs
来尝试找出您的容器发生了什么,就像这样:
kubectl logs -p fsharp-service-7lrq8
-p
标志允许您获取上一次启动的日志,在这种情况下这是必需的,因为容器正在崩溃。
更多信息:http://kubernetes.io/docs/user-guide/kubectl/kubectl_logs/
我已将以下行添加到我的 F# 服务(Unix 特定代码)以确保进程不会退出:
let signals = [| new UnixSignal (Signum.SIGINT);
new UnixSignal (Signum.SIGTERM);
new UnixSignal (Signum.SIGQUIT)
|]
let which = UnixSignal.WaitAny (signals, -1);
在那之后我的复制控制器是 运行 正常。
我执行了以下步骤。
使用以下配置文件创建了复制控制器:
{
"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)"
怎么了?
如何找出控制器无法正常启动的原因?
更新。
我已经尝试将简单的 "fsharp/fsharp:latest" 图像更改为另一个图像,其中将有一个服务侦听端口,这就是我想要使用容器的方式。
图像名为 "username/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 标志:\
有什么想法吗?
您正在启动一个立即退出的容器。 kubelet 注意到,重新启动它,然后再次退出。这种情况发生几次后,kubelet 会减慢它尝试启动容器的速度(这是 CrashLoopBackOff 状态)。
fsharp documentation 向 运行 带有 -i
标志的容器发出交互式提示。如果你只是做
docker run fsharp/fsharp:latest
您会注意到容器立即退出并将您转储到本地 shell。这是您尝试在集群中调用容器的方式,它同样会立即退出。
我会使用 kubectl logs
来尝试找出您的容器发生了什么,就像这样:
kubectl logs -p fsharp-service-7lrq8
-p
标志允许您获取上一次启动的日志,在这种情况下这是必需的,因为容器正在崩溃。
更多信息:http://kubernetes.io/docs/user-guide/kubectl/kubectl_logs/
我已将以下行添加到我的 F# 服务(Unix 特定代码)以确保进程不会退出:
let signals = [| new UnixSignal (Signum.SIGINT);
new UnixSignal (Signum.SIGTERM);
new UnixSignal (Signum.SIGQUIT)
|]
let which = UnixSignal.WaitAny (signals, -1);
在那之后我的复制控制器是 运行 正常。