Kubernetes找不到一个jar文件。

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

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中的CMDRUN层以使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=&quot;-Dspring.profiles.active=prod -Dspring.application.name=words&quot;
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

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.

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:

确定