简体   繁体   中英

package jar in docker + kubernetes

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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