英文:
Kubernetes doesn't find a jar file
问题
以下是您提供的内容的翻译:
我正在使用这个Dockerfile
配置
FROM openjdk:17-alpine
ARG APP_HOME=/app
WORKDIR $APP_HOME
COPY ./target/ws-exec.jar ws.jar
ENV JAVA_OPTS="-Dspring.profiles.active=prod -Dspring.application.name=words"
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
中的CMD
或RUN
层以使jar
可执行,但没有帮助。
我的错误在哪里,或者我理解错了什么?
更新:这是我的deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: revise-words-ws
name: revise-words-ws
namespace: default
spec:
replicas: 1
minReadySeconds: 45
selector:
matchLabels:
app: revise-words-ws
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
labels:
app: revise-words-ws
spec:
containers:
- image: maxrybalkin91/revise-words-ws:1.0
imagePullPolicy: IfNotPresent
name: revise-words-ws
env:
- name: VAULT_TOKEN
valueFrom:
secretKeyRef:
name: words
key: vault_token
- name: VAULT_HOST
valueFrom:
secretKeyRef:
name: words
key: vault_host
- name: VAULT_PORT
valueFrom:
secretKeyRef:
name: words
key: vault_port
ports:
- name: liveness-port
containerPort: 8089
resources:
requests:
cpu: 100m
memory: 256Mi
limits:
cpu: 300m
memory: 512Mi
readinessProbe:
httpGet:
path: /
port: liveness-port
failureThreshold: 5
periodSeconds: 10
initialDelaySeconds: 60
livenessProbe:
httpGet:
path: /
port: liveness-port
failureThreshold: 5
periodSeconds: 10
initialDelaySeconds: 60
terminationGracePeriodSeconds: 30
restartPolicy: Always
希望这对您有所帮助。如果您需要进一步的帮助,请随时提出。
英文:
I'm using this Dockerfile
configuration
FROM openjdk:17-alpine
ARG APP_HOME=/app
WORKDIR $APP_HOME
COPY ./target/ws-exec.jar ws.jar
ENV JAVA_OPTS="-Dspring.profiles.active=prod -Dspring.application.name=words"
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 <image>
with my image's name, and it successfuly started with docker. Running docker exec -it <container>
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
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: revise-words-ws
name: revise-words-ws
namespace: default
spec:
replicas: 1
minReadySeconds: 45
selector:
matchLabels:
app: revise-words-ws
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
labels:
app: revise-words-ws
spec:
containers:
- image: maxrybalkin91/revise-words-ws:1.0
imagePullPolicy: IfNotPresent
name: revise-words-ws
env:
- name: VAULT_TOKEN
valueFrom:
secretKeyRef:
name: words
key: vault_token
- name: VAULT_HOST
valueFrom:
secretKeyRef:
name: words
key: vault_host
- name: VAULT_PORT
valueFrom:
secretKeyRef:
name: words
key: vault_port
ports:
- name: liveness-port
containerPort: 8089
resources:
requests:
cpu: 100m
memory: 256Mi
limits:
cpu: 300m
memory: 512Mi
readinessProbe:
httpGet:
path: /
port: liveness-port
failureThreshold: 5
periodSeconds: 10
initialDelaySeconds: 60
livenessProbe:
httpGet:
path: /
port: liveness-port
failureThreshold: 5
periodSeconds: 10
initialDelaySeconds: 60
terminationGracePeriodSeconds: 30
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),那么在执行时是否考虑使用绝对路径呢?
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?
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论