简体   繁体   English

skaffold 不会在 minikube 中重新加载 golang 代码

[英]skaffold does not reload golang code in minikube

I've been experimenting with skaffold with a local minikube installation.我一直在尝试使用本地 minikube 安装的 skaffold。 It's a nice to be able to develop your project on something that is as close as possible to production.能够在尽可能接近生产的东西上开发您的项目真是太好了。

If I use the getting-started example provided on skaffold github repo, everything works just fine, my IDE (intellij idea) stops on the breakpoints and when I modify my code, the changes are reflected instantly.如果我使用 skaffold github repo 上提供的入门示例,一切正常,我的 IDE(intellij idea)在断点处停止,当我修改代码时,更改会立即反映。

Now on my personal project which is a bit more complicated than a simple main.go file, things don't work as expected.现在在我的个人项目中,它比简单的 main.go 文件要复杂一些,但事情并没有按预期工作。 The IDE stops on the breakpoint but hot code reload are not happening even though I see in the console that skaffold detected the changes made on that particular file but unfortunately the changes are not reflected/applied. IDE 在断点处停止,但是即使我在控制台中看到 skaffold 检测到对该特定文件所做的更改,但没有反映/应用更改,也没有发生热代码重新加载。

A docker file is used to build an image, the docker file is the following一个docker文件用于构建镜像,docker文件如下

FROM golang:1.14 AS builder

WORKDIR /app

COPY go.mod go.sum ./
RUN go mod download
COPY . .

RUN CGO_ENABLED=0 go build -o /app.o ./cmd/shortener/shortener.go

FROM alpine:3.12
COPY --from=builder /app.o ./
COPY --from=builder /app ./
EXPOSE 3000
ENV GOTRACEBACK=all
CMD ["./app.o"]

On kubernetes side, I'm creating a deployment and a service as follows:在 kubernetes 方面,我正在创建一个部署和服务,如下所示:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: url-shortener-deployment
spec:
  selector:
    matchLabels:
      app: url-shortener
  template:
    metadata:
      labels:
        app: url-shortener
    spec:
      containers:
        - name: url-shortener
          image: url_shortener
          ports:
            - containerPort: 3000
---
apiVersion: v1
kind: Service
metadata:
  name: url-shortener-service
spec:
  selector:
    app: url-shortener
  ports:
    - port: 3000
      nodePort: 30000
  type: NodePort

As for skaffold, here's the skaffold.yaml file:至于 skaffold,这里是 skaffold.yaml 文件:

apiVersion: skaffold/v2beta5
kind: Config
metadata:
  name: url-shortener
build:
  artifacts:
    - image: url_shortener
      context: shortener
      docker:
        dockerfile: build/docker/Dockerfile.dev
        noCache: false
deploy:
  kubectl:
    manifests:
      - stack/mongo/mongo.yaml
      - shortener/deployments/kubernetes/shortener.yaml

I've enabled verbose logging and I notice this in the output whenever I save (CTRL+S) a source code file.我启用了详细日志记录,每当我保存 (CTRL+S) 源代码文件时,我都会在 output 中注意到这一点。

time="2020-07-05T22:51:08+02:00" level=debug msg="Found dependencies for dockerfile: [{go.mod /app true} {go.sum /app true} {. /app true}]"
time="2020-07-05T22:51:08+02:00" level=info msg="files modified: [shortener/internal/handler/rest/rest.go]"

I'm assuming that this means that the change has been detected.我假设这意味着已检测到更改。

breakpoints works correctly in the IDE but code swap in kubernetes don't seem to be happening断点在 IDE 中正常工作,但 kubernetes 中的代码交换似乎没有发生

The debug functionality deliberately disables Skaffold's file-watching , which rebuilds and redeploys containers on file change.调试功能故意禁用 Skaffold 的文件监视,它会在文件更改时重建和重新部署容器。 The redeploy causes existing containers to be terminated, which tears down any ongoing debug sessions.重新部署会导致现有容器被终止,从而中断任何正在进行的调试会话。 It's really disorienting and aggravating to have your carefully-constructed debug session be torn down because you accidentally saved a change to a comment!由于您不小心保存了对评论的更改,因此将您精心构建的调试 session 拆除,真是令人迷失方向和恶化!

But we're looking at how to better support this more iterative debugging within Cloud Code.但我们正在研究如何在 Cloud Code 中更好地支持这种更具迭代性的调试

If you're using Skaffold directly, we recently added the ability to re-enable file-watching via skaffold debug --auto-build --auto-deploy (present in v1.12).如果您直接使用 Skaffold,我们最近添加了通过skaffold debug --auto-build --auto-deploy (在 v1.12 中提供)重新启用文件监视的功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM