I'm trying to exec a command into a running pod. I'm using go K8sclient to achieve this but facing a issue. I also don't know if solution is correct or not. Can anyone please check and provide correct solution?
This is my code.
namespace := getNamespace()
podName := "maxscale-0"
config, err := rest.InClusterConfig()
if err != nil {
log.Fatal(err)
}
clientset, err := kubernetes.NewForConfig(config)
if err != nil {
log.Fatal(err)
}
req := clientset.CoreV1().Pods(namespace).Exec(podName, &corev1.PodExecOptions{
Command: []string{"sh", "-c", "grep -oP '\"name\": \"\\K[^\"]*' /var/lib/maxscale/MariaDB-Monitor_journal.json"},
})
// Set up a stream to capture the output
execStream, err := req.Stream()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
// Print the output
buf := new(bytes.Buffer)
buf.ReadFrom(execStream)
fmt.Println(buf.String())
The error I got is
clientset.CoreV1().Pods(namespace).Exec undefined (type "k8s.io/client-go/kubernetes/typed/core/v1".PodInterface has no field or method Exec)