title: example of exec in k8s's pod by using go client
body: <p>I want to use k8s go client to exec command in a pod. However I cannot find any example about this. So I read <code>kubectl exec</code> source code, and write code as below. And <code>err = exec.Stream(sopt)</code> always get an error without any message. Can anyone tell me how to debug this problem, or give me a correct example.</p>
  <pre class="lang-golang prettyprint-override"><code>config := &amp;restclient.Config{
      Host:     &quot;http://192.168.8.175:8080&quot;,
      Insecure: true,
  }
  
  config.ContentConfig.GroupVersion = &amp;api.Unversioned
  config.ContentConfig.NegotiatedSerializer = api.Codecs
  
  restClient, err := restclient.RESTClientFor(config)
  if err != nil {
      panic(err.Error())
  }
  
  req := restClient.Post().Resource(&quot;pods&quot;).Name(&quot;wordpress-mysql-213049546-29s7d&quot;).Namespace(&quot;default&quot;).SubResource(&quot;exec&quot;).Param(&quot;container&quot;, &quot;mysql&quot;)
  req.VersionedParams(&amp;api.PodExecOptions{
      Container: &quot;mysql&quot;,
      Command:   []string{&quot;ls&quot;},
      Stdin:     true,
      Stdout:    true,
  }, api.ParameterCodec)
  
  exec, err := remotecommand.NewExecutor(config, &quot;POST&quot;, req.URL())
  if err != nil {
      panic(err.Error())
  }
  sopt := remotecommand.StreamOptions{
      SupportedProtocols: remotecommandserver.SupportedStreamingProtocols,
      Stdin:              os.Stdin,
      Stdout:             os.Stdout,
      Stderr:             os.Stderr,
      Tty:                false,
  }
  
  err = exec.Stream(sopt)
  if err != nil {
      panic(err.Error())
  }
  </code></pre>