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