1

I'm beginning with kubernetes and docker and facing an issue.

Deployed a springboot app on minikube after converting it to docker image (using minikube's docker)... the app is online and receiving request so well as you can see in the below screenshots, but doesn't reply as expected.

For example, when i deploy the app normally (on my computer like usually) everything works well i can go on all html pages etc, but once deployed inside minikube it doesn't reply correctly. (all working part is the receiving of favicon of spring)

YAMLs used to deploy the app:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: esse-deployment-1
  labels:
    app: esse
spec:
  replicas: 1
  selector:
    matchLabels:
      app: esse-1
  template:
    metadata:
      labels:
        app: esse-1
    spec:
      containers:
      - image: mysql:5.7
        name: esse-datasource
        ports:
        - containerPort: 3306
        env: 
          - name: MYSQL_ROOT_PASSWORD
            value: esse_password 
      - image: esse_application
        name: esse-app-1
        imagePullPolicy: Never
        ports:
        - containerPort: 8080
      volumes:
        - name: esse-1-mysql-persistent-storage
          persistentVolumeClaim:
            claimName: mysql-persistent-storage-claim
---

apiVersion: v1
kind: Service
metadata:
  name: esse-service-1
spec:
  selector:
    app: esse-1
  ports:
    - protocol: TCP
      port: 8080
  type: NodePort

----

kind: PersistentVolume
apiVersion: v1
metadata:
  name: mysql-persistent-storage
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/home/docker/data"

---

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: mysql-persistent-storage-claim
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 200Mi

Docker file to contruct image:

FROM openjdk:8
ADD ESSE_Application.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "app.jar"]

App log Result in brower

Mssm
  • 717
  • 11
  • 29
  • It might be a copy-n-paste error but it seems that a YAML doc separator `---` is missing between the Service and PersistentVolume definitions? – apisim Jul 30 '19 at 02:52
  • Yeah sorry forgot to add --- once i copied the yaml code (i have those yaml definitions in separated files) – Mssm Jul 30 '19 at 09:35
  • Do you have a better result if you do `curl http://pod_ip:8080` ? This way we should be able to tell if the problem comes from your app or your service configuration. – Marc ABOUCHACRA Jul 30 '19 at 10:09
  • No i get the same result, running curl http://172.17.0.4:8080/ inside minikube (after running minikube ssh) where 172.17.0.4 is the pod_ip, and it gives: {"timestamp":1564484568041,"status":404,"error":"Not Found","message":"No message available","path":"/"} ... but notice that when the application is running hosted in my computer, it works just fine :/ – Mssm Jul 30 '19 at 11:05
  • Ok, so the problem does not come from your K8S service, but probably from your application configuration in K8S. Have you checked the spring-boot log after starting the app in K8S ? – Marc ABOUCHACRA Jul 30 '19 at 12:23
  • Yes the log is displayed in the first picture (joined with the topic) and as you can see there's no execeptions, the app launched and request are received so well by the application. – Mssm Jul 30 '19 at 12:31
  • And what about running your app in Docker ? I mean, just Docker, no K8S ? Does it work ? – Marc ABOUCHACRA Jul 30 '19 at 12:49
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/197217/discussion-between-marc-abouchacra-and-mouley). – Marc ABOUCHACRA Jul 30 '19 at 12:51
  • Did you resolve the problem? – Mark Aug 01 '19 at 07:52
  • I found the problem yeah but i'm still trying to solve it to post the answer. The problem was nothing related to minikube. I was working with Eclipse IDE, and have some jsps in src/main/webapp/WEB-INF/jsps and once compiled to a single .jar file, those jsps are not included, this is why i can't access the pages when running the jar file. I'm sure Ecipse IDE does some processing to add them itself so that why it was working when starting it from the EDI – Mssm Aug 01 '19 at 09:13

2 Answers2

0

I can see you have .yml files to define the deployment and the service, but I can see no "Ingress". A .yml file of kind: Route is needed in order to tell kubernetes that there should be an external url pointing to your service; a minimal Ingress resource example:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: test-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - http:
      paths:
      - path: /testpath
        backend:
          serviceName: test
          servicePort: 80

**Please don't take this code literally, I'm just trying to draft some example code here and may not match perfectly your naming/data :)

Javier Aviles
  • 7,952
  • 2
  • 22
  • 28
  • Is `kind: Route` a Kubernetes or OpenShift-specific resource? – apisim Jul 30 '19 at 02:39
  • Sorry, I understood minishift!! my bad, you need an Ingress then? https://kubernetes.io/docs/concepts/services-networking/ingress/ – Javier Aviles Jul 30 '19 at 08:03
  • I don't think ingress is necessary to avoid this issue, i've already exposed other apps (when practicing on kubernetes basics) and never used ingress addons, only exposing by adding a TypeNode type service... problem might be somewhere else – Mssm Jul 30 '19 at 09:36
0

Finally solved the problem.

Everything was working fine because i was launching the app from Eclipse IDE, and when packaging a .jar file, the jps files included inside the /webapp/WEB-INF/jsps folder were not included inside the .jar file and even including them throw the <resources> tag in the pom.xml file didn't solve the problem since the jar packaging isn't suitable for jsp file.

I fixed the problem by adding <packaging>war</packaging> inside the pom.xml file to change the packaging method as the .jsp files feel confortable within a .war file.

Thanks to @Marc for the help.

Mssm
  • 717
  • 11
  • 29