func (k *KubeClient) Exec(command, pod, container, ns string) (string, string, error) {
	var stderr, stdout bytes.Buffer
	req := k.CoreV1().
		RESTClient().
		Post().
		Resource("pods").
		Name(pod).
		Namespace(ns).
		SubResource("exec")
	scheme := runtime.NewScheme()
	if err := corev1.AddToScheme(scheme); err != nil {
		return "", "", errors.Errorf("error adding to scheme: %v", err)
	}
	paramCodec := runtime.NewParameterCodec(scheme)
	req.VersionedParams(&corev1.PodExecOptions{
		Command:   strings.Fields(command),
		Container: container,
		Stdout:    true,
		Stderr:    true,
	}, paramCodec)
	exec, err := remotecommand.NewSPDYExecutor(cfg, "POST", req.URL())
	if err != nil {
		return "", "", fmt.Errorf("error while creating Executor: %v", err)
	}
	err = exec.Stream(remotecommand.StreamOptions{
		Stdout: &stdout,
		Stderr: &stderr,
	})
	if err != nil {
		return "", "", errors.Errorf("error in Stream: %v", err)
	}
	return stdout.String(), stderr.String(), nil
}
Exec execute the given command in given ns/pod/container and return the output
package k8s
import (
	"bytes"
	"fmt"
	"strings"
	"github.com/pkg/errors"
	corev1 "k8s.io/api/core/v1"
	"k8s.io/apimachinery/pkg/runtime"
	"k8s.io/client-go/tools/remotecommand"
)