gpt4 book ai didi

kubernetes - Skaffold 开发人员因首次部署消息失败而挂起

转载 作者:行者123 更新时间:2023-12-02 19:09:19 27 4
gpt4 key购买 nike

我正在向我的 Kubernetes 集群添加 NextJS 前端。我添加了以下文件:

apiVersion: apps/v1
kind: Deployment
metadata:
name: client-depl
spec:
replicas: 1
selector:
matchLabels:
app: client
template:
metadata:
labels:
app: client
spec:
containers:
- name: client
image: ldco2016/client
---
apiVersion: v1
kind: Service
metadata:
name: client-srv
spec:
selector:
app: client
ports:
- name: client
protocol: TCP
port: 3000
targetPort: 3000

到我的infra/k8s/目录,然后重新配置ingress-srv.yml,如下所示:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress-service
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/use-regex: "true"
spec:
rules:
- host: ticketing.dev
http:
paths:
- path: /api/users/?(.*)
backend:
serviceName: auth-srv
servicePort: 3000
- path: /?(.*)
backend:
serviceName: client-srv
servicePort: 3000

skaffold.yml 文件:

apiVersion: skaffold/v2alpha3
kind: Config
deploy:
kubectl:
manifests:
- ./infra/k8s*
build:
local:
push: false
artifacts:
- image: ldco2016/auth
context: auth
docker:
dockerfile: Dockerfile
sync:
manual:
- src: "src/**/*.ts"
dest: .
- image: ldco2016/client
context: client
docker:
dockerfile: Dockerfile
sync:
manual:
- src: "**/*.js"
dest: .

当我运行skaffold dev时,它卡在此处:

starting deploy...
- deployment.apps/auth-depl created
- service/auth-srv created
- deployment.apps/auth-mongo-depl created
- service/auth-mongo-srv created
- deployment.apps/client-depl created
- service/client-srv created
- ingress.extensions/ingress-service created
Waiting for deployments to stabilize...
- deployment/auth-depl: waiting for rollout to finish: 0 of 1 updated replicas are available...
- deployment/auth-mongo-depl: waiting for rollout to finish: 0 of 1 updated replicas are available...
- deployment/client-depl: waiting for rollout to finish: 0 of 1 updated replicas are available...
- deployment/client-depl is ready. [2/3 deployment(s) still pending]
- deployment/auth-mongo-depl is ready. [1/3 deployment(s) still pending]

有什么想法吗?

我还运行 Docker 桌面和 Kubernetes。由于这是一个微服务应用程序,我认为 Kubernetes 可能需要更多资源。我尝试添加更多资源,但这并没有解决问题。

最佳答案

我怀疑问题出在我的一个 Pod 上,所以我运行: kubectl get pods

NAME                               READY   STATUS                       RESTARTS   AGE
auth-depl-5867ffb6bd-n5s6w 0/1 CreateContainerConfigError 0 2m7s
auth-depl-669fc8fd66-qr8kj 0/1 CreateContainerConfigError 0 6m11s
auth-mongo-depl-585f5f978c-tnc9w 1/1 Running 0 2m7s

所以问题似乎出在我的 auth-depl 上,所以我查看了它的 yaml 文件,我怀疑问题出在我添加的 key 上,所以我评论了像这样:

apiVersion: apps/v1
kind: Deployment
metadata:
name: auth-depl
spec:
replicas: 1
selector:
matchLabels:
app: auth
template:
metadata:
labels:
app: auth
spec:
containers:
- name: auth
image: ldco2016/auth
# env:
# - name: JWT_KEY
# valueFrom:
# secretKeyRef:
# name: jwt-secret
# key: JWT_KEY
---
apiVersion: v1
kind: Service
metadata:
name: auth-srv
spec:
selector:
app: auth
ports:
- name: auth
protocol: TCP
port: 3000
targetPort: 3000

然后我运行 skaffold dev --cleanup=false 并看到:

Listing files to watch...
- ldco2016/auth
Generating tags...
- ldco2016/auth -> ldco2016/auth:latest
Some taggers failed. Rerun with -vdebug for errors.
Checking cache...
- ldco2016/auth: Found Locally
Tags used in deployment:
- ldco2016/auth -> ldco2016/auth:367e6b2171c5c8477a3f3458d23dd73030f35716df45a290aa54baa5f4dcdaa1
Starting deploy...
- deployment.apps/auth-depl configured
- service/auth-srv configured
- deployment.apps/auth-mongo-depl configured
- service/auth-mongo-srv configured
- ingress.extensions/ingress-service configured
Waiting for deployments to stabilize...
- deployment/auth-depl: waiting for rollout to finish: 1 old replicas are pending termination...
- deployment/auth-mongo-depl: waiting for rollout to finish: 1 old replicas are pending termination...
- deployment/auth-depl is ready. [1/2 deployment(s) still pending]
- deployment/auth-mongo-depl is ready.
Deployments stabilized in 3.633465001s
Watching for changes...
[auth-depl-5c59699679-tnzk2 auth]
[auth-depl-5c59699679-tnzk2 auth] > <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="48293d3c20087966786678" rel="noreferrer noopener nofollow">[email protected]</a> start /app
[auth-depl-5c59699679-tnzk2 auth] > nodemon ./src/index.ts
[auth-depl-5c59699679-tnzk2 auth]
[auth-depl-5c59699679-tnzk2 auth] [nodemon] 2.0.5
[auth-depl-5c59699679-tnzk2 auth] [nodemon] to restart at any time, enter `rs`
[auth-depl-5c59699679-tnzk2 auth] [nodemon] watching path(s): *.*
[auth-depl-5c59699679-tnzk2 auth] [nodemon] watching extensions: ts,json
[auth-depl-5c59699679-tnzk2 auth] [nodemon] starting `ts-node ./src/index.ts`
[auth-depl-5c59699679-tnzk2 auth] (node:40) UnhandledPromiseRejectionWarning: Error: JWT must be defined

这是一个很大的线索,因为当我去 kubectl get Secrets 时,我发现我的 JWT 不再在 Kubernetes Secret 中,我相信这是因为我的机器最近无意中重新启动了,这意味着我忘记点击上述内容,直到稍后,它才在当天晚上重新启动,从而使用 Kubernetes 重新启动了我的 Docker 桌面的本地副本。

因此,我再次运行 kubectl create Secret... 命令,然后运行 ​​kubectl get Secrets 并再次看到我的 key 。

我在这些环境变量中添加了 key 或该 key 的值在我的 auth-depl.yml 文件中,然后运行 ​​skaffold dev --cleanup=false 再次:

Listing files to watch...
- ldco2016/auth
Generating tags...
- ldco2016/auth -> ldco2016/auth:latest
Some taggers failed. Rerun with -vdebug for errors.
Checking cache...
- ldco2016/auth: Found Locally
Tags used in deployment:
- ldco2016/auth -> ldco2016/auth:367e6b2171c5c8477a3f3458d23dd73030f35716df45a290aa54baa5f4dcdaa1
Starting deploy...
- deployment.apps/auth-depl configured
- service/auth-srv configured
- deployment.apps/auth-mongo-depl configured
- service/auth-mongo-srv configured
- ingress.extensions/ingress-service configured
Waiting for deployments to stabilize...
- deployment/auth-depl: waiting for rollout to finish: 1 old replicas are pending termination...
- deployment/auth-mongo-depl: waiting for rollout to finish: 1 old replicas are pending termination...
- deployment/auth-depl is ready. [1/2 deployment(s) still pending]
- deployment/auth-mongo-depl is ready.
Deployments stabilized in 3.612848017s
Watching for changes...
[auth-depl-5c59699679-tnzk2 auth] Error from server (BadRequest): container "auth" in pod "auth-depl-5c59699679-tnzk2" is terminated
[auth-depl-7d9bf44d9f-n9rcq auth]
[auth-depl-7d9bf44d9f-n9rcq auth] > <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bfdecacbd7ff8e918f918f" rel="noreferrer noopener nofollow">[email protected]</a> start /app
[auth-depl-7d9bf44d9f-n9rcq auth] > nodemon ./src/index.ts
[auth-depl-7d9bf44d9f-n9rcq auth]
[auth-depl-7d9bf44d9f-n9rcq auth] [nodemon] 2.0.5
[auth-depl-7d9bf44d9f-n9rcq auth] [nodemon] to restart at any time, enter `rs`
[auth-depl-7d9bf44d9f-n9rcq auth] [nodemon] watching path(s): *.*
WARN[0004] exit status 1
[auth-depl-7d9bf44d9f-n9rcq auth] [nodemon] watching extensions: ts,json
[auth-depl-7d9bf44d9f-n9rcq auth] [nodemon] starting `ts-node ./src/index.ts`
[auth-depl-7d9bf44d9f-n9rcq auth] Connected to MongoDB
[auth-depl-7d9bf44d9f-n9rcq auth] Listening on port 3000!!!!!

恢复业务。

关于kubernetes - Skaffold 开发人员因首次部署消息失败而挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64559024/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com