【问题标题】:Why is skaffold failing when rebuilding containers in skaffold dev?为什么在 skaffold dev 中重建容器时 skaffold 失败?
【发布时间】:2020-12-03 20:13:48
【问题描述】:

我正在尝试了解有关 Kubernetes 和相关工具的更多信息。这次我试图学习如何使用 skaffold 设置本地开发环境。但是,我在skaffold dev 期间遇到了一些错误,这些错误仅在重建时发生,而不是在初始构建时发生。我需要一些关于在哪里查看和/或如何解决该问题的提示。

我将k3s 用于本地集群。

这是我的 Kubernetes 文件:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mepipe-videos-deployment
spec:
  replicas: 3
  selector:
    matchLabels:
      app: mepipe-videos
  template:
    metadata:
      labels:
        app: mepipe-videos
    spec:
      containers:
        - name: mepipe
          image: registry.local:5000/mepipe-videos:v1
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 8000
          livenessProbe:
            httpGet:
              path: /health
              port: 8000
              scheme: HTTP
            initialDelaySeconds: 5
            periodSeconds: 15
            timeoutSeconds: 5
          readinessProbe:
            httpGet:
              path: /readiness
              port: 8000
              scheme: HTTP
            initialDelaySeconds: 5
            timeoutSeconds: 1
apiVersion: v1
kind: Service
metadata:
  name: mepipe-videos-service
spec:
  type: ClusterIP
  ports:
    - name: http
      port: 80
      targetPort: 8000
  selector:
    app: mepipe-videos
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: mepipe-ingress
  annotations:
    kubernetes.io/ingress.class: "traefik"
spec:
  rules:
    - http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: mepipe-videos-service
                port:
                  number: 80

这是我的skaffold.yaml

apiVersion: skaffold/v2beta9
kind: Config
metadata:
  name: mepipe
build:
  artifacts:
  - image: registry.local:5000/mepipe-videos
    sync:
      infer:
        - 'cmd/**/*.go'
        - 'pkg/**/*.go'
        - 'go.mod'
        - 'go.sum'

deploy:
  kubectl:
    manifests:
    - deployments/dev/mepipe-deployment.yaml
    - deployments/dev/mepipe-service.yaml
    - deployments/dev/traefik-ingress.yaml

当我第一次运行skaffold dev 时,结果是这样的。

如您所见 - 它似乎运行正常(health check changed 是正确的日志)。当 Kubernetes 到达 /health 端点时,它会记录一条消息(没有准备就绪的日志)。我还可以从我的本地计算机上同时访问/health/readiness 和其他端点。

但是,如果我更改代码库的任何部分(例如更改为 health check really changed),我会得到这个。

这将永远挂起。如果我运行kubectl get pods - 我可以看到所有的 pod 都是新的、新重建的。如果我从其中一个中获取日志 - 我将得到正确的结果,正如预期的那样。我希望skaffold 重建图像并仍然跟踪结果。没有。

任何想法为什么?我会在哪里查找发生了什么样的错误?

编辑:这是我用来测试的示例存储库。 https://github.com/galkowskit/k8s-skaffold-example

在新设置的 k3s 集群上运行 skaffold dev 时,这是我在输出中得到的。

Starting deploy...
 - deployment.apps/mepipe-videos-deployment created
 - service/mepipe-videos-service created
 - ingress.networking.k8s.io/mepipe-ingress created
Waiting for deployments to stabilize...
 - deployment/mepipe-videos-deployment: FailedMount: MountVolume.SetUp failed for volume "default-token-r7bv7" : failed to sync secret cache: timed out waiting for the condition
    - pod/mepipe-videos-deployment-86c74fb58b-qkg6n: FailedMount: MountVolume.SetUp failed for volume "default-token-r7bv7" : failed to sync secret cache: timed out waiting for the condition
    - pod/mepipe-videos-deployment-86c74fb58b-k98gt: FailedMount: MountVolume.SetUp failed for volume "default-token-r7bv7" : failed to sync secret cache: timed out waiting for the condition
 - deployment/mepipe-videos-deployment: FailedMount: MountVolume.SetUp failed for volume "default-token-r7bv7" : failed to sync secret cache: timed out waiting for the condition
    - pod/mepipe-videos-deployment-86c74fb58b-qkg6n: FailedMount: MountVolume.SetUp failed for volume "default-token-r7bv7" : failed to sync secret cache: timed out waiting for the condition
    - pod/mepipe-videos-deployment-86c74fb58b-k98gt: FailedMount: MountVolume.SetUp failed for volume "default-token-r7bv7" : failed to sync secret cache: timed out waiting for the condition
 - deployment/mepipe-videos-deployment is ready.
Deployments stabilized in 16.200469338s
Press Ctrl+C to exit
Watching for changes...

看起来秘密有一些错误。我对如何解决这个问题感到有点迷茫。我的设置基于此 https://devopsspiral.com/articles/k8s/k3d-skaffold/ 博文。

【问题讨论】:

    标签: kubernetes skaffold


    【解决方案1】:

    有趣!容器日志不可用表明容器创建失败。我认为您随后可以使用 kubectl get pods,因为部署随后会尝试重新创建 pod 并成功;因为初始部署失败,Skaffold 可能没有在寻找日志。我不确定您如何从 k3d 获取日志,但那里可能有更多详细信息。你也可以试试kubectl describe deployment/mepipe-video-deployment

    可以分享这个项目吗?有一个示例来改进此诊断输出对我们很有用。

    我在这里看到的一个问题是您在 deployment.yaml 中对 image: registry.local:5000/mepipe-videos:v1 的图像引用将不起作用:它需要与您的 skaffold.yaml 中的图像相匹配(registry.local:5000/mepipe-videos - 请注意缺少 @987654327 @ 标签)。但 Skaffold 应该警告说,该图像在任何地方都没有被引用,所以也许你已经修复了这个问题。

    【讨论】:

    • 啊,我还没有解决这个问题。版本不匹配是因为我手动执行了 skaffold 正在执行的操作(以确保 Kubernetes 部分正常工作)。我会看看这是否会改变任何东西(它可能会)。如果不是,我可以分享这个项目,当然!
    • 我删除了:v1 广告,结果是一样的。我将准备一个可重现的 repo 并在原始问题中添加一个链接。
    • 我已将存储库链接添加到我的原始问题中。 github.com/galkowskit/k8s-skaffold-example 在新的 k3d 集群上进行设置时,我遇到了一些错误,因此机密或卷可能存在一些问题。
    猜你喜欢
    • 2022-12-17
    • 2021-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-23
    • 1970-01-01
    • 2021-07-16
    • 1970-01-01
    相关资源
    最近更新 更多