Docker image not able to stay alive in a Jenkins Kubernetes build pipeline

12/19/2019

We want to deploy using ArgoCD from our Jenkinsfile (which is slightly not how this is intended to be done but close enough), and after done some experiments want to try using the official container with the CLI, so we have added this snippet to our our pipeline kubernetes yaml:

  - name: argocdcli
    image: argoproj/argocli
    command:
    - argo
    args: 
    - version
    tty: true

Unfortunately the usual way to keep these containers alive is to invoke cat in the container, which isn't there, so it fails miserably. Actually the only command in there is the "argo" command which doesn't have a way to sleep infinitely. (We are going to report this upstream so it will be fixed, but while we wait for that....)

My question therefore is, is there a way to indicate to Kubernetes that we know that this pod cannot keep itself up on its own, and therefore not tear it down immediately?

-- Thorbjørn Ravn Andersen
argocd
jenkins
jenkins-pipeline
kubernetes

1 Answer

12/19/2019

Unfortunately it's not possible since as you stated, argo is the only command available on this image.

It can be confirmed here:

####################################################################################################
# argocli
####################################################################################################
FROM scratch as argocli
COPY --from=argo-build /go/src/github.com/argoproj/argo/dist/argo-linux-amd64 /bin/argo
ENTRYPOINT [ "argo" ]

As we can see on this output, running argo is all this container is doing:

$ kubectl run -i --tty --image argoproj/argocli argoproj1 --restart=Never 
argo is the command line interface to Argo

Usage:
  argo [flags]
  argo [command]
...  

You can optionally create you own image based on that and include sleep, so it'll be possible to keep it running as in this example:

apiVersion: v1
kind: Pod
metadata:
  name: busybox
  namespace: default
spec:
  containers:
  - name: busybox
    image: busybox:1.28
    command:
      - sleep
      - "3600"
    imagePullPolicy: IfNotPresent
  restartPolicy: Always
-- mWatney
Source: StackOverflow