0

I am trying to create two containers within a pod with one container being an init container. The job of the init container is to download a jar and make it available for the app container. I am able to create everything and the logs look good but when i check, i do not see the jar in my app container. Below is my deployment yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: web-service-test
  labels:
    app: web-service-test
spec:
  replicas: 1
  selector:
    matchLabels:
      app: web-service-test
  template:
    metadata:
      labels:
        app: web-service-test
    spec:
      volumes:
      - name: shared-data
        emptyDir: {}
      containers:
      - name: web-service-test
        image: some image
        ports:
        - containerPort: 8081
        volumeMounts:
        - name: shared-data
          mountPath: /tmp/jar
      initContainers:
      - name: init-container
        image: busybox
        volumeMounts:
        - name: shared-data
          mountPath: /jdbc-jar
        command:
        - wget
        - "https://repo1.maven.org/maven2/com/oracle/ojdbc/ojdbc8/19.3.0.0/ojdbc8-19.3.0.0.jar"
daze-hash
  • 31
  • 7
  • Can you include in your question the commands you're using to check for the presence of the downloaded file in your `web-service-test` container? – larsks Dec 28 '20 at 22:17

2 Answers2

1

You need to save jar in the /jdbc-jar folder

try updating your yaml to following

command: ["/bin/sh"]
args: ["-c", "wget -O /pod-data/ojdbc8-19.3.0.0.jar https://repo1.maven.org/maven2/com/oracle/ojdbc/ojdbc8/19.3.0.0/ojdbc8-19.3.0.0.jar"] 
Abhijit Gaikwad
  • 3,072
  • 28
  • 37
0

Add following block of code to your init container section:

command: ["/bin/sh","-c"]
args: ["wget -O /jdbc-jar/ojdbc8-19.3.0.0.jar https://repo1.maven.org/maven2/com/oracle/ojdbc/ojdbc8/19.3.0.0/ojdbc8-19.3.0.0.jar"]

The command ["/bin/sh", "-c"] says "run a shell, and execute the following instructions". The args are then passed as commands to the shell. In shell scripting a semicolon separates commands. In the wget command I have added the -O flag to download the jar from the specified url and save it as /jdbc-jar/ojdbc8-19.3.0.0.jar . To check if jar is persistent in container. Simply execute command:

$ kubectl exec -it web-service-test -- /bin/bash

Then go to folder /jdbc-jar ( $ cd jdbc-jar ) and list files in it ($ ls -al). You should see your jar there.

See examples: commands-in-containers, initcontainers-running.

Malgorzata
  • 6,409
  • 1
  • 10
  • 27