linkerd2: Pod controlled by a Job does not exit after after main container completes
Bug Report
What is the issue?
Pods that are controlled by Jobs are not terminating when the main container exits
How can it be reproduced?
Create a job with linkerd sidecar container
Logs, error output, etc
main container logs are as usual, sidecar container logs are as usual
linkerd check
output
Status check results are [ok]
Environment
- Kubernetes Version: 1.11.4
- Cluster Environment: AWS (kops)
- Host OS: Container Linux by CoreOS 1911.3.0 (Rhyolite)
- Linkerd version: edge-18.11.2 (client and server)
Possible solution
I think that when a container within a pod controlled by a Job completes, the sidecar should exit as well.
Additional context
The sidecar was created using linkerd inject
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 27 (7 by maintainers)
I updated the comment above.
Can confirm the original solution I posted is still working fine after about three months.
We also have some some crons running on Argo Workflows with linkerd sidecars.
shareProcessNamespace
doesn’t seem to be an available option in argo workflow specifications. We were able to get Argo to kill the sidecars only after setting the right annotations on the job template:The key part is the
skip-outbound-ports
… I set this up a while ago so I don’t remember the precise reasoning. It was some sort of deadlock where the argo sidecar container couldn’t kill the linkerd sidecar container because argo was trying to communicate over 443, which was proxied by linkerd, so linkerd refused to die because it still had open connections over 443, etc. Fun stuff!I believe I found a solution to this that doesn’t require waiting for a new k8s feature or significantly altering the main job process.
Pods have a
shareProcessNamespace
setting. This lets containers in a pod see and kill the processes running in other containers.The solution: Assume you can identify the process id for the main workload in your job/cronjob. Then you can add your own sidecar container that checks to see if your job process is running, sleeps, and repeats until the job process exits. Once it exits, you kill the linkerd2-proxy process, which makes that container exit, and successfully ends the job/cronjob.
Here’s an example which assumes your job process is called
java
. I assume it would work for any other process, you just have to be able to return the process id by runningpgrep <name-of-my-process>
.For context, we are running k8s version 1.15.7.
provide the annotation and set it to disabled on the job’s pod spec
@wmorgan @laukaichung I didn’t find an existing one, so I created an issue about the missing documentation.
I’ll update once I try 😉
On Mon, Mar 9, 2020, 5:59 PM Alex Klibisz notifications@github.com wrote: