Kubernetes 101 for Java Developers Demo
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
Stop the running application
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
Stop all:
docker stop mongo mininote-java
We have an application and image running in docker Now, we deploy application in a kubernetes cluster running in our machine
docker tag mininote-java <your-dockerhub-username>/mininote-java:1.0.0
docker push <your-dockerhub-username>/mininote-java:1.0.0
minikube start
cd kube
kubectl apply -f mininote.yaml
kubectl apply -f mongo.yaml
minikube dashboard
Check
minikube service mininote-service
minikube stop
az login
az aks get-credentials --name MyManagedCluster --resource-group MyResourceGroup
cd charts
helm install philly-note philly-note
kubectl get pods
kubectl get service
Check
http://<ingress_controller_IP>