Deploying Your First Application on Google Kubernetes Engine (GKE)

Kubernetes is an open-source system that automates the deployment, scaling, and management of containerized applications. Google Kubernetes Engine (GKE) is a managed, production-ready environment for running Kubernetes clusters. This blog will guide you through deploying your first application on GKE.

Step 1: Setting up your Google Cloud account and project

Before starting, ensure you have a Google Cloud account. If not, head over to the Google Cloud signup page and create a free account. Once you've logged in, navigate to the Google Cloud Console and create a new project. You can do this by clicking on the project drop-down and selecting the New Project option.

Step 2: Enabling Kubernetes Engine API

For the newly created project, we need to enable the Kubernetes Engine API. Navigate to the APIs & Services >  Library. Search for Kubernetes Engine API and enable it.

Step 3: Installing and setting up the Google Cloud SDK

Google Cloud SDK is a set of tools that can interact with the Google Cloud Platform directly from your machine. Download and install the Google Cloud SDK according to your OS.

Once installed, authenticate your account by running the following command in the terminal:

gcloud auth login

Set your project ID with the following command

gcloud config set project YOUR_PROJECT_ID

Replace YOUR_PROJECT_ID with the ID of the project you created in the Google Cloud Console.

When you’re done, you can now set up the CTO.ai GCP GKE workflow to deploy and install your infrastructure. If you don’t have access to this repository, kindly reach out to our support team(Support@cto.ai)

Once you have access, you have to set up and build your infrastructure using the ops run setup command.

The GCP GKE Pulumi workflow allows you to manage infrastructure over GCP, the resources that are defined to be managed are the following: Network, GKE: Kubernetes, GCR, Database, Storage buckets.

Once you are done building your infrastructure, you can now deploy to your environment (DEV, STG, PROD) using the ops run deploy command.

Next, deploy your application on your cluster using the following command

kubectl create deployment YOUR_DEPLOYMENT_NAME --image=gcr.io/YOUR_PROJECT_ID/YOUR_APP_NAME

Replace YOUR_DEPLOYMENT_NAME with a name for your deployment.

Step 4: Exposing your application

By default, your application is not accessible from the internet. To expose it, you need to create a service. Run the following command:

kubectl expose deployment YOUR_DEPLOYMENT_NAME --type=LoadBalancer --port 80 --target-port 8080

This command will expose your application on port 80. --target-port is the port on which your application is running in the container.

Once the service is created, you can get the external IP of your application by running the following command: kubectl get service

Step 5: Clean up

When you're done with your application, you might want to delete your cluster, and infrastructure to avoid unnecessary charges. You can do this using the following command: ops run destroy


Conclusion

Congratulations! You've just deployed your first application on Google Kubernetes Engine. CTO.ai provides a managed, production-ready environment for running Kubernetes clusters, services, simplifying the process of deploying and managing containerized applications. Keep exploring and learning more about the capabilities of GKE to fully leverage its features. Reach out to our support team if you need any help.

Happy coding!