After Springboot application updated, image could not be pulled

5/16/2018

I am using two virtual machines, installed with centos 7. Host is win10 professional version.

I followed the link to make spring boot application container managed by kubernetes. The link is using minikube, but I am using two nodes as kubernetes minimum installation. One node is master(172.16.100.81), one node is worker (172.16.100.96). With hello application, I follow the step, it works. The brief of my command is as follows:

docker build -t $USER/hello:0.0.1 .
kubectl run hello --image $USER/hello:0.0.1 --port 8080
kubectl expose deployment hello --type=NodePort

so far everything is nice. I could even make it scale to replica=3.

But now I modify the spring boot application, I just add a couple of characters as follows:

package com.springdeveloper.k8s.hello;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;


@SpringBootApplication
public class HelloApplication {

        public static void main(String[] args) {
                SpringApplication.run(HelloApplication.class, args);
        }

        @RestController
        class HelloController {
                @GetMapping("/hello")
                String hello() {
                        return "Hello Kubernauts!, are there image transfer?";
                }
        }


}

With this change, I also changed Dockerfile so that it may not have conflicts with previous version. The modified Dockerfile is as follows:

FROM registry.docker-cn.com/library/openjdk:8-alpine
VOLUME /tmp
ADD ./target/hello-0.0.1-SNAPSHOT.jar /hello2.jar
RUN sh -c 'touch /hello2.jar'
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","q/hello2.jar"]

original Dockerfile is as follows:

FROM registry.docker-cn.com/library/openjdk:8-alpine
VOLUME /tmp
ADD ./target/hello-0.0.1-SNAPSHOT.jar /hello.jar
RUN sh -c 'touch /hello.jar'
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/hello.jar"]

Then I do the same steps as previously did:

docker build -t $USER/hello2:0.0.2 .
kubectl run hello2 --image $USER/hello2:0.0.2 --port 8081
kubectl expose deployment hello2 --type=NodePort

But hello2 could not be in ready state, while hello is in ready state. I could not see the difference between hello and hello2. Why hello2 could not be in ready state?

[root@master2 hello]# kubectl get pods
NAME                     READY     STATUS             RESTARTS   AGE
hello-7db856d974-sg9kh   1/1       Running            0          1h
hello2-5c9c6776d-zgvhs   0/1       ImagePullBackOff   0          51m

I then use kubectl logs: it shows:

-- user84592
kubernetes

1 Answer

5/16/2018
  1. You are adding the jar to /hello2.jar but the ENTRYPOINT points to q/hello2.jar.

  2. Your port is now 8081, but Springs default is 8080 which you correctly used in the first attempt.

Did you try to start the container locally and have a look into the logs?

-- Jannik Weichert
Source: StackOverflow