首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么在skaffold dev中重建容器时skaffold会失败?

为什么在skaffold dev中重建容器时skaffold会失败?
EN

Stack Overflow用户
提问于 2020-12-04 04:13:49
回答 1查看 427关注 0票数 0

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

我正在对本地群集使用k3s

以下是我的Kubernetes文件:

代码语言:javascript
复制
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
代码语言:javascript
复制
apiVersion: v1
kind: Service
metadata:
  name: mepipe-videos-service
spec:
  type: ClusterIP
  ports:
    - name: http
      port: 80
      targetPort: 8000
  selector:
    app: mepipe-videos
代码语言:javascript
复制
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

代码语言:javascript
复制
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 -我可以看到所有的pods都是新的,刚刚重建的。如果我从其中一个抓取日志-我会得到正确的结果,正如预期的那样。我预计skaffold会重建图像,并仍然跟踪结果。事实并非如此。

你知道为什么吗?我应该在哪里查找发生了什么样的错误?

编辑:这是我用来测试的一个样本库。https://github.com/galkowskit/k8s-skaffold-example

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

代码语言:javascript
复制
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/博客文章。

EN

回答 1

Stack Overflow用户

发布于 2020-12-04 05:35:23

有意思的!容器日志不可用表示容器创建失败。我认为您可以随后yse Skaffold,因为部署随后会尝试重新创建kubectl get pods并成功;因为初始部署失败,Skaffold可能不会查找日志。我不确定您是如何从k3d获取日志的,但可能会有更多细节。您也可以尝试使用kubectl describe deployment/mepipe-video-deployment

有没有可能分享这个项目?对于我们来说,有一个例子来改进这个诊断输出是很有用的。

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65133446

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档