Alexa and Kubernetes. Deploying the Alexa Skill on Azure Kubernetes Services (VIII)
In this blog post, we will see how to create a Kubernetes Cluster and deploy our Alexa Skill with Terraform using Azure Kubernetes Services.
Join the DZone community and get the full member experience.Join For Free
Now we have everything prepared and ready to go to a Kubernetes Cluster in a cloud provider. It is a fact that create a cluster in any cloud provider manually is a hard task. Moreover, if we want to automate these deployments we need something that helps us in this tedious task. In this blog post, we will see how to create a Kubernetes Cluster and all of its required objects and deploying our Alexa Skill with Terraform using Azure Kubernetes Services.
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
- Terraform 12.x
- Azure Account
- Azure CLI
Terraform is a tool for building, changing, and versioning infrastructure safely and efficiently. Terraform can manage existing and popular service providers as well as custom in-house solutions.
Configuration files describe to Terraform the components needed to run a single application or your entire datacenter. Terraform generates an execution plan describing what it will do to reach the desired state, and then executes it to build the described infrastructure. As the configuration changes, Terraform is able to determine what changed and create incremental execution plans which can be applied.
The infrastructure Terraform can manage includes low-level components such as compute instances, storage, and networking, as well as high-level components such as DNS entries, SaaS features, etc.
After the brief overview of Terraform, we are going to explaining all the terraform files and its objects that we are going to use to deploy de cluster and our Alexa Skill. You can find all the files related to this deployment in
A provider is responsible for understanding API interactions and exposing resources. Most of the available providers correspond to one cloud or on-premises infrastructure platform and offers resource types that correspond to each of the features of that platform.
For the Azure Kubernetes Service, we will use the
azurerm provider. This provider allow us to create all Azure objects that we need to create our Alexa Skill Stack:
As we are going to deploy Helm Charts, it will be required to have the
Once the Private cloud Network has been created, we can create the cluster that will use that VPC. For that, we need to use the
Once the Resource Group has been created, we can create the cluster that will use that RG. For that, we need to use the
All the resources and modules commented above are related to the Kubernetes cluster. Now it’s time to deploy our Alexa Skill starting with the
After that, we can proudly deploy our Alexa Skill Helm chart in our Kubernetes Cloud cluster:
We have provided some variables that you can modify easily in order to change the name of the app_id or the password of this Azure app. For that, you can modify the variables on
To create an Azure Service Principal using the
az cli and getting the password for that Service Principal. Terraform needs a Service Principal to create resources on your behalf. You can think of it as a user identity (login and password) with a specific role, and tightly controlled permissions to access your resources. It could have fine-grained permissions such as only to create virtual machines or read from a particular blob storage.
For that, we need to execute the following commands:
Deploying the Stack
In order to make a provider available on Terraform, we need to make a
terraform init, these commands download any plugins we need for our providers. After that, we have to execute
terraform plan. The terraform plan command is used to create an execution plan. It will not modify things in infrastructure. Terraform performs a refresh, unless explicitly disabled, and then determines what actions are necessary to achieve the desired state specified in the configuration files. This command is a convenient way to check whether the execution plan for a set of changes matches your expectations without making any changes to real resources or to the state. Then, we need to execute
terraform apply. The terraform apply command is used to apply the changes required to reach the desired state of the configuration. Terraform apply will also write data to the terraform.tfstate file. Once the application is completed, resources are immediately available.
Here you have the full command list:
After running the
terraform apply, we can take a look to Azure Kubernetes Service to see that our cluster now appears:
We need to wait like 10 minutes until the cluster is created. Once the cluster is created now we can see the full specifications:
After the cluster creation, Terraform will deploy all the Helm charts. Here you can see all the Kubernetes Pods deployed:
And here the Kubernetes Services and the external IP of the
nginx-ingress-controller. That IP is the one we are going to use to make Alexa requests:
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 at http://18.104.22.168. With Postman you can emulate any Alexa Request.
For example, you can test a
Destroy the Stack
If we want to remove all the stack created by Terraform, just run:
- Official Alexa Skills Kit Node.js SDK — The Official Node.js SDK Documentation
- Official Alexa Skills Kit Documentation — Official Alexa Skills Kit Documentation
- Official Express Adapter Documentation — Express Adapter Documentation
- Official Kind Documentation — Kind Documentation
- Official Kubernetes Documentation — Kubernetes Documentation
- Terraform AKS — Terraform AKS
- Terraform AKS Github — Terraform AKS GitHub
Now we have our Alexa Skill running in a Kubernetes Cluster of our cloud provider everything automated with Terraform and ready to use in our live Alexa Skills.
I hope this example project is useful to you.
You can find the code here.
That’s all folks!
Opinions expressed by DZone contributors are their own.