normalian blog

Let's talk about Microsoft Azure, ASP.NET and Java!

How to update your Java application in ACS Kubernetes

This post is continuation of . Please read the post before this one if you haven't read it. I will show you how to update your Java application in ACS kubernetes in this post.

Update your Java application - Run this section at your Windows Docker Client

At first, update your Java application. Modify your "index.jsp" file like below.

<html>
 <head>
  <title>Docker deployed apps !!update!!</title>
 </head>
 <body>
  <h2>Hello World! on Docker !!update!!</h2>
 </body>
</html>

And run "mvn package" command in the Java project folder. After create new war file in "helloworld/target/helloworld.war", create new Docker image and launch the application by running below commands.

helloworld>docker build --no-chache -t normalian/wildfly-helloworld .

helloworld>docker images
REPOSITORY                                                  TAG                 IMAGE ID            CREATED             SIZE
normalian/wildfly-helloworld                                latest              xxxx2536f9e2        11 seconds ago      584MB
xxxxxxxxxxxxxxxxx.azurecr.io/normalian/wildfly-helloworld   latest              xxxx171bcbcf        40 minutes ago      584MB
jboss/wildfly                                               latest              xxxx152f84f9        5 days ago          584MB

helloworld>docker run -it --rm -p 8080:8080 normalian/wildfly-helloworld

After above, access http://localhost:8080/helloworld. Stop the application if you can check your update.

Push your Docker image into your private repository on Azure by running below commands.

helloworld>docker tag normalian/wildfly-helloworld xxxxxxxxxxxxxxxxx.azurecr.io/normalian/wildfly-helloworld

helloworld>docker push xxxxxxxxxxxxxxxxx.azurecr.io/normalian/wildfly-helloworld
The push refers to a repository [xxxxxxxxxxxxxxxxx.azurecr.io/normalian/wildfly-helloworld]
xxxx02afd48c: Pushed
xxxx5bc19b9a: Pushed
xxxx11518954: Layer already exists
xxxx13dfbb96: Layer already exists
xxxx519728f4: Layer already exists
xxxx7c284ded: Layer already exists
xxxx8d9413e4: Layer already exists
latest: digest: sha256:xxxxxxxxxxxxxxxxx1522ee990cd74155116034b15ab51198ecc9a7e246a926 size: 1789

Update your Java application - Run this section at Kubernetes master node

Connect Kubernetes master node by SSH(e.x, Bash on Ubuntu on Windows). Run below commands.

azureuser@k8s-master-3AEAFCA1-0:~$ kubectl set image deployment my-java-app01 my-java-app01=xxxxxxxxxxxxxxxxx.azurecr.io/normalian/wildfly-helloworld
deployment "my-java-app01" image updated

azureuser@k8s-master-3AEAFCA1-0:~$ kubectl get pod
NAME                             READY     STATUS              RESTARTS   AGE
my-java-app01-2735613267-h0gsp   0/1       ContainerCreating   0          5s
my-java-app01-979249178-1k5c9    1/1       Running             0          35m

azureuser@k8s-master-3AEAFCA1-0:~$ kubectl get services
NAME            CLUSTER-IP    EXTERNAL-IP    PORT(S)          AGE
kubernetes      10.0.0.1      <none>         443/TCP          3d
my-java-app01   10.0.174.35   23.99.81.xxx   8080:32298/TCP   1h

After above, access http://23.99.81.xxx:8080/helloworld via browser. You can check your updated Java application.

Please note "kubectl set image deployment my-java-app01 my-java-app01=xxxxxxxxxxxxxxxxx.azurecr.io/normalian/wildfly-helloworld:latest" won't work when you use "latest" tag for your Docker images.