How to get logs from kubernetes using golang?

前端 未结 4 1788
情话喂你
情话喂你 2020-12-17 00:59

I\'m looking for the solution of how to get logs from a pod in Kubernetes cluster using golang. I\'ve looked at \"https://github.com/kubernetes/client-go\" and \"https://god

4条回答
  •  萌比男神i
    2020-12-17 01:32

    @Emixam23

    I believe you will find this snippet useful.

    How to get the dynamic name of a pod?

    import  metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    
        labelSelector := metav1.LabelSelector{MatchLabels: map[string]string{: }}
        listOptions := metav1.ListOptions{
            LabelSelector: labels.Set(labelSelector.MatchLabels).String(),
        }
        pod, err := k8sClient.CoreV1().Pods().List(listOptions)
        podName := pod.Items[0].ObjectMeta.Name
    

提交回复
热议问题