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

时间:2018-10-11 15:12:59

标签: 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的成功运行不会将任何内容打印到标准输出。

1 个答案:

答案 0 :(得分:4)

如果您想一次运行任务并在成功完成后完成,则应考虑使用Kubernetes JobsCronJobs

类似这样的东西:

<div class="menu-trigger" tabindex="1">
    <div class="menu-btn">
        Click Me
    </div>
    <div class="menu-content hide">

        <!-- example content  -->
        <button>Clicking this now doesn't close the menu!</button>
        <p>Clicking this doesn't</p>

    </div>
</div>

<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>

如果您具有Kubernetes 1.12或更高版本,要自动删除作业,可以使用ttlSecondsAfterFinished。不幸的是,如果您使用的是Kuberbetes 1.11或更早版本,则必须手动删除它们,或者可以设置CronJob来完成。