java spingboot microservice deployment on aks throws UnsupportedClassVersionError

6/1/2020

While trying to deploy java springboot microservice on aks continuously gives me UnsupportedClassVersionError. I am using "kubectl apply -f file.yaml" command to apply the deployment. Even after compiling to correct compiler version now, it still complains the same. Not sure where I am missing.

First Attempt <br/> - compiled with oracle openjdk 11 <br/> - checked compiled class version using javap -verbose MyApplication | findstr "major" <br/>  console output - major version: 55 <br/> - Deployment to aks failed

Second Attempt <br/> - compiled with oracle jdk 1.8 <br/> - checked compiled class version using ' javap -verbose MyApplication | findstr "major" ' <br/>  console output - major version: 52 <br/> - Deployment to aks fails

Common to both deployment <br/> - Used command "kubectl apply -f myapp.yaml" to deploy on aks cluster <br/> - Receiving same error, which is, <br/><br/>

> Exception in thread "main" java.lang.UnsupportedClassVersionError:
> MyApplication has been compiled by a more recent version of the Java
> Runtime (class file version 55.0), this version of the Java Runtime
> only recognizes class file versions up to 52.0
>         at java.lang.ClassLoader.defineClass1(Native Method)
>         at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
>         at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
>         at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
>         at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
>         at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
>         at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
>         at java.security.AccessController.doPrivileged(Native Method)
>         at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
>         at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
>         at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:92)
>         at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
>         at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:46)
>         at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
>         at org.springframework.boot.loader.Launcher.launch(Launcher.java:51)
>         at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:52)

<br/> Request kind help

Regards

-- sdsquare
docker
java
kubernetes

1 Answer

6/2/2020

Default pull policy is set to IfNotPresent which tells Kubelet to skip pulling an image if it already exists on a node where pod is being scheduled. If you want to force image to always be pulled you could do following:

  • set the imagePullPolicy of the container to Always.
  • omit the imagePullPolicy and use :latest as the tag for the image to use.
  • omit the imagePullPolicy and the tag for the image to use.
  • enable the AlwaysPullImages admission controller.

Note that you should avoid using :latest tag, see Best Practices for Configuration for more information.

-- Crou
Source: StackOverflow