Sign inSign up

shinyay/spring-hello-gke

By shinyay

•Updated over 6 years ago

Image
0

365

shinyay/spring-hello-gke repository overview

⁠Simple Hello World by Spring on GKE

Hello World App by Spring Boot deployed to GKE with Cloud Build

⁠Description

This project describes how to deploy Spring App to GKE using CI/CD pipeline by Cloud Build.

⁠Demo

⁠1. Build Container Image
⁠Multi-Stage Build
FROM gradle:6.5.0-jdk11 as build
COPY --chown=gradle:gradle . /home/gradle/src
WORKDIR /home/gradle/src
RUN gradle assemble --no-daemon

FROM openjdk:11.0.5-jre-slim-buster
COPY --from=build /home/gradle/src/build/libs/*.jar /app.jar
:
:
⁠2. Containerize with Cloud Build

hello-gke is app-name and repository-name.

⁠Get your Google Cloud project ID
$ gcloud config get-value project
⁠Build your container image using Cloud Build
$ gcloud builds submit --tag gcr.io/<GOOGLE_PROJECT_ID>/hello-gke <DOCKERFILE_DIRECTORY>
⁠3. Create GKE Cluster

hello-gke-cluster is GKE cluster name.

⁠Create GKE Cluster as Cloud Platform Scope
$   gcloud container clusters create <GKE_CLUSTER_NAME> \
    --num-nodes 1 \
    --scopes cloud-platform \
    --enable-stackdriver-kubernetes \
    --enable-ip-alias \
    --zone us-central1-c
⁠Generate kubeconfig entry
$ gcloud container clusters get-credentials <CLUSTER_NAME> --zone us-central1-c
⁠4. Deploy App to GKE Cluster
⁠Deployment Configuration
apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello-gke-deployment
spec:
  selector:
    matchLabels:
      app: hello-gke
  replicas: 1
  template:
    metadata:
      labels:
        app: hello-gke
    spec:
      containers:
      - name: hello-gke-app
        image: gcr.io/GOOGLE_CLOUD_PROJECT/hello-gke:latest
        ports:
        - containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
  name: hello-gke
spec:
  type: NodePort
  selector:
    app: hello-gke
  ports:
  - protocol: TCP
    port: 8080
    targetPort: 8080
⁠Service Configuration for LoadBalancer
apiVersion: v1
kind: Service
metadata:
  name: hello-gke-loadbalancer
spec:
  type: LoadBalancer
  selector:
    app: hello-gke
  ports:
  - protocol: TCP
    port: 80
    targetPort: 8080
⁠Ingress Configuration
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: hello-gke-ingress
spec:
  rules:
  - http:
      paths:
      - path: /*
        backend:
          serviceName: hello-gke
          servicePort: 8080
⁠Deploy to GKE Cluster
$ kubectl apply -f spring/kubernetes/deployment.yml
$ kubectl apply -f spring/kubernetes/service.yml
$ kubectl apply -f spring/kubernetes/ingress.yml
⁠5. Create and Associate wuth Source Repository

hello-gke is source-repository-name.

⁠Create Source Repository
$ gcloud source repos create <REPOSITRY_NAME>
⁠Associate with Source Repository
$ git config credential.'https://source.developers.google.com'.helper gcloud.sh
$ git remote add google https://source.developers.google.com/p/(gcloud config get-value project)/r/$_flag_repository
$ git push google master
⁠6. Bind Roles of GKE and CSR with Cloud Build
$ gcloud projects add-iam-policy-binding (gcloud config get-value project) --member serviceAccount:<CLOUDBUILD_SA> --role roles/container.admin
$ gcloud projects add-iam-policy-binding (gcloud config get-value project) --member serviceAccount:<CLOUDBUILD_SA> --role roles/source.writer

⁠Features

  • feature:1
  • feature:2

⁠Requirement

⁠Usage

⁠Installation

⁠Licence

Released under the MIT license⁠

⁠Author

shinyay⁠

Tag summary

Content type

Image

Digest

Size

88.5 MB

Last updated

over 6 years ago

docker pull shinyay/spring-hello-gke