Java Parameters on Kubernetes Deployment

226 Views Asked by At

I have a Java/Spring Boot application which is being deployed on K8s Cluster; containerized via Docker. I'm using Google JIB plugin to create the Docker Image.

While running a Spring Boot app as JAR we can pass JDK parameters along as java -jar -Djdk.httpclient.keepalive.timeout=120 <JARName>.

I wanted to know if there is a way to pass the same JDK parameter to a Deployment in Kubernetes. ? Here are current ENV variable on Deployment.yaml file

containers:
        - name: {{ .Chart.Name }}
          securityContext:
            {{- toYaml .Values.securityContext | nindent 12 }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          ports:
            - name: http
              containerPort: 8080
              protocol: TCP
          env:
            - name: SERVER_PORT
              value: "8080"
            - name: SPRING_PROFILES_ACTIVE
              value: {{ .Values.profile.active }}
            - name: TZ
              value: America/New_York

Thanks

1

There are 1 best solutions below

0
mipo256 On

In the K8S pod's spec you can merely define the image being used. This image has already been built and published to the container registry. It is not obvious (or even possible for that matter) how to override the container's entrypoint/cmd that launches the JVM with specifics args.

What I think you should do instead, is just use ENV/ARG in Docker during your CI/CD pipeline. This is exactly what they were designed to solve. This way, you can pass everything you need just during the image build.