简体   繁体   中英

PowerShell script for calling Kubernetes commands

I would like to create a .ps1 script that would open an Windows Terminal window with multiple tabs and in each tab a command to be executed ( kubectl logs -f "name_of_pod" ).

So I would basically want to automate my day to day process of opening Windows Terminal, getting a desired pod name with 'kubectl get pods -n 'your_namespace' command and then copy the pod name and open another Windows Terminal tab and execute kubectl logs -f 'name_of_pod' there. And I've got around 10 pods whose logs I need to monitor. And if Windows Terminal crash ( it happens ) I need to start again all.

So far I've managed to only open a new Windows Terminal tab and rename the tab via .ps1 script, but I can't pass the kubectl command - I am getting error "[error 2147942593 (0x800700c1) when launching.. "

Does anyone have any ides how to do this?

All best, D.

I encountered this problem recently. I think the solution is to always pass the full path to the exact instance of Windows PowerShell you want to run to control which version is called and under what user context.

For example to run your kubectl command example, try this:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe `
  -Command "& {(`$kubectl get pods -n 'my_pod_name')}"

Similar solution on this S/O answer https://stackoverflow.com/a/70548103/490787

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM