cgo: exec gcc: exec: "gcc": 在 $PATH 中找不到可执行文件 Egress operator 安装错误

cgo: exec gcc: exec: "gcc": executable file not found in $PATH Error in Egress operator installation

我正在尝试 Egress Operator for restricting the egress calls based on domain. I am using Ubuntu 18 Hyper-V VM and I have all prerequisites:

  1. 用于推送图像的 Azure 存储库
  2. Kubebuilder 用于代码生成
  3. Kustomize 用于构建 Kubernetes 清单
  4. CoreDns(k3s 默认)pod 运行
  5. Golang : go version go1.16.5 linux/amd64

但是 Testing locally make run 给出以下错误:

root@Ubuntu18-Virtual-Machine:~/egress-operator# make run
go: creating new go.mod: module tmp
go get: added sigs.k8s.io/controller-tools v0.2.4
/root/go/bin/controller-gen object:headerFile=./hack/boilerplate.go.txt paths="./..."
Error: go [list -e -json -compiled=true -test=false -export=false -deps=true -find=false -tags ignore_autogenerated -- ./...]: exit status 2: # runtime/cgo
cgo: exec gcc: exec: "gcc": executable file not found in $PATH

同样在 ConfigMap 中编辑 coredns 部署和 coredns Corefile 之后,如 coredns plugin setup I am seeing blow error while executing make deploy 命令中所述:

root@Ubuntu18-Virtual-Machine:~/egress-operator# make deploy IMG=MY_REPO/egress-operator:v0.1
go: creating new go.mod: module tmp
go get: added sigs.k8s.io/controller-tools v0.2.4
/root/go/bin/controller-gen "crd:trivialVersions=true" rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
Error: go [list -e -json -compiled=true -test=false -export=false -deps=true -find=false -tags ignore_autogenerated -- ./...]: exit status 2: # runtime/cgo
cgo: exec gcc: exec: "gcc": executable file not found in $PATH

谁能告诉我如何解决这个问题?

您的环境似乎没有安装 gcc 编译器。请按如下方式尝试:

sudo apt-get install build-essential

sudo apt-get  build-dep  gcc

然后查看是否安装成功:

gcc --version

另请参阅此