Deploy a Microservice in Kubernetes with zero lines of code
Tags: kubernetes, microservices, devops, node
Published: 2021-09-22 05:26:51

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

![Import a Google Kubernetes Engine](https://raw.githubusercontent.com/sagar-jadhav/sagar-jadhav.github.io/master/static/img/_posts/deploy-microservice.JPG)

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>
   ```

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](https://www.gopaddle.io/) 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](https://gopaddle.io/)

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

![Import a Google Kubernetes Engine](https://raw.githubusercontent.com/sagar-jadhav/sagar-jadhav.github.io/master/static/img/_posts/import_cluster.png)

III. Add an Image Registry in your gopaddle account.

![Add an Image Registry](https://raw.githubusercontent.com/sagar-jadhav/sagar-jadhav.github.io/master/static/img/_posts/add_image_registry.png)

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](https://github.com/developersthought/node-hello) repository.

![Add a source code repository](https://raw.githubusercontent.com/sagar-jadhav/sagar-jadhav.github.io/master/static/img/_posts/add_code_repository.png)

V. Install `gpctl` CLI using the below commands:

```
wget https://gpctl.s3-ap-southeast-1.amazonaws.com/gpctl
```

```
chmod +x gpctl
```

```
cp gpctl /usr/local/bin/
```

**Note:** Refer [Official Documentation](https://portal.gopaddle.io/tutorials) for more details.

#### Gear up yourself to deploy a Microservice in Kubernetes

![Gear Up](https://media.giphy.com/media/WoiaGtXaOYwRqS2J3m/giphy.gif?cid=ecf05e47e4mh6bo9ec1wp7uag3hrkl9k6fjb5dk4ii82002f&rid=giphy.gif&ct=g)

Follow the below steps along with me.

I. Clone [node-hello](https://github.com/developersthought/node-hello) git repository using the following command:

```
git clone https://github.com/developersthought/node-hello.git
```

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

```
cd <path_to_node_hello_repo>/
```

III. Install dependencies using the following command:

```
sh buildScript.sh
```

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

```
gpctl login -emailID=<EMAIL> --password=<PASSWORD> --endPoint=https://portal.gopaddle.io
```

- 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
```

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](https://www.buymeacoffee.com/sagarjadhv23)._