Creating a local dev environment for Kubernetes with $0 cost
Tags: kubernetes, shipa, tutorial, microservices
Published: 2021-11-12 17:35:11

Embracing any new technology stack can certainly be a journey. No matter if this is your first time using Kubernetes or you have been on the Google Borg Team. 

This post will show you how to create a Kubernetes cluster, add it an application platform (Shipa), and start deploying applications with $0 cost. 

We will leverage minikube and a free Shipa Cloud account.

# Kubernetes Pre-Reqs

The first part is for us to create a local Kubernetes Cluster, where you can deploy applications to. A quick and free option we will use is minikube on your local machine. 

If you are using a Mac, installing minikube can be accomplished by leveraging Homebrew. 

Once Homebrew is installed, run:

`brew install minikube`

If using a new variant of Mac OS, an easy hypervisor to use for minikube is HyperKit. You can set minikube to leverage HyperKit. If you have not installed HyperKit before, Homebrew can take care of that also for you. Potentially you might have to install the machine driver if the brew formulae does not have it as a dependency.

```
brew install docker-machine-driver-hyperkit #optional
brew install hyperkit
```

Once HyperKit is installed, you can wire minikube to leverage HyperKit. 

`minikube config set driver hyperkit`

Lastly, depending on your machine size you can make dedicate more resources to minikube. For example I would like 8 gigs of memory dedicated to minikube. 

`minikube config set memory 8128`

Now you are all set to start your minukube cluster. 

`minikube start`

With minukube up and running, you can run a kubectl command to validate. Homebrew would have also laid down kubectl for you if installing minkube from Hoembrew. 

`kubectl get nodes`

![Kubernetes cluster setup](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/btxsio3jsdiirl43dvdc.png)

Now you are all set to create your Shipa Cloud account.

# Getting Started with Shipa Cloud

Our goal is to deploy and manage our applications without dealing with the underlying complexities that Kubernetes impose, so we will use Shipa Cloud for that.

You can [sign up for a free account here](https://apps.shipa.cloud)

![Shipa Cloud](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jt14vna900udm0gwi55l.png)

There are a few [core concepts](https://learn.shipa.io/docs/concepts) to work through. The first item that you will need to define is a Framework. A Shipa Framework is the lifeblood of your Shipa Configuration housing all the controls and policies. 

Shipa Cloud -> Frameworks + Create Framework -> Basic

![Creating Shipa Framework](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c1xcidu958dlk09ucyp4.png)

Creating a basic Framework for the example, just name your Framework “myfirstframework”. By default, you have access to a Plan and Team. The defaults for the example are fine. 

![Creating Shipa Framework](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9r687qx3423vbhd602jn.png)

Once you click Create, your Framework will be available. 

![Creating Shipa Framework](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7gp5m24uwpi5jfdpfd5x.png)

# Wiring Your Kubernetes Cluster to Shipa Cloud

You will need a few pieces of authentication from your minikube instance to connect it to Shipa Cloud. 

Shipa Cloud will need an accessible address to your cluster, a Kubernetes authentication token, and CA Certificate. 

## Public URL – ngrok

If you run the cluster-info command on your local minukube instance, you will get a local to your network address. 

`kubectl cluster-info | grep 'Kubernetes' | awk '/http/ {print $NF}'`

Leveraging a service like [ngrok](https://ngrok.com/), you can expose your local instance, more specifically the Kubernetes API. [This guide on ITNEXT](https://itnext.io/expose-local-kubernetes-service-on-internet-using-ngrok-2888a1118b5b) is really good for getting started. For evaluation purposes only, you can also expose the Kubernetes API. We will be doing that for this example. 

### Sign up and Install ngrok 

You can sign up for a free account with ngrok. Installing the ngrok client is easy with homebrew by running:

`brew install –cask ngrok`

Once installed, you can head to the ngrok setup page and run the authorization command e.g “Connect your account:”

![ngrok](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oz5pkxo68saj2v5o0epv.png)

Then: `ngrok authtoken <your_token>`

![ngrok](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i615906kvt9nj18rccui.png)

Once that is connected, you can leverage an [HTTP proxy for the Kubernetes API](https://kubernetes.io/docs/tasks/extend-kubernetes/http-proxy-access-api/)

`kubectl proxy --disable-filter=true`

Then can fire up ngrok to front the traffic over your localhost and the default Kubernetes API Port e.g 8001. 

`ngrok http 8001`

![ngrok](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jrw5z5jblvh4yyqrhr5u.png)

Grab the HTTP forwarding address and can save that for the Shipa Cloud Cluster configuration. 

## Kubernetes Auth Token

Creating an authorization token based off a Kubernetes role is straightforward. The [Shipa Documentation](https://learn.shipa.io/docs/connecting-clusters) for connecting a cluster gives the needed manifest to create the role and base the token off of. 

Create the [shipa-admin-service-account.yaml](https://learn.shipa.io/docs/connecting-clusters#cluster-connection) file with the following content:

![Shipa service account creation file](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zajaj7akbh4wypzhzqqk.png)

Then apply the manifest. 

`kubectl apply -f shipa-admin-service-account.yaml`

With the service account created, you can grab the authorization token. Can re-run the below command when it is time to copy and paste into Shipa Cloud. 

`kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep shipa-admin | awk '{print $1}')`

![Required Cluster Information](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lplish1ol466hnskd2te.png)

You can also grab the CA Certificate for service account by running the following command. Similarly can re-run when needed to copy and paste into Shipa Cloud. 

`kubectl get secret $(kubectl get secret | grep default-token | awk ‘{print $1}’) -o jsonpath='{.data.ca\.crt}’ | base64 –decode`

## Adding the Cluster

Once you have the three needed pieces, you can add the cluster to Shipa Cloud. 

Shipa Cloud -> Clusters + Add Cluster 

Can name the cluster “myminikube” and leverage your framework you created earlier e.g “myfirstframework”.

![Adding Cluster Information](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g445nmxauykezjo7evwm.png)

Click Next and fill out the the connectivity information [HTTP address, token, and certificate] that was just created. 

![Adding Cluster Information](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oifkqhdtjdq4vlrwkpga.png)

Once you click Next, your Cluster will be available! 

![Cluster available on Shipa Cloud](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hws8v8arnxgvh7saq3l7.png)

Once your cluster is available, the world is your oyster and you are ready to start deploying your apps without all the Kubernetes related complexity. 

Leveraging Shipa Cloud to help drive engineering efficiency across the application stack is now possible. With the wide paintbrush that Shipa Cloud offers, the art of the possible is great.