Skip to content

helayoty/Kubernetes-101-for-Java-developers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kubernetes-101-for-Java-Developers

Kubernetes 101 for Java Developers Demo

Build and run application:

Spring boot and mysql database running on docker

Clone from repository

git clone [email protected]:helayoty/Kubernetes-101-for-Java-Developers.git

Build application

cd java-kubernetes
mvn clean install

Set MongoDB connection

cd src/main/resources
vim application.yml
spring:
  data:
    mongodb:
      uri: ${MONGO_URL:mongodb://localhost:27017/dev}

Run application

mvn spring-boot:run

# or you can use this command: 
# java --enable-preview -jar target/java-kubernetes.jar

Check

http://localhost:8080/

Stop the running application

Part two - Dockerize Java app:

Create a Dockerfile:

  FROM maven:3.6.3-jdk-11 AS base
  WORKDIR /app
  ADD pom.xml /app

  # ----Build App with Dependencies ----
  FROM base AS dependencies
  ADD . /app

  RUN mvn clean package -DskipTests

  #Define the base layer for the container
  FROM adoptopenjdk/openjdk11:jdk-11.0.2.9-slim AS release
  #Set the working directory
  WORKDIR /opt
  #Use to set any env variables
  ENV PORT 8080
  EXPOSE 8080
  #Copy the jar files from target into the directory inside the container
  COPY --from=dependencies /app/target/*.jar /opt/app.jar
  #Execute java inside the container
  ENTRYPOINT exec java $JAVA_OPTS -jar /opt/app.jar

Build application and docker image

docker build -t mininote-java .

Create Docker network

docker network create mininote

Run mongoDB inside docker

docker run --name=mongo --rm --network=mininote mongo

Run the application container

docker run --name=mininote-java --rm --network=mininote -p 8080:8080 -e MONGO_URL=mongodb://mongo:27017/dev mininote-java:1.0.0

Check

http://localhost:8080/

Stop all:

docker stop mongo mininote-java

Part three - app on local Kubernetes:

We have an application and image running in docker Now, we deploy application in a kubernetes cluster running in our machine

Push your image to Docker Hub first

docker tag mininote-java <your-dockerhub-username>/mininote-java:1.0.0

docker push <your-dockerhub-username>/mininote-java:1.0.0

Start minikube

minikube start

deploy your app

cd kube

kubectl apply -f mininote.yaml
kubectl apply -f mongo.yaml

Open Dashboard

minikube dashboard

Check

minikube service mininote-service

stop minikube

minikube stop

Part four - app on cloud Kubernetes (AKS):

az login
az aks get-credentials --name MyManagedCluster --resource-group MyResourceGroup

deploy your app

cd charts

helm install philly-note philly-note

verify pod is up and running

kubectl get pods

get service ip to access application

kubectl get service

Check

http://<ingress_controller_IP>

About

Kubernetes 101 for Java Developers Demo

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published