Java Application on Kubernetes: Development Made Easy with Docker Desktop

By Manikandan DUpdated as on November 9, 2023 4 minutes read 75 Views


In this guide, we will walk through the process of enabling Kubernetes in Docker Desktop and deploying a Java application on a Kubernetes cluster node by using ingress-nginx.

Configuration step

  1. Installing the Docker Desktop
  2. Enabling the kubernetes in Docker Desktop
  3. Building Docker Images
  4. Deploying the java application in kubernetes cluster

Installing the Docker Desktop

  • WSL version or later.
  • Windows 11 64-bit: Home or Pro version 21H2 or higher, or Enterprise or Education version 21H2 or higher.
  • Windows 10 64-bit: Home or Pro 21H2 (build 19045) or higher, or Enterprise or Education 21H2 (build 19045) or higher.
  • Turn on the WSL 2 feature on Windows.

The following hardware prerequisites are necessary for successfully running WSL 2 as a backend on Windows 10 or Windows 11.

64-bit processor , 8GB system RAM, BIOS-level hardware virtualization support must be turned on in the BIOS settings

Download Docker Desktop by following the link, then install it and reboot your system.

After licensing, if you encounter a “Docker Desktop required a newer WSL kernel version” error, you can resolve it by updating the kernel using the “wsl-update” command.

At the end, we have installed and started Docker Desktop. You can verify the Docker engine and client’s running status by using the “docker –version” command.

Enabling the kubernetes in Desktop docker

  1. In Docker Dashboard, select the Settings and then Kubernetes from the left sidebar.
  2. Click the checkbox on Enable kubernetes and apply & restart, save the setting.


Kubernetes containers will be hidden within Docker Desktop containers, and they won’t appear in commands like “docker ps.” To view the Docker Kubernetes containers, navigate to Settings -> Kubernetes, check the “Show system containers (advanced)” checkbox, and then click apply & restart.

You can verify the status of the local Kubernetes cluster nodes by using the command “kubectl get node.”

Building Docker Images

Here is a sample Dockerfile for a java application to build a Docker image.


FROM openjdk:17-jdk-slim
COPY app.jar app.jar
EXPOSE 8080 5701
ENTRYPOINT java -jar app.jar
docker build -t my-app:1.0.0.

Once the Docker image build process is finished, you’ll be able to find the “my-app:1.0.0” Docker image in the Docker Desktop images as below.

Deploying java application in kubernetes cluster

Now, let’s see how to deploy an application within a new namespace in a local Kubernetes environment.

Installing ingress-nginx

Ingress-Nginx is a popular Kubernetes Ingress controller that facilitates the management of external access to services within a Kubernetes cluster. It plays a crucial role in routing and controlling incoming traffic to various applications and services, offering essential features such as load balancing, routing, security, and more.

kubectl apply -f

Namespace creation

Name: ns.yaml

apiVersion: v1
kind: Namespace
  name: development

Created the new namespace as “devlopment”

Deployment Creation


apiVersion: apps/v1
kind: Deployment
  name: app-deployment
  namespace: development
  replicas: 2
      app: app-lab
      version: "1"
        app: app-lab
        version: "1"
        - name: app-deployment
          image: my-app:1.0.0 
          imagePullPolicy: IfNotPresent
            - name: APP_VERSION
              value: "6"              
            - name: http
              containerPort: 8080
            - containerPort: 5701
              protocol: TCP
              name: multicast

image: my-app:1.0.0 – using locally built image.

imagePullPolicy: IfNotPresent – to pull image from local docker image repository.

Kubectl apply -f deployment.yaml

Created the containers, pods, replicaSets in the background.

Services — Access the deployment

Name: Service.yaml

kind: Service
apiVersion: v1
  name: app-svc
  namespace: development
    app: app-lab
    version: "1"
    - name: http
      port: 80
      targetPort: http
apiVersion: v1
kind: Service
  name: hazelcast-service
  namespace: development
    app: app-lab
    version: "1"
    - name: multicast
      port: 5701
  type: ClusterIP
kubectl apply -f service.yaml

Both “App-svc” and “hazelcast-service” service connect to all the pod of “app-deployment” deployment .

Nginx ingress – Routing the traffic to service


kind: Ingress
  name: app-nginx
  namespace: development
  annotations: "nginx"
    # --- Optional ---
    # If server Push is enabled in the application and uses Websocket for transport,
    # these settings replace the default Websocket connection timeouts in Ngnix. "86400" "86400"
    # --- "cookie" "persistent"
    - http:
          - path: /
            pathType: Prefix
                name: app-svc
                  number: 80
Kubectl apply -f ingress.yaml

When you access “http://localhost,” Nginx Ingress will route the traffic to your service “app-svc,” and “app-svc” will then direct it to one of the pods in the “app-deployment” deployment.


By using Docker desktop , Developers can easily set up a Kubernetes local environment, deploy their applications within Kubernetes, and test them as if they were in a production environment.