在 Golang 示例中执行 `kubectl get po -o yaml` 时出现错误。

huangapple go评论79阅读模式
英文:

Error while exec kubectl get po -o yaml in golang example

问题

如何在Golang中获取kubectl get po -o yaml的输出?

你可以使用以下代码来运行这段代码Go客户端示例,其中预期的输出是:

./app
集群中有3个Pod
集群中有3个Pod
集群中有3个Pod

但是当我运行它时,我得到了以下错误:

go build -o app .
    ./app
panic: exec plugin: invalid apiVersion "client.authentication.k8s.io/v1alpha1"

goroutine 1 [running]:
main.main()
	/Users/padmanabanpr/Documents/client-go/examples/out-of-cluster-client-configuration/main.go:61 +0x5b6
英文:

How to get Kubectl get po -o yaml in golang

it to run this code
Go client example

where the expected output is

./app
There are 3 pods in the cluster
There are 3 pods in the cluster
There are 3 pods in the cluster

but when i run it i got

 go build -o app .
    ./app
panic: exec plugin: invalid apiVersion "client.authentication.k8s.io/v1alpha1"

goroutine 1 [running]:
main.main()
	/Users/padmanabanpr/Documents/client-go/examples/out-of-cluster-client-configuration/main.go:61 +0x5b6

答案1

得分: 1

这可能是因为您的k8s客户端/服务器版本高于1.24+。请参考此链接以获取进一步的解释:https://github.com/aws/aws-cli/issues/6920

英文:

This might be due to your k8s client/server version being higher than 1.24+
https://github.com/aws/aws-cli/issues/6920 Please refer this for further clarification

答案2

得分: 0

以下步骤修复了该问题:

  • 安装 Kubectl 客户端 1.23.0-00(1.24.x 存在一些问题)
$ cd client-go/examples/out-of-cluster-client-configuration
$ go mod init example.com/m
$ go mod tidy
$ go build -o app .
$ ./app
英文:

the following steps fixed the issue

  • install Kubectl client 1.23.0-00(there is some problem with 1.24.x)
$ cd client-go/examples/out-of-cluster-client-configuration
$ go mod init example.com/m
$ go mod tidy
$ go build -o app .
$ ./app

huangapple
  • 本文由 发表于 2022年5月31日 17:24:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/72445271.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定