使用 Kubernetes client-go 以编程方式创建 pod 会出现以下错误:
an empty namespace may not be set during creation
从这个例子开始: https ://github.com/feiskyer/go-examples/blob/master/kubernetes/pod-create/pod.go
#go
handler := clientset.CoreV1().Pods("").PodInterface
pod := apiv1.Pod{
TypeMeta: metav1.TypeMeta{
Kind: "Pod",
APIVersion: "v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: "my-pod",
Namespace: "my-namespace",
},
Spec: apiv1.PodSpec{
Containers: []apiv1.Container{
{
Name: "my-container",
Image: "my-container",
},
},
},
}
result, err := handler.Create(pod)
期望:创建 Pod。
实际:创建失败并出现 k8s 错误:创建期间可能未设置空命名空间