DEV Community

Sagar Jadhav
Sagar Jadhav

Posted on • Originally published at developersthought.in

Deploy a Microservice in Kubernetes with zero lines of code

In general, To deploy a Microservice in Kubernetes you have to perform the following tasks:

Import a Google Kubernetes Engine

  1. Build a Docker Image of a Microservice
  2. Push that Docker Image into an Image Registry
  3. Create a YAML's for different Kubernetes objects such as Deployment, Service, Secret, etc.
  4. Apply those YAMLs using the following command:
   kubectl apply -f <FILE_NAME>
Enter fullscreen mode Exit fullscreen mode

All the above tasks require you to write a lot of code. What If I do all this in a single command?

Yes, It is possible. Using gopaddle you can deploy a Microservice in Kubernetes without writing any extra code in just one command.

Let me show you How?

Before you start deploying, finish the below prerequisites:

I. Sign up for a free trial account in gopaddle

II. Import a Google Kubernetes Engine (GKE) into your gopaddle account.

Import a Google Kubernetes Engine

III. Add an Image Registry in your gopaddle account.

Add an Image Registry

IV. Add a source code repository in your gopaddle account that will have a source code of a Microservice that you want to deploy in Kubernetes. For this blog, I have used node-hello repository.

Add a source code repository

V. Install gpctl CLI using the below commands:

wget https://gpctl.s3-ap-southeast-1.amazonaws.com/gpctl
Enter fullscreen mode Exit fullscreen mode
chmod +x gpctl
Enter fullscreen mode Exit fullscreen mode
cp gpctl /usr/local/bin/
Enter fullscreen mode Exit fullscreen mode

Note: Refer Official Documentation for more details.

Gear up yourself to deploy a Microservice in Kubernetes

Gear Up

Follow the below steps along with me.

I. Clone node-hello git repository using the following command:

git clone https://github.com/developersthought/node-hello.git
Enter fullscreen mode Exit fullscreen mode

II. Go to the node-hello directory using the following command:

cd <path_to_node_hello_repo>/
Enter fullscreen mode Exit fullscreen mode

III. Install dependencies using the following command:

sh buildScript.sh
Enter fullscreen mode Exit fullscreen mode

IV. log in to gopaddle account using the following command:

gpctl login -emailID=<EMAIL> --password=<PASSWORD> --endPoint=https://portal.gopaddle.io
Enter fullscreen mode Exit fullscreen mode
  • EMAIL: Email to connect to gopaddle account
  • PASSWORD: Password to connect to gopaddle account

V. Deploy Microservice in Kubernetes using the following command:

gpctl init --startScript=./runScript.sh --buildScript=./buildScript.sh --buildImage=node:8
Enter fullscreen mode Exit fullscreen mode

The above command will prompt you to select the Cluster, Registry, and Policy. Please select appropriately to proceed further.

That's it !! with this, you have deployed a Microservice in Kubernetes without writing any deployment code.

Hope you like this blog and find it useful, If Yes then do consider buying me a coffee.

Discussion (0)