Skaffold 同步文件但 pod 不刷新

Sat*_*rik 5 node.js typescript kubernetes skaffold

Kubernetes 新手在这里。

我有一些奇怪的 Skaffold/Kubernetes 行为。我在 Google Cloud 中工作,但我已更改到本地环境进行测试,结果是一样的。所以可能是我怎么做错了。问题是,虽然我看到 Skaffold 同步更改,但这些更改并未反映出来。Pod 中的所有文件都是旧文件。

Skaffold.yaml:

apiVersion: skaffold/v2alpha3
kind: Config
deploy:
  kubectl:
    manifests:
      - ./infra/k8s/*
build:
  # local:
  #   push: false
  googleCloudBuild:
    projectId: ts-maps-286111
  artifacts:
    - image: us.gcr.io/ts-maps-286111/auth
      context: auth
      docker:
        dockerfile: Dockerfile
      sync:
        manual:
          - src: 'src/**/*.ts'
            dest: .
    - image: us.gcr.io/ts-maps-286111/client
      context: client
      docker:
        dockerfile: Dockerfile
      sync:
        manual:
          - src: '**/*.js'
            dest: .
    - image: us.gcr.io/ts-maps-286111/tickets
      context: tickets
      docker:
        dockerfile: Dockerfile
      sync:
        manual:
          - src: 'src/**/*.ts'
            dest: .
    - image: us.gcr.io/ts-maps-286111/orders
      context: orders
      docker:
        dockerfile: Dockerfile
      sync:
        manual:
          - src: 'src/**/*.ts'
            dest: .
    - image: us.gcr.io/ts-maps-286111/expiration
      context: expiration
      docker:
        dockerfile: Dockerfile
      sync:
        manual:
          - src: 'src/**/*.ts'
            dest: .
Run Code Online (Sandbox Code Playgroud)

当其中一个目录中的文件发生更改时,我会看到以下日志:

time="2020-09-05T01:24:06+03:00" level=debug msg="Change detected notify.Write: \"F:\\projects\\lrn_microservices\\complex\\expiration\\src\\index.ts\""
time="2020-09-05T01:24:06+03:00" level=debug msg="Change detected notify.Write: \"F:\\projects\\lrn_microservices\\complex\\expiration\\src\\index.ts\""
time="2020-09-05T01:24:06+03:00" level=debug msg="Change detected notify.Write: \"F:\\projects\\lrn_microservices\\complex\\expiration\\src\\index.ts\""
time="2020-09-05T01:24:06+03:00" level=debug msg="Change detected notify.Write: \"F:\\projects\\lrn_microservices\\complex\\expiration\\src\\index.ts\""
time="2020-09-05T01:24:06+03:00" level=debug msg="Change detected notify.Write: \"F:\\projects\\lrn_microservices\\complex\\expiration\\src\\index.ts\""
time="2020-09-05T01:24:06+03:00" level=debug msg="Change detected notify.Write: \"F:\\projects\\lrn_microservices\\complex\\expiration\\src\\index.ts\""
time="2020-09-05T01:24:07+03:00" level=debug msg="Found dependencies for dockerfile: [{package.json /app true} {. /app true}]"
time="2020-09-05T01:24:07+03:00" level=debug msg="Skipping excluded path: node_modules"
time="2020-09-05T01:24:07+03:00" level=debug msg="Found dependencies for dockerfile: [{package.json /app true} {. /app true}]"
time="2020-09-05T01:24:07+03:00" level=debug msg="Skipping excluded path: .next"
time="2020-09-05T01:24:07+03:00" level=debug msg="Skipping excluded path: node_modules"
time="2020-09-05T01:24:07+03:00" level=debug msg="Found dependencies for dockerfile: [{package.json /app true} {. /app true}]"
time="2020-09-05T01:24:07+03:00" level=debug msg="Skipping excluded path: node_modules"
time="2020-09-05T01:24:07+03:00" level=debug msg="Found dependencies for dockerfile: [{package.json /app true} {. /app true}]"
time="2020-09-05T01:24:07+03:00" level=debug msg="Skipping excluded path: node_modules"
time="2020-09-05T01:24:07+03:00" level=debug msg="Found dependencies for dockerfile: [{package.json /app true} {. /app true}]"
time="2020-09-05T01:24:07+03:00" level=debug msg="Skipping excluded path: node_modules"
time="2020-09-05T01:24:07+03:00" level=info msg="files modified: [expiration\\src\\index.ts]"
Syncing 1 files for us.gcr.io/ts-maps-286111/expiration:2aae7ff-dirty@sha256:2e31caedf3d9b2bcb2ea5693f8e22478a9d6caa21d1a478df5ff8ebcf562573e
time="2020-09-05T01:24:07+03:00" level=info msg="Copying files: map[expiration\\src\\index.ts:[/app/src/index.ts]] to us.gcr.io/ts-maps-286111/expiration:2aae7ff-dirty@sha256:2e31caedf3d9b2bcb2ea5693f8e22478a9d6caa21d1a478df5ff8ebcf562573e"
time="2020-09-05T01:24:07+03:00" level=debug msg="getting client config for kubeContext: ``"
time="2020-09-05T01:24:07+03:00" level=debug msg="Running command: [kubectl --context gke_ts-maps-286111_europe-west3-a_ticketing-dev exec expiration-depl-5cb997d597-p49lv --namespace default -c expiration -i -- tar xmf - -C / --no-same-owner]"
time="2020-09-05T01:24:09+03:00" level=debug msg="Command output: [], stderr: tar: removing leading '/' from member names\n"
Watching for changes...
time="2020-09-05T01:24:11+03:00" level=info msg="Streaming logs from pod: expiration-depl-5cb997d597-p49lv container: expiration"
time="2020-09-05T01:24:11+03:00" level=debug msg="Running command: [kubectl --context gke_ts-maps-286111_europe-west3-a_ticketing-dev logs --since=114s -f expiration-depl-5cb997d597-p49lv -c expiration --namespace default]"
[expiration]
[expiration] > expiration@1.0.0 start /app
[expiration] > ts-node-dev --watch src src/index.ts
[expiration]
[expiration] ts-node-dev ver. 1.0.0-pre.62 (using ts-node ver. 8.10.2, typescript ver. 3.9.7)
[expiration] starting expiration!kdd
[expiration] Connected to NATS!
Run Code Online (Sandbox Code Playgroud)

Pod 内的 NodeJS 服务器重新启动。有时我看到这条线,有时没有,结果总体上是一样的

[expiration] [INFO] 22:23:42 Restarting: src/index.ts has been modified
Run Code Online (Sandbox Code Playgroud)

但是没有进行任何更改。如果我将更改后的文件放在 pod 中,它是旧版本,如果我删除一个 pod,它会再次以旧版本开始。

我的文件夹结构:

+---auth
|   \---src
|       +---models
|       +---routes
|       |   \---__test__
|       +---services
|       \---test
+---client
|   +---.next
|   |   +---cache
|   |   |   \---next-babel-loader
|   |   +---server
|   |   |   \---pages
|   |   |       +---auth
|   |   |       \---next
|   |   |           \---dist
|   |   |               \---pages
|   |   \---static
|   |       +---chunks
|   |       |   \---pages
|   |       |       +---auth
|   |       |       \---next
|   |       |           \---dist
|   |       |               \---pages
|   |       +---development
|   |       \---webpack
|   |           \---pages
|   |               \---auth
|   +---api
|   +---components
|   +---hooks
|   \---pages
|       \---auth
+---common
|   +---build
|   |   +---errors
|   |   +---events
|   |   |   \---types
|   |   \---middlewares
|   \---src
|       +---errors
|       +---events
|       |   \---types
|       \---middlewares
+---config
+---expiration
|   \---src
|       +---events
|       |   +---listeners
|       |   \---publishers
|       +---queue
|       \---__mocks__
+---infra
|   \---k8s
+---orders
|   \---src
|       +---events
|       |   +---listeners
|       |   |   \---__test__
|       |   \---publishers
|       +---models
|       +---routes
|       |   \---__test__
|       +---test
|       \---__mocks__
+---payment
\---tickets
    \---src
        +---events
        |   +---listeners
        |   |   \---__test__
        |   \---publishers
        +---models
        |   \---__test__
        +---routes
        |   \---__test__
        +---test
        \---__mocks__
Run Code Online (Sandbox Code Playgroud)

将不胜感激任何帮助!

Ima*_*ngh 7

对我有用的是使用--pollflag 和ts-node-dev. 我的脚本看起来像这样

"start" : "ts-node-dev --respawn --poll --inspect --exit-child src/index.ts
Run Code Online (Sandbox Code Playgroud)


Ric*_*ico 1

日志中看起来没有重大错误,我的猜测是这些文件实际上被放在另一个目录中。您可以尝试在容器中运行。

\n
find / -name "index.ts"\n
Run Code Online (Sandbox Code Playgroud)\n

看看它是否没有落在其他地方。

\n

另一件需要检查的事情是WORKDIR容器中的价值。检查运行时进入的目录:

\n
kubectl exec -it -c <container-name> <pod-name>\n
Run Code Online (Sandbox Code Playgroud)\n

\xe2\x9c\x8c\xef\xb8\x8f

\n