我正在努力学习更多关于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: 1apiVersion: v1
kind: Service
metadata:
name: mepipe-videos-service
spec:
type: ClusterIP
ports:
- name: http
port: 80
targetPort: 8000
selector:
app: mepipe-videosapiVersion: 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 -我可以看到所有的pods都是新的,刚刚重建的。如果我从其中一个抓取日志-我会得到正确的结果,正如预期的那样。我预计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/博客文章。
发布于 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应该警告说这个图像没有在任何地方引用,所以你可能已经修复了这个问题。
https://stackoverflow.com/questions/65133446
复制相似问题