使用 Kubernetes Go Client - 叢集內部

package main

import (
  "fmt"

  "k8s.io/client-go/1.5/kubernetes"
  "k8s.io/client-go/1.5/pkg/api/v1"
  "k8s.io/client-go/1.5/rest"
)

func main()  {
    config, err = rest.InClusterConfig()
    if err != nil {
      return nil, err
    }

    c, err := kubernetes.NewForConfig(config)
    if err != nil {
      return nil, err
    }

    // Get Pod by name
    pod, err := c.Pods(v1.NamespaceDefault).Get("my-pod")
    if err != nil {
        fmt.Println(err)
        return
    }
  
    // Print its creation time
    fmt.Println(pod.GetCreationTimestamp())
}