成功运行命令后,Kubernetes 部署不会自动终止



我有一个 Kubernetes 集群,我在其中创建了一个部署来运行一个 pod。不幸的是,在运行它之后,pod 不想自我终止,而是进入重新启动/CrashLoopBackOff 循环的连续状态。

该命令(在入口点上(在首次部署时可以正常运行,我希望它只运行一次。

我正在使用 Python K8s API 以编程方式部署配置入口点的 docker 映像。这是我的部署 YAML:

apiVersion: apps/v1
kind: Deployment
metadata:
name: kio
namespace: kmlflow
labels:
app: kio
name: kio
spec:
replicas: 1
selector:
matchLabels:
app: kio
name: kio
template:
metadata:
labels:
app: kio
name: kio
spec:
containers:
- name: kio-ingester
image: MY_IMAGE
command: ["/opt/bin/kio"]
args: ["some", "args"]
imagePullPolicy: Always
restart: Never
backofflimit: 0

感谢您的任何帮助

kubectl pod 的输出是:

Name:               ingest-160-779874b676-8pgv5
Namespace:          kmlflow
Priority:           0
PriorityClassName:  <none>
Node:               02-w540-02.glebe.kinetica.com/172.30.255.205
Start Time:         Thu, 11 Oct 2018 13:31:20 -0400
Labels:             app=kio
name=kio
pod-template-hash=3354306232
Annotations:        <none>
Status:             Running
IP:                 10.244.0.228
Controlled By:      ReplicaSet/ingest-160-779874b676
Containers:
kio-ingester:
Container ID:  docker://b67a682d04e69c2dc5c1be7e02bf2e4cf7a12a7557dfbe642dfb531ca4b03f07
Image:         kinetica/kinetica-intel
Image ID:      docker-pullable://docker.io/kinetica/kinetica-intel@sha256:eefbb6595eb71822300ef97d5cbcdac7ec58f2041f8190d3a2ba9cffd6a0d87c
Port:          <none>
Host Port:     <none>
Command:
/opt/gpudb/bin/kio
Args:
--source
kinetica://172.30.50.161:9191::dataset_iris
--destination
kinetica://172.30.50.161:9191::iris5000
State:          Waiting
Reason:       CrashLoopBackOff
Last State:     Terminated
Reason:       Completed
Exit Code:    0
Started:      Thu, 11 Oct 2018 13:33:27 -0400
Finished:     Thu, 11 Oct 2018 13:33:32 -0400
Ready:          False
Restart Count:  4
Environment:    <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-69wkn (ro)
Conditions:
Type              Status
Initialized       True 
Ready             False 
ContainersReady   False 
PodScheduled      True 
Volumes:
default-token-69wkn:
Type:        Secret (a volume populated by a Secret)
SecretName:  default-token-69wkn
Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
node.kubernetes.io/unreachable:NoExecute for 300s
Events:
Type     Reason     Age                  From                                    Message
----     ------     ----                 ----                                    -------
Normal   Scheduled  2m39s                default-scheduler                       Successfully assigned kmlflow/ingest-160-779874b676-8pgv5 to 02-w540-02.glebe.kinetica.com
Normal   Created    89s (x4 over 2m28s)  kubelet, 02-w540-02.glebe.kinetica.com  Created container
Normal   Started    89s (x4 over 2m28s)  kubelet, 02-w540-02.glebe.kinetica.com  Started container
Warning  BackOff    44s (x7 over 2m15s)  kubelet, 02-w540-02.glebe.kinetica.com  Back-off restarting failed container
Normal   Pulling    33s (x5 over 2m28s)  kubelet, 02-w540-02.glebe.kinetica.com  pulling image "kinetica/kinetica-intel"
Normal   Pulled     33s (x5 over 2m28s)  kubelet, 02-w540-02.glebe.kinetica.com  Successfully pulled image "kinetica/kinetica-intel"

Kubectl logs <crashing-pod>没有输出,因为使用注入的参数成功运行命令 KIO 不会将任何内容打印到标准输出。

如果你想运行一次任务并在成功完成后完成,你应该考虑使用 Kubernetes Jobs 或 CronJobs

像这样:

apiVersion: batch/v1
kind: Job
metadata:
name: kio
namespace: kmlflow
labels:
app: kio
name: kio
spec:
template:
metadata:
labels:
app: kio
name: kio
spec:
containers:
- name: kio-ingester
image: MY_IMAGE
command: ["/opt/bin/kio"]
args: ["some", "args"]
imagePullPolicy: Always
restart: Never
backoffLimit: 4

要在拥有 Kubernetes 1.12 或更高版本的情况下自动删除作业,您可以使用ttlSecondsAfterFinished。不幸的是,如果您使用的是 Kuberbetes 1.11 或更早版本,则必须手动删除它们,或者您可以设置 CronJob 来执行此操作。

相关内容

  • 没有找到相关文章

最新更新