-
Notifications
You must be signed in to change notification settings - Fork 317
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Best practice to handle a kubernetes job that needs to connect to the mesh #722
Comments
HI @harscoet, thanks for posting this question. |
Linkerd also provides the linkerd-await wrapper that will call the shutdown hook for you when the job terminates, as a convenience. C'mon over and give it a try! |
Thanks for the reply @kschoche! |
Hi @harscoet! |
Related to Kyle's response, are you using metrics merging? |
Adding an additional option to this @harscoet, this code repository: https://github.com/nrmitchi/k8s-controller-sidecars contains a controller that you can deploy to your cluster that automatically kills sidecar pods when the main job container exits. You will need to build this from the go code and bundle it into a Docker container as there is no release (if you just want to test you can use: nicholasjackson/k8s-controller-sidecars:latest). But it works really well, in addition to the injection annotations for Consul you simply add an additional annotation I think you are using the transparent proxy features so many of the below annotations may not be required, my cluster is not yet using that. Example annotations "consul.hashicorp.com/connect-inject": "true"
"consul.hashicorp.com/connect-service": "cron-job"
"consul.hashicorp.com/connect-service-port": 9090
"consul.hashicorp.com/connect-service-upstreams": "minecraft-bot:3000"
"nrmitchi.com/sidecars": "consul-sidecar,envoy-sidecar" Kind regards, Nic |
@harscoet Could you share your example yaml file with your job injected? We're looking into how to solve this now. |
This is now documented here: https://developer.hashicorp.com/consul/docs/k8s/connect#kubernetes-jobs. Will go ahead and close this issue. Thanks for your feedback. If you're on Consul K8s 1.2.x, you'll need to wait until the next patch release to get the graceful shutdown endpoint. |
Actually to be able to create a kubernetes job that needs to call some services from the mesh, I need to register the job itself as a service in consul. Is it the only solution? Do you have some best practices to handle this really common use case?
Related to this issue #692 I now need to create a kubernetes service, as I don't have any port, what manifest I need to create?
Is it enough?
I have a secondary issue related to this kubernetes behavior kubernetes/kubernetes#25908
When my jobs ends, consul sidecars are still running so the job is not considered terminated. Do you have a good solution to handle this? Linkerd for example added a special endpoint to be able to shutdown linkerd/linkerd2-proxy#811
The workaround actually for me is to use
shareProcessNamespace: true
run my main container as root and runpkill consul
at the end of my scriptThe text was updated successfully, but these errors were encountered: