title: How can I get pod external IP from Go code at runtime
body: <p>Pretty simple question, how can I get the Pod where my current go code is running?</p>
  
  <p>I need it because for some reason, I need to ping directly the Pod's code instead of using my regular endpoint which would be the load balancer.</p>
  
  <p>My current config:</p>
  
  <pre><code>apiVersion: v1
  kind: Service
  metadata:
    name: web-socket-service-api
  spec:
    ports:
      # Port that accepts gRPC and JSON/HTTP2 requests over HTTP.
      - port: 8080
        targetPort: 8080
        protocol: TCP
        name: grpc
      # Port that accepts gRPC and JSON/HTTP2 requests over HTTP.
      - port: 8081
        targetPort: 8081
        protocol: TCP
        name: rest
      # Port that accepts WebSockets.
      - port: 8082
        targetPort: 8082
        protocol: TCP
        name: websocket
    selector:
      app: web-socket-service-api
    type: LoadBalancer
  ---
  apiVersion: extensions/v1beta1
  kind: Deployment
  metadata:
    name: web-socket-service-api
  spec:
    replicas: 3
    template:
      metadata:
        labels:
          app: web-socket-service-api
      spec:
        containers:
          - name: web-socket-service-api
            image: gcr.io/[PROJECT]/web-socket-service-api:latest
            ports:
              - containerPort: 8080
              - containerPort: 8081
              - containerPort: 8082
  </code></pre>
  
  <p>I tried</p>
  
  <pre><code>/*
      metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
      "k8s.io/client-go/kubernetes"
      "k8s.io/client-go/rest"
  */
  
  func GetContainerIP() string {
  
      // creates the in-cluster config
      config, err := rest.InClusterConfig()
      if err != nil {
          panic(err.Error())
      }
      // creates the clientset
      clientset, err := kubernetes.NewForConfig(config)
      if err != nil {
          panic(err.Error())
      }
  
      log.Println("checking pods")
      pods, err := clientset.CoreV1().Pods("default").List(metav1.ListOptions{})
      if err != nil {
          panic(err.Error())
      }
      b, _ := json.Marshal(pods)
      log.Println(string(b))
  
      for _, pod := range pods.Items {
          log.Println(pod.Name, pod.Status)
          pod, err := clientset.CoreV1().Pods("default").Get(pod.Name, metav1.GetOptions{})
          if err != nil {
              panic(err.Error())
          }
          log.Println(pod.Status)
      }
      log.Println("checked pods")
  
      return ""
  }
  </code></pre>
  
  <p>But I sadly got</p>
  
  <blockquote>
    <p>panic: pods is forbidden: User "system:serviceaccount:default:default" cannot list resource "pods" in API group "" in the namespace "default"</p>
  </blockquote>
  
  <p>And I couldn't find a way to fix it or any tutorial about it..</p>