Skip to content

Google Cloud Deployment

PROJECT ZERO edited this page Jan 18, 2025 · 1 revision

Google Cloud Deployment

This document provides step-by-step instructions for deploying the application to Google Cloud.

Prerequisites

Before you begin, ensure you have the following:

  • A Google Cloud account
  • Google Cloud SDK installed and configured
  • Docker installed

Step 1: Build the Docker Image

First, build the Docker image for the application.

docker build -t myapp:latest .

Step 2: Push the Docker Image to Google Container Registry (GCR)

Create a repository in Google GCR and push the Docker image to it.

  1. Authenticate Docker to the Google GCR registry:
gcloud auth configure-docker
  1. Tag the Docker image:
docker tag myapp:latest gcr.io/<your-project-id>/myapp:latest
  1. Push the Docker image:
docker push gcr.io/<your-project-id>/myapp:latest

Step 3: Deploy the Application to Google Kubernetes Engine (GKE)

Create a Kubernetes cluster and deploy the application to GKE.

  1. Create a Kubernetes cluster:
gcloud container clusters create my-gke-cluster --num-nodes=1
  1. Get the credentials for the Kubernetes cluster:
gcloud container clusters get-credentials my-gke-cluster
  1. Create a deployment YAML file (deployment.yaml):
apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp
spec:
  replicas: 1
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
      - name: myapp
        image: gcr.io/<your-project-id>/myapp:latest
        ports:
        - containerPort: 80
  1. Apply the deployment:
kubectl apply -f deployment.yaml
  1. Expose the deployment as a service:
kubectl expose deployment myapp --type=LoadBalancer --name=myapp-service

Step 4: Verify the Deployment

Verify that the application is running by checking the GKE service and accessing the application URL.

  1. Check the GKE service status:
kubectl get services myapp-service
  1. Access the application URL:

Retrieve the external IP address of the service and access the application in your web browser.

Conclusion

You have successfully deployed the application to Google Cloud using Google Kubernetes Engine (GKE) and Docker.

TABLE OF CONTENTS

Clone this wiki locally