Alexa and Kubernetes: Local Development and Deployment With DevSpace (VI)
In this article, I will discuss how to deploy the Alexa Skill in a local Kubernetes cluster and how to develop it using DevSpace.
Join the DZone community and get the full member experience.Join For Free
It is a fact that the development process in a Kubernetes environment is not easy. There are a lot of tools that help us in this process. For this use case, we are going to use DevSpace; a tool for developers that makes the Kubernetes lifecycle easier.
Here you have the technologies used in this project:
- Node.js v12.x
- Visual Studio Code
- Docker 19.x
- Kubectl CLI
- MongoDB Atlas Account
- go >=1.11
- DevSpace CLI
DevSpace is a client-only, open-source developer tool for Kubernetes and you can do the following tasks using it:
- Build, test, and debug applications directly inside Kubernetes.
- Develop with hot reloading: You can update your running containers without rebuilding images or restarting containers.
- Unify deployment workflows within your team and across dev, staging, and production.
- Automate repetitive tasks for image building and deployment.
This is how DevSpace works:
Now, I'll take you through how DevSpace works.
Mentioning the DevSpace documentation, DevSpace allows you to store all your workflows in one declarative config file:
- Codify workflow knowledge about building images, deploying your project, its dependencies, etc.
- Version your workflows together with your code (i.e. you can get any old version up and running with just a single command).
- Share your workflows with your teammates.
DevSpace helps your team to standardize deployment and development workflows without requiring everyone on your team to become a Kubernetes expert, such as the below:
- The DevOps and Kubernetes expert on your team can configure DevSpace using
devspace.yamland simply commits it via git.
- If other developers on your team check out the project, they only need to run DevSpace deploy to deploy the project (including image building and deployment of other related projects, etc.) and they have a running instance of the project.
- The configuration of DevSpace is highly dynamic, so you can configure everything using configuration variables that make it much easier to have one base configuration but still allow differences among developers (e.g. different sub-domains for testing).
Instead of rebuilding images and redeploying containers, DevSpace allows you to hot reload running containers while you are coding:
- Simply edit your files with your IDE and see how your application reloads within the running container.
- The high performance, bi-directional file synchronization detects code changes immediately and synchronizes files immediately between your local dev environment and the containers running in Kubernetes.
- Stream logs, connect debuggers, or open a container terminal directly from your IDE with just a single command.
Deploying and debugging services with Kubernetes requires a lot of knowledge and forces you to repeatedly run commands like kubectl get pod and copy pod ids back and forth. Stop wasting time, and let DevSpace automate the tedious parts of working with Kubernetes, such as the following:
- DevSpace lets you build multiple images in parallel, tag them automatically, and deploy your entire application (including its dependencies) with just a single command.
- Let DevSpace automatically start port-forwarding and log streaming, so you don’t have to constantly copy and paste pod ids or run 10 commands to get everything started.
DevSpace is battle-tested with many Kubernetes distributions including:
- Local Kubernetes clusters like minikube, k3s, MikroK8s, and kind.
- Managed Kubernetes clusters in GKE (Google), EKS (AWS), AKS (Azure), and DOKS (Digital Ocean).
- Self-managed Kubernetes clusters (e.g. created with Rancher).
The most important thing about DevSpace is that DevSpace is cloud-agnostic. That means that it depends on your Kubernetes context!
Once DevSpace has been explained, let’s take a look at our DevSpace configuration file.
Let’s take a look at this file step-by-step:
images: Here, we are going to specify the name of the image that we are going to use and where the
Dockerfile is stored. One cool feature of DevSpace is that you can overwrite the entry point of the Docker Image for debugging.
deployments: Here, we can specify all the deployment we want to deploy in our Kubernetes cluster. Here, you can specify Helm charts with is values, Kubernetes objects, or Component Helm Charts. These are charts made on the fly.
dev: Here, we will specify all the configurations that we need to develop our applications. In this example, we specify the auto-reload of the Docker image when there is a change on the
package.json and the
Dockerfile files. Then, we specify the sync folder that we want to keep synced between our machine and the Kubernetes Cluster.
One of the cool features that DevSpace has is that if we have any deployment dependencies with other GIT repos, we can add them down the
dependencies object in the YAML config file like this:
Start Deployment and Development
We have the configuration file properly filled. Now, we have to run the following commands to start our development with DevSpace:
When DevSpace is running and everything is deployed with all the files synced, DevSpace creates a WebUI where we can explore our deployment. The web is available here.
For example, we can see the logs of our pods:
Or we can run a shell terminal inside our pods directly through the website.
Now, we can start developing our Alexa Skill locally and synced automatically with our Kubernetes Cluster thanks to DevSpace.
I’m sure you already know the famous tool call Postman. REST APIs have become the new standard in providing a public and secure interface for your service. Though REST has become ubiquitous, it’s not always easy to test. Postman makes it easier to test and manage HTTP REST APIs. Postman gives us multiple features to import, test, and share APIs, which will help you and your team be more productive in the long run.
After running your application, you will have an endpoint available here. With Postman, you can emulate any Alexa Request.
For example, you can test a
Destroy and Stop De-Development
If we want to remove all the stack created by DevSpace, just run:
- The Official Node.js SDK Documentation
- Official Alexa Skills Kit Documentation
- Express Adapter Documentation
- Kind Documentation
- Kubernetes Documentation
- Devspace Documentation
As you can see, DevSpace makes our development process in a Kubernetes cluster easier. With just a configuration file and 3 commands, we have it all set up, and we can start developing our Alexa Skill.
I hope this example project is useful to you.
You can find the code here.
That’s all folks! Happy coding!
Opinions expressed by DZone contributors are their own.