我正在构建以下非常简单的go程序
package main
import (
"context"
"flag"
"fmt"
"log"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/util/homedir"
)
const namespace = "default"
func main() {
home := homedir.HomeDir()
defaultKubeConfigPath := fmt.Sprintf("%s/%s", home, ".kube/config")
kubeconfig := flag.String("kubeconfig", defaultKubeConfigPath, "location to kubeconfig file")
config, err := clientcmd.BuildConfigFromFlags("", *kubeconfig)
if err != nil {
panic(err)
}
clientset, err := kubernetes.NewForConfig(config)
if err != nil {
log.Fatal(err)
}
pods, err := clientset.CoreV1().Pods(namespace).List(context.TODO(), metav1.ListOptions{})
if err != nil {
panic(err)
}
for i := range pods.Items {
fmt.Printf("%s\n", pods.Items[i].Name)
}
deployments, err := clientset.AppsV1().Deployments(namespace).List(context.TODO(), metav1.ListOptions{})
if err != nil {
panic(err)
}
for i := range deployments.Items {
fmt.Printf("%s\n", deployments.Items[i].Name)
}
}
使用以下Dockerfile
FROM golang:1.19.2-alpine3.15 as builder
COPY src /src
WORKDIR /src
RUN go build -race -ldflags "-s -w" -a -o client-go
FROM scratch
COPY --from=builder client-go /client-go
ENTRYPOINT [ "./client-go" ]
构建失败如下:
#8 21.92 # runtime/cgo
#8 21.92 cgo: C compiler "gcc" not found: exec: "gcc": executable file not found in $PATH
gcc因为我没有使用任何cgo扩展,所以到底需要哪里?
是否有先验方法来确定何时需要gccfor ?cgo
梦里花落0921
相关分类