Kubernetes找不到一个jar文件。

huangapple go评论106阅读模式
英文:

Kubernetes doesn't find a jar file

问题

以下是您提供的内容的翻译:

我正在使用这个Dockerfile配置

  1. FROM openjdk:17-alpine
  2. ARG APP_HOME=/app
  3. WORKDIR $APP_HOME
  4. COPY ./target/ws-exec.jar ws.jar
  5. ENV JAVA_OPTS="-Dspring.profiles.active=prod -Dspring.application.name=words"
  6. ENTRYPOINT java $JAVA_OPTS -jar ./ws.jar $JAVA_ARGS

在部署到minikube之后,我只看到以下日志:
Error: Unable to access jarfile /ws.jar

我尝试运行docker run -it <image>,使用我的镜像名称,它成功启动了docker。运行docker exec -it <container>显示jar文件存在于正确的文件夹中。我尝试添加Dockerfile中的CMDRUN层以使jar可执行,但没有帮助。
我的错误在哪里,或者我理解错了什么?

更新:这是我的deployment.yaml

  1. apiVersion: apps/v1
  2. kind: Deployment
  3. metadata:
  4. labels:
  5. app: revise-words-ws
  6. name: revise-words-ws
  7. namespace: default
  8. spec:
  9. replicas: 1
  10. minReadySeconds: 45
  11. selector:
  12. matchLabels:
  13. app: revise-words-ws
  14. strategy:
  15. rollingUpdate:
  16. maxSurge: 25%
  17. maxUnavailable: 25%
  18. type: RollingUpdate
  19. template:
  20. metadata:
  21. labels:
  22. app: revise-words-ws
  23. spec:
  24. containers:
  25. - image: maxrybalkin91/revise-words-ws:1.0
  26. imagePullPolicy: IfNotPresent
  27. name: revise-words-ws
  28. env:
  29. - name: VAULT_TOKEN
  30. valueFrom:
  31. secretKeyRef:
  32. name: words
  33. key: vault_token
  34. - name: VAULT_HOST
  35. valueFrom:
  36. secretKeyRef:
  37. name: words
  38. key: vault_host
  39. - name: VAULT_PORT
  40. valueFrom:
  41. secretKeyRef:
  42. name: words
  43. key: vault_port
  44. ports:
  45. - name: liveness-port
  46. containerPort: 8089
  47. resources:
  48. requests:
  49. cpu: 100m
  50. memory: 256Mi
  51. limits:
  52. cpu: 300m
  53. memory: 512Mi
  54. readinessProbe:
  55. httpGet:
  56. path: /
  57. port: liveness-port
  58. failureThreshold: 5
  59. periodSeconds: 10
  60. initialDelaySeconds: 60
  61. livenessProbe:
  62. httpGet:
  63. path: /
  64. port: liveness-port
  65. failureThreshold: 5
  66. periodSeconds: 10
  67. initialDelaySeconds: 60
  68. terminationGracePeriodSeconds: 30
  69. restartPolicy: Always

希望这对您有所帮助。如果您需要进一步的帮助,请随时提出。

英文:

I'm using this Dockerfile configuration

  1. FROM openjdk:17-alpine
  2. ARG APP_HOME=/app
  3. WORKDIR $APP_HOME
  4. COPY ./target/ws-exec.jar ws.jar
  5. ENV JAVA_OPTS=&quot;-Dspring.profiles.active=prod -Dspring.application.name=words&quot;
  6. ENTRYPOINT java $JAVA_OPTS -jar ./ws.jar $JAVA_ARGS

After deploying it to minikube, I see the only log:
Error: Unable to access jarfile /ws.jar.

I've tried to run docker run -it &lt;image&gt; with my image's name, and it successfuly started with docker. Running docker exec -it &lt;container&gt; shew me that the jar is present in the right folder. I tried to make the jar executable adding a CMD or RUN layer into my Dockerfile, but nothing helped.
Where is my mistake, or what I don't understand?

UPD here is my deployment.yaml

  1. apiVersion: apps/v1
  2. kind: Deployment
  3. metadata:
  4. labels:
  5. app: revise-words-ws
  6. name: revise-words-ws
  7. namespace: default
  8. spec:
  9. replicas: 1
  10. minReadySeconds: 45
  11. selector:
  12. matchLabels:
  13. app: revise-words-ws
  14. strategy:
  15. rollingUpdate:
  16. maxSurge: 25%
  17. maxUnavailable: 25%
  18. type: RollingUpdate
  19. template:
  20. metadata:
  21. labels:
  22. app: revise-words-ws
  23. spec:
  24. containers:
  25. - image: maxrybalkin91/revise-words-ws:1.0
  26. imagePullPolicy: IfNotPresent
  27. name: revise-words-ws
  28. env:
  29. - name: VAULT_TOKEN
  30. valueFrom:
  31. secretKeyRef:
  32. name: words
  33. key: vault_token
  34. - name: VAULT_HOST
  35. valueFrom:
  36. secretKeyRef:
  37. name: words
  38. key: vault_host
  39. - name: VAULT_PORT
  40. valueFrom:
  41. secretKeyRef:
  42. name: words
  43. key: vault_port
  44. ports:
  45. - name: liveness-port
  46. containerPort: 8089
  47. resources:
  48. requests:
  49. cpu: 100m
  50. memory: 256Mi
  51. limits:
  52. cpu: 300m
  53. memory: 512Mi
  54. readinessProbe:
  55. httpGet:
  56. path: /
  57. port: liveness-port
  58. failureThreshold: 5
  59. periodSeconds: 10
  60. initialDelaySeconds: 60
  61. livenessProbe:
  62. httpGet:
  63. path: /
  64. port: liveness-port
  65. failureThreshold: 5
  66. periodSeconds: 10
  67. initialDelaySeconds: 60
  68. terminationGracePeriodSeconds: 30
  69. restartPolicy: Always

答案1

得分: 4

作为ENTRYPOINT,您指定Java运行./ws.jar,假设它会从工作目录/app中解析。
在运行时,您会收到错误消息,指出/ws.jar不可访问,这似乎是一个绝对路径。

当使用/bin/bash运行容器时,请查看您的jar文件位于何处以及它处于哪种模式。然后决定谁是正确的,谁是错误的:您的Docker文件还是您的错误消息。修复错误的那个。

英文:

As ENTRYPOINT you specify Java to run ./ws.jar, assuming it would resolve from within work directory /app.
At runtime you get the error message that /ws.jar is not accessible, which looks like an absolute path.

When running your container with /bin/bash, please check out where your jar file exists and which mode it has. Then decide who is right and who is broken: Your docker file or your error message. Fix the broken one.

答案2

得分: 1

如果,如您所说,jar文件位于正确的位置(我假设是/app),那么在执行时是否考虑使用绝对路径呢?

  1. ENTRYPOINT java $JAVA_OPTS -jar $APP_HOME/ws.jar $JAVA_ARGS
英文:

If, as you say the jar file is in the right location (and I assume that is /app), how about using the absolute path for execution?

  1. ENTRYPOINT java $JAVA_OPTS -jar $APP_HOME/ws.jar $JAVA_ARGS

答案3

得分: 0

如下所示,docker run maxrybalkin91/revise-words-ws:1.0 启动了应用程序,报告缺少配置数据的问题 - 但没有找到缺失的jar文件。

由于在Minikube中出现完全不同的错误,有可能您正在运行一些过时的镜像吗?

尝试更改 imagePullPolilcy=Always 看看您会得到什么。

https://kubernetes.io/docs/concepts/containers/images/

英文:

As it seems a docker run maxrybalkin91/revise-words-ws:1.0 brings up the application which complains about missing configuration data - but nowhere a jar file that is not found.

Since in minikube you see a completely different error, is it possible you are running some outdated image?

Try changing imagePullPolilcy=Always and see what you get.

https://kubernetes.io/docs/concepts/containers/images/

huangapple
  • 本文由 发表于 2023年5月22日 03:37:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/76301618.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定