C
C#2w ago
ayjay

✅ Restart k8s pod from .net app

Has someone ever restarted/deleted a pod from a .net app? I have a very specific scenario where I must do from the app.
15 Replies
mtreit
mtreit2w ago
Just shell out to kubectl using System.Diagnostics.Process?
Jayy
Jayy2w ago
This isn't how you want to do this. You have to bake the binary into the image then also pull its auth tokens and build the request manually @ayjay this is not normally a thing you need to do from an application pod but you'll need to mount a service account with the correct rbac on it then use the generate oapi client in dotnet
Jayy
Jayy2w ago
GitHub
GitHub - kubernetes-client/csharp: Officially supported dotnet Kube...
Officially supported dotnet Kubernetes Client library - GitHub - kubernetes-client/csharp: Officially supported dotnet Kubernetes Client library
mtreit
mtreit2w ago
Maybe I misunderstood the question. I read it as: I want to write some program (say, a console app) and run that app locally (or somewhere) to restart a pod. I envisioned something like what k9s does (which I believe just runs kubectl commands...)
Jayy
Jayy2w ago
Ah maybe that's the case, even in that case tho it's easier to use the client for your language. K9s uses normal client-go Using kubectl for the watches would be very inefficient
mtreit
mtreit2w ago
I hardly do anything with kubernets so I'm sure you know more than I do about it 🙂
Jayy
Jayy2w ago
Not that shelling out to kubectl won't work or isn't a thing that people do. But it's usually more of a pain than it's worth when the official clients can auth with nicer ergonomics
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
Jayy
Jayy2w ago
It'll restart the container, the pod won't go away. So if you need a reschedule you need the api call
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
Jayy
Jayy2w ago
It says both restarted and deleted in the op :hmm: coin flip here imo
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
ayjay
ayjayOP2w ago
Both help in my case, i will try with liveness probe
Unknown User
Unknown User2w ago
Message Not Public
Sign In & Join Server To View
MODiX
MODiX2w ago
If you have no further questions, please use /close to mark the forum thread as answered

Did you find this page helpful?