Remember Heroku? I bet you do! I wouldn’t be surprised if your entire app is being powered by Heroku right now!

Heroku took the world by storm with its Platform-as-a-Service. Though it was originally for Ruby, they now have expanded to cover most of the languages. They have a ton of integrations and other managed server offerings.

A single command to deploy your app makes operations a hell lot easier. I guess that was why Heroku took off in the first place.

In a not so distant land reigns Google Firebase. It’s an amazing Backend-as-a-Service application which advocates backendless apps. Firebase sets the bar super high by eliminating the need to deploy any form of a backend. All database interaction logic sits on the frontend. The backend is fully managed by Google.

Deploying Apps Is a Nightmare

No matter where you come from, if you have deployed any app in production, and were responsible for making sure its always up, you know what I’m talking about.

That’s the beauty of platforms like Heroku and Firebase. They let us sleep at night.

However, Heroku turns out to be really expensive at scale, and not all logic can be written on the frontend right?

We need a platform which gives us the power to do both. Moreover, we must have the flexibility to choose our database and the cloud we want to work in.

Let’s Build a Solution

Kubernetes to The Rescue

Kubernetes is an open-source container orchestration tool. You basically give it a container to run, specify some constraints like replicas, resources, etc., and off you go.

It will run your container, and make sure it keeps running.

The problem is that it runs containers. It’s not too much to ask, but I’d prefer to deploy my apps directly without having to worry about dockerize everything.

In Comes Space Cloud

Space Cloud is a web server which provides a realtime data access layer. Basically, it’s an open-source Firebase alternative which can run on any cloud and works with any database.

It also provides a framework to write microservices in the form of functions. Think of this as an AWS Lambda, running as a long-lived process. So, basically, you can now run long-lived TensorFlow models in your microservices while maintaining an API similar to lambda.

All of the features described above are completely open-source.

Space Cloud Enterprise comes with a deployment module which natively connects with Kubernetes. This means you can now host your frontend and run you microservices on Kubernetes with a simple CLI command.

The best part? Space Cloud Enterprise costs just $10 for this feature.

Let’s Get Hacking!

Enough talk. Let’s get straight to it. We are gonna be building our own Heroku + Firebase environment over the next 30 minutes.

I’ll be available at the SpaceUpTech Discord server to help you accomplish this mission just in case you need any help.

So what all do we need?

  • Single-node Kubernetes cluster on DigitalOcean. Costs $20 per month
  • Space Cloud Enterprise. Costs $10 per month
  • Courage to ride the serverless wave!

To run you through all the steps really quick, we will be:

  • Creating a Kubernetes cluster on DigitalOcean. You’ll need a DO account for that.
  • Installing and configuring kubectl to talk to our newly created cluster.
  • Deploying MongoDB to our cluster using kubectl.
  • Deploying Space Cloud to our cluster. This will be done using the kubectl tool.
  • Configuring Space Cloud to enable the deploy module, and activating the deploy module by making a free account on Space Up Tech.
  • Downloading the Space CLI and deploying a web-based to do app using that.

Head over to the DigitalOcean website, sign up and create a Kuberntes cluster. Here’s a super awesome guide to create a Kubernetes cluster on DigitalOcean.

Create a Kub Clusters

To create a Kubernetes cluster:

From the Create menu in the control panel, click Clusters. Choose San Francisco 2 as the datacenter region.

Customize the default node pool, choose the 2CPU instance type, and set the number of nodes to 1. This will cost you $20 per month.

Name the cluster kube-sc and, optionally, add a tag.

Click Create Cluster. Provisioning the cluster takes several minutes.

Note down the Public IP of the droplet just created. We’ll need this public IP later.

Configure Kubectl

  • Install kubectl. It’s the tool used to talk to the Kubernetes cluster. We will need it just once to deploy Space Cloud to Kubernetes.

  • Download the cluster configuration file from the DigitalOcean Control Panel. It’s going to be on the Kubernetes page. Download this file to the .kube directory inside your home folder and save by the name config. Remove the .yaml extension.

  • To create a default cluster-admin role run

    kubectl create clusterrolebinding default-cluster-admin --clusterrole=cluster-admin --serviceaccount=default:default
    

Deploy MongoDB

Space Cloud doesn’t yet support deploying stateful services. So we’ll be deploying MongoDB using kubectl.

  • To deploy MongoDB run

    kubectl run mongodb --image=mongo --port 27017
    
  • Now to make it accessible in the cluster by running

    kubectl expose deployment mongodb --port 27017 --target-port 27017
    

Run Space Cloud on Kubernetes

Now we need to deploy the SC

  • Run the following command to run SC:

    kubectl create deployment space-cloud --image=spaceuptech/space-cloud
    
  • Expose SC to the external world:

    kubectl create service nodeport space-cloud --tcp=4122 --node-port=30122
    

Configure Space Cloud

All features resembling Firebase are completely open-source in Space Cloud. However, the Kubernetes integration is an enterprise level feature.

  • Open http://PUBLIC_IP:30122/mission-control and log in.
  • The default user is admin while the password is 123. In an upcoming tutorial, I will be talking about configuring Mission Control which talks about changing the default credentials as well.
  • Create a new Project. Name it test-kube. Choose MongoDB as the default database.
  • In the User Management section, enable Mail Authentication.
  • Head over to the Database section. Edit the MongoDB connection string to mongodb://mongodb:27017 and hit save.
  • In the Static Hosting section, add a route and enter the following config: { "prefix": "/", "proxy": "http://todo-app:8000" }
  • Go to the Plans section and select Standard.
  • It will prompt you to sign into SpaceUpTech. Create a free account. Without this, you will not be able to use the deployment module.
  • Next step is to enable the deploy module. You can do this in the Deploy section.

Deploy the Frontend

Man! That was a lot of steps. Maybe I should write a shell script to do all of this next time. Just one more step to go, guys.

  • The final step is deploying the frontend. For this, we will need Space CLI. Download the package for your OS and don’t forget to make it executable and add it to your path:
  • Now download the frontend archive I’ve created for you.
  • Extract it and cd into the folder.
  • Run the space-cli init command and enter the name todo-app. The project is test-kube. Kind is a Web App. Leave the rest to defaults.
  • Run space-cli cluster add test-kube http://PUBLIC_IP:30122 followed by space-cli login test-kube. The username is admin and the password is 123. This is the same username and password we used to log into mission-control.
  • To deploy, all you need to do is run space-cli deploy test-kubecommand. This will package your app and ship it out to you cluster.

Check the app out http://PUBLIC_IP:30122. Open it in multiple tabs to check out the crazy realtime feature.

From here on, you can deploy any service or web app directly without having to deal with kubectl.

Wrapping Up

That was one heck of a tutorial. In the days ahead, my goal will be simplifying this entire process.

Space Cloud is a pretty cool tool. I know I’m talking about my own project here, but you must give it a try. You can follow the quick start page to get things up and running or get your hands dirty with the getting started guide.

If you like what we are doing, do star us on GitHub.We would love to get you on board as well! You can start by posting about a bug or suggest improvements. Also, you can join our Discord server to get in touch with us directly.