Deployment on Google kubernetes clusters with Maven
- DevOps
Deployment on Google kubernetes clusters with Maven
There are two ways to do the deployment
- By Installing gcloud sdk and kubectl at your local system.
- By using Google cloud shell
Here I am describing the steps for method 2 (By using Google cloud shell) because you don’t need any setup for your local system.
Step 1: Crete a file with name Dockerfile in your git repository root directory with the following content
FROM maven:3.6-jdk-11 as build #copy pom COPY pom.xml . #resolve maven dependencies RUN mvn clean install -Dmaven.test.skip -Dmaven.main.skip -Dspring-boot.repackage.skip && rm -r target/ #copy source COPY src ./src # build the app (no dependency download here) RUN mvn clean install -Dmaven.test.skip #RUN mvn -f app/pom.xml clean install package # latest oracle openjdk is the basis FROM openjdk:11 # copy jar file into container image under app directory #COPY app/target/kickstart-0.0.1-SNAPSHOT.jar app/app.jar COPY --from=build ./target/kickstart-0.0.1-SNAPSHOT.jar app/app.jar # expose server port accept connections EXPOSE 8080 # start application #CMD ["java","-Dspring.profiles.active=local", "-jar", "app/app.jar"] ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar","app/app.jar"]
Step 2: Open https://console.cloud.google.com and Open Cloud Shell by clicking the button in the navigation bar in the upper-right corner of the console.
At the bottom below screen will be opened
Step 3: Run the cammand with your cluster name
gcloud container clusters get-credentials <Cluster-name>
Step 4: Crete the docker image with git repository
sudo docker build -t <docker-image-name> <url-to-clone-repo>#<branch_name>
A prompt for git password
Step 5: Push the docker image
docker push <docker-image-name>
Step 6 : create a deployment.yaml file and place the following code or copy from previous deployment
apiVersion: apps/v1 kind: Deployment metadata: name: guardian spec: replicas: 1 selector: matchLabels: app: guardian template: metadata: labels: app: guardian spec: containers: - name: app image: <docker-image-name> ports: - containerPort: 8080 imagePullPolicy: Always readinessProbe: httpGet: path: /api/global/health # for checking readiness port: 8080 initialDelaySeconds: 5 periodSeconds: 30 livenessProbe: httpGet: path: /api/global/health # for checking liveness port: 8080 initialDelaySeconds: 5 periodSeconds: 30
and apply the deployment
kubectl apply -f <path to deployment.yaml file>
You can check deployment & pods status – scale by following cammands
kubectl get deployments kubectl get pods kubectl get service
Related content
Toll mangement and command centre with TMCC
We’re passionately committed to helping our clients and their customers thrive, working side by side to drive customer value and results..
A Smarter Health Safety Solution
We’re passionately committed to helping our clients and their customers thrive, working side by side to drive customer value and results..
Building fastest loan portal in India
We’re passionately committed to helping our clients and their customers thrive, working side by side to drive customer value and results..
Toll mangement and command centre with TMCC
We’re passionately committed to helping our clients and their customers thrive, working side by side to drive customer value and results...
Toll mangement and command centre with TMCC
We’re passionately committed to helping our clients and their customers thrive, working side by side to drive customer value and results..
Entreprise IT Transformation and Automation
We understand user and market, create product strategy and design experience for customers and employees to make breakthrough digital products and services