简体   繁体   English

package jar 在 docker + kubernetes

[英]package jar in docker + kubernetes

I am new to docker, kubernetes.我是 docker、kubernetes 的新手。 I have created a jar file and I need to start the jar file when kube creates the pod.我创建了一个 jar 文件,我需要在 kube 创建 pod 时启动 jar 文件。 I want to pass args from kube pod.yml to call a java class in the jar file packaged in the docker image - 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 -以下是我的 pod 文件 -

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 -在我的 pom.xml 我有以下 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.我不知道如何 go 关于这个。 Do I need to use ENTRYPOINT or CMD or anything else.我是否需要使用 ENTRYPOINT 或 CMD 或其他任何东西。

You need to have an entrypoint in the Dockerfile which starts the applicaion/process like java -jar app-jar-with-dependencies.jar.您需要在 Dockerfile 中有一个入口点,它启动应用程序/过程,如 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.然后在使用 args 的 pod 定义中,kubernetes 会将它们作为运行时 args 传递。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM