Sure, here’s the translation: 在 Docker 和 Kubernetes 中的 JAR 包。

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

package jar in docker + kubernetes

问题

以下是已经翻译好的内容:

我对Docker和Kubernetes还不熟悉。我已经创建了一个JAR文件,我需要在Kubernetes创建Pod时启动这个JAR文件。我希望能够从Kubernetes的pod.yml文件中传递参数,以调用打包在Docker镜像中的JAR文件中的Java类。

Dockerfile

FROM openjdk:8
ARG JAR_FILE=target/app.jar

cd /usr/local/runme

WORKDIR /usr/local/runme/

COPY ${JAR_FILE} app-jar-with-dependencies.jar

以下是我的Pod文件 -

apiVersion: v1
kind: Pod
metadata:
name: app
labels:
zone: dev
version: v1
spec:
containers:
- name: app-ctr
image: "从上述Dockerfile创建的Docker镜像"
ports:
- containerPort: 8080
env:
- name: NO_OF_CONSUMERS
value: "1"

args: ["-n", "$(NO_OF_CONSUMERS)"]

在我的pom.xml中,我有以下mainClass -

maven-assembly-plugin



com.app.KafkaConsumer



jar-with-dependencies




make-assembly package

single


我不确定如何进行下一步。我需要使用ENTRYPOINT、CMD还是其他什么东西。

英文:

I am new to docker, kubernetes. I have created a jar file and I need to start the jar
file when kube creates the pod. I want to pass args from kube pod.yml to call a java class
in the jar file packaged in the docker image -

Dockerfile
==========
FROM openjdk:8
ARG JAR_FILE=target/app.jar
# cd /usr/local/runme
WORKDIR /usr/local/runme/

COPY ${JAR_FILE} app-jar-with-dependencies.jar

The following is my pod file -

apiVersion: v1
kind: Pod
metadata:
  name: app
  labels:
zone: dev
version: v1
spec:
  containers:
    - name: app-ctr
      image: "docker-image-created-from-above-dockerfile"
      ports:
      - containerPort: 8080
    env:
    - name: NO_OF_CONSUMERS
      value: "1"  

args: [ "-n", "$(NO_OF_CONSUMERS)"]

In my pom.xml I have the following mainClass -

<plugin>
			<artifactId>maven-assembly-plugin</artifactId>
			<configuration>
				<archive>
					<manifest>
						<mainClass>com.app.KafkaConsumer</mainClass>
					</manifest>
				</archive>
				<descriptorRefs>
					<descriptorRef>jar-with-dependencies</descriptorRef>
				</descriptorRefs>
			</configuration>
			<executions>
				<execution>
					<id>make-assembly</id> <!-- this is used for inheritance merges -->
					<phase>package</phase> <!-- bind to the packaging phase -->
					<goals>
						<goal>single</goal>
					</goals>
				</execution>
			</executions>
		</plugin>

I am not sure how to go about this. Do I need to use ENTRYPOINT or CMD or anything else.

答案1

得分: 1

你需要在 Dockerfile 中设置一个入口点,启动应用程序/进程,例如:java -jar app-jar-with-dependencies.jar。然后在 Pod 定义中,当使用 args 时,Kubernetes 将把它们作为运行时参数传递。

英文:

You need to have an entrypoint in the Dockerfile which starts the applicaion/process like java -jar app-jar-with-dependencies.jar. Then in the pod definition when args is used kubernetes will pass them as a run time args.

huangapple
  • 本文由 发表于 2020年4月9日 08:38:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/61112194.html
匿名

发表评论

匿名网友

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

确定