0

我正在尝试更多地了解 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

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

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/博文。

4

1 回答 1

0

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

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

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

于 2020-12-03T21:35:22.813 回答