Over 10 years we help companies reach their financial and branding goals. Engitech is a values-driven technology agency dedicated.

Gallery

Contacts

411 University St, Seattle, USA

contactus@lucidpath.io

+1 -800-456-478-23

GoLang
What are the top frameworks used by companies using Golang?

Guide on how to Deploy Mern Stack App on GCP GKE

The deployment process must be understood by Mern Stack Developers after the application has been built, as we covered in the previous post on how to develop a Mern stack app on GCP GKE. The Google Cloud Platform (GKE) deployment of the application is quite different from the deployment on other platforms. The majority of enterprises chose GCP as a platform to deploy their apps due to digitization. It is a little complicated, but we are here to make it simple by dissecting the process and attempting to make it as clear and understandable to you as possible.

Deployment procedure in detail:

It involves seven steps. Every Mern Stack developer should be familiar with the principles of Mern Stack technology, Kubernetes, Docker, etc. in order to comprehend this approach in depth. As their experience enables you to comprehend what is required to understand the deployment procedure simply, it is advised to get professional aid from experienced specialists from either the Mern Stack app development businesses or Mern Stack platforms if you find it tough to understand.

Dockerize your web application:

The web application must be dockerized before you begin the deployment process because Google GKE makes it simple to run K8 on GCP, making this step crucial. It’s crucial to create images using Docker files. You can download programmes more quickly and with fewer attacks thanks to Docker images. For ease of comprehension, the steps for creating Docker images are broken down step by step.

  • UI build stage:

            The basic image for creating Docker images is node:14-slim. The package.json files for the react server and node.js server must be added to a docker file system. Install the prerequisites needed for this level. Copy the source file after installing each dependency file. Once the React app has been built, execute npm run build. The build folder, which is located inside the UI folder, contains all required files or components.

  • API build stage:

            Once more, begin with the primary image. Then transfer just the package.json files for node.js to the /.api folder. Set up the required dependencies. the server.js file into the same folder, and then copy it there.

  • Packaging the app:

Start with the fundamental illustration. Take a copy of the API and UI build files. Use the node api.bundle.js command to package the application after that.

  • Building docker image:

For creating images, use docker build -t mern-image. Using Docker images, you can verify whether or not you built the right images once they are created. If not, carry out the same procedures again until the right Docker images are created.

  • Running web app on Docker:

            Running your web application on Docker is the next step after creating the Docker image. Simply use the following command to launch the Docker image:

// run the container

docker run -d -p 80:80 –name mern-stack mern-image

// list the container

docker ps

// logs

docker logs mern-stack

// exec into a running container

docker exec -it mern-stack /bin/sh

The majority of Mern Stack developers have issues launching Docker images. Carefully complete this step and fix any errors discovered when running the web application. Once the aforementioned instructions have been executed, you can access your web application at https://localhost/.

  • Pushing image to container registry:

            One platform where you can easily manage all the Docker images is a container registry. Even who has access to your data is up to you. Let’s concentrate on the push process for the GCP container registry. The sole requirement is having a pertinent API on GCP. Use the command below after signing into GCP to see if the API is enabled or not.

            enable containerregistry.googleapis.com using gcloud services.

            Then, to configure Docker with the GCP container registry, use cloud auth configure-docker. The docker tag web app gcr.io/staticweb-test/webapp:v1 command can be used to add tags to a docker image after it has been produced. Here, the sample project is called static web-test, the web app is represented by a Docker image, and the image tag is v1. You may push the Docker image into the GCP container registry by executing docker push gcr.io/staticweb-test/webapp:v1 after that. Before pushing the actual Docker image used for their projects, Mern Stack developers should practise with fake images to make this step easier.

  • Creating GKE cluster:

            Running the gcloud container clusters create my-cluster command creates the cluster, which is the next step. By logging into the GCP console and taking the following actions, you may also construct a cluster:

  1. For the procedure to begin, click the “create” button.
  2. The options GKE standard and Autopilot are shown. The GKE standard should always be used when building clusters.
  3. Click the “create cluster” button after entering the cluster’s basic information.
  4. Three nodes are used to establish a new cluster. Use the gcloud container clusters list command to see a list of the clusters.
  • Configure Kuebctl With the GKE Cluster:

            Using the GCP console makes configuration really simple. The command utility line for K8 used in Mern stack web applications is called kuebctl. You need to instal it first before configuring it. After installation, select the connect option found on the GCP console. You can configure Kuebctl with the GKE cluster using a new command. To configure, copy the command and run it on your terminal.

            Clusters of gCloud containers get-credentials The example command frontend-cluster -zone us-central1-c -project static web-test was developed using the information entered while building a new cluster using the GCP console.

  • Deploying K8 objects on the GKE cluster:

            The K8 objects can now be deployed by generating deployment and service objects. then utilise the earlier-created image from the GCP container registry. Get the image console URL information from the details section of the container registry where your image or repository is located in order to continue. After copying the information, use the kubectl create -f manifest.yml command to create service objects. Use the commands listed below to determine whether the objects are in the desired condition once they have been created:

// list the deployment

kubectl get deploy

// list the pods

kubectl get pod

// list the service

kubectl get svc

You can determine how many copies were made for the deployment process by counting the number of running pods.

  • Deleting the cluster:

            You can access the web application using a browser once the application has been deployed. Making an external IP from the load balancer is one method of getting access to the application. Using the gcloud container clusters remove [CLUSTER NAME] command, you can delete the cluster after determining that no changes need to be performed.

Summary:

Since the majority of organisations prefer to deploy apps on GCP or GKE clusters due to their popularity and strong demand, every Mern Stack developer should be aware of this procedure. The greatest strategy to stay one step ahead of your competition is to properly learn this procedure under the expert direction of knowledgeable Mern Stack Developers. Their expertise aids in improving understanding.

About us:

A one-stop shop for mern-stack development is Lucidpath. The majority of organisations rely on the skills of our knowledgeable Mern Stack engineers to properly implement this technology without any problems.

 

Author

Adarsh Suresh

Leave a comment

Your email address will not be published. Required fields are marked *