简体   繁体   English

用于调用 Kubernetes 命令的 PowerShell 脚本

[英]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" ).我想创建一个 .ps1 脚本,该脚本将打开一个带有多个选项卡的 Windows 终端窗口,并在每个选项卡中执行一个要执行的命令( 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.所以我基本上想自动化我打开 Windows 终端的日常过程,使用'kubectl get pods -n 'your_namespace'命令获取所需的 pod 名称,然后复制 pod 名称并打开另一个 Windows 终端选项卡并执行kubectl 日志 - f 'name_of_pod'在那里。 And I've got around 10 pods whose logs I need to monitor.我有大约 10 个豆荚,我需要监控它们的日志。 And if Windows Terminal crash ( it happens ) I need to start again all.如果 Windows 终端崩溃(发生),我需要重新开始。

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.. "到目前为止,我已经设法只打开一个新的 Windows 终端选项卡并通过 .ps1 脚本重命名该选项卡,但我无法传递 kubectl 命令 - 启动时出现错误“[error 2147942593 (0x800700c1)..”

Does anyone have any ides how to do this?有谁知道如何做到这一点?

All best, D.万事如意,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.我认为解决方案是始终将完整路径传递给您要运行的 Windows PowerShell 的确切实例,以控制调用哪个版本以及在什么用户上下文下调用。

For example to run your kubectl command example, try this:例如,要运行您的 kubectl 命令示例,请尝试以下操作:

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此 S/O 答案的类似解决方案https://stackoverflow.com/a/70548103/490787

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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