Side Navigation

X

Deploy Spring boot app to GKE (Google Kuberenetes Engine)

create cluster -> create project (defaul namespace) -> connect cluster to local terminal.

create Dockerfile in root directory -> deployement.yml;

docker build -> docker push -> kubectl apply -f deployment.yml -> kubectl get pods -> kubectl get services –all -namespaces

 

Install Google Cloud SDK

and add google-sdk/bin/gcloud  to the PATH then configure kubernetes by

$gcloud components install kubectl (it will configure kubectl to gcloud)

$gcloud auth configure-docker

$gcloud init

create project -> create a cluster -> select a zone

$gcloud container clusters get-credentials practice –zone us-central1-c –project spring-boot-303707

username

password

we can also create cluster by using this command

$kubectl create clusterrolebinding cluster-admin-binding –clusterrole=cluster-admin –user=$(gcloud config get-value core/account)

Kubernete services -> activate istio

$ kubectl get services --all-namespaces

$ kubectl get pods –all-namespaces

$kubectl describe pods -n istio-system

create deployment.yml and deployment-mongo.yml

kubectl apply -f deployment.yml

$ kubectl get pods
NAME                      READY     STATUS    RESTARTS   AGE
spring-c5b8bf947-rkw5f   1/1       Running   0          21s

$kubectl get events (to see whats going on)

create Dockerfile at root level of the project

FROM openjdk:8-jdk-alpine  
ENV APP_FILE springbootkbe-0.0.1-SNAPSHOT.jar  
ENV APP_HOME /usr/app  
EXPOSE 8000  
COPY build/libs/*.jar $APP_HOME/  
WORKDIR $APP_HOME  
ENTRYPOINT ["sh", "-c"]  
CMD ["exec java -jar $APP_FILE"]

apiVersion: v1  
kind: Service  
metadata:  
  name: kayak-service  
  labels:  
    app: kayak-service  
spec:  
  ports:  
    - name: http  
      port: 8000  
  selector:  
    app: kayak-service  
---  
apiVersion: extensions/v1beta1  
kind: Deployment  
metadata:  
  name: kayak-service  
spec:  
  replicas: 1  
  template:  
    metadata:  
      labels:  
        app: kayak-service  
        version: v1  
    spec:  
      containers:  
        - name: kayak-app  
          image: gcr.io/spring-boot-gke-<id>/kayak-app:1.0  
          imagePullPolicy: IfNotPresent  
          env:  
            - name: MONGODB_HOST  
              value: mongodb  
          ports:  
            - containerPort: 8000  
          livenessProbe:  
            httpGet:  
              path: /  
              port: 8000  
            initialDelaySeconds: 5  
            periodSeconds: 5
gcloud auth configure-docker (to configure Docker to gcloud)
docker build -t spring-app:1.0 .

Tag the image and push it to the Google container registry (again note the Google Cloud project name):

docker tag kayak-app:1.0 gcr.io/$PROJECT_NAME/kayak-app:1.0;  
docker push gcr.io/$PROJECT_NAME/kayak-app:1.0

Now apply the deployment.yml file to the GKE cluster:

kubectl apply -f deployment.yml

Check to make sure the pod deployed properly:

kubectl get pods

You May Also Like

Comments

Leave a Comment

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>