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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
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
1 |
gcloud container clusters get-credentials <Cluster-name> |
Step 4: Crete the docker image with git repository
1 |
sudo docker build -t <docker-image-name> <url-to-clone-repo>#<branch_name> |
A prompt for git password
Step 5: Push the docker image
1 |
docker push <docker-image-name> |
Step 6 : create a deployment.yaml file and place the following code or copy from previous deployment
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
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
1 |
kubectl apply -f <path to deployment.yaml file> |
You can check deployment & pods status – scale by following cammands
1 2 3 |
kubectl get deployments kubectl get pods kubectl get service |
Related content
Auriga: Leveling Up for Enterprise Growth!
Auriga’s journey began in 2010 crafting products for India’s