Shipa Blog

Latest updates on our products, plus helpful articles relating to Kubernetes, container security, microservices and more

Deploying microservice apps on Kubernetes using Terraform

Terraform is a popular choice among DevOps and Platform Engineering teams as engineers can use the tool to quickly spin up environments directly from their CI/CD pipelines.

Application Challenges When Using Terraform

As teams leverage Terraform to build a standardized Kubernetes cluster management process, they now face the question: How can we effectively leverage Terraform to enable developers to deploy and manage their applications on Kubernetes?

The challenges they face to achieve this are:

  • Terraform leverages Helm for deployments on Kubernetes. Given the complexity, developers will have to rely on the DevOps team to create, maintain, and update Terraform templates.
  • Once applications are deployed, Developers have difficulty having visibility over the status of their applications, dependencies, and ultimately, be able to manage them.

Application as Code for Terraform

By using Shipa with Terraform, you:

  • Abstract Terraform away from Helm, making it easy for developers to build and maintain their own Terraform templates focused on the application rather than infrastructure.
  • Give developers an application portal where they can easily manage their applications without spending time trying to understand how to support apps on Kubernetes.

With such an approach, you free up developers to focus on the application and the DevOps team to continue advancing the further adoption of Kubernetes in your organization.

Deploying a Sample Application

Requirements:

  • Kubernetes Cluster: See the list of supported K8s clusters here
  • Shipa Cloud: You can create a free account here
  • Shipa Policy Framework: Find more information on how to create a policy framework here
  • Bind Policy Framework: Details of how to bind a Shipa policy framework to your K8s cluster can be found here
  • Shipa CLI: You can download the Shipa CLI here

With the requirements above addressed, let’s see the definition of our sample application:

terraform {
  required_providers {
    shipa = {
      version = "0.0.3"
      source = "shipa-corp/shipa"
    }
  }
}

provider "shipa" {
  host = "htt://target.shipa.cloud:8080"
  token = "<your-shipa-token>"
}

resource "shipa_app" "tf-app" {
  app {
    name = "terraform-app"
    teamowner = "shipa-team"
    framework = "prod"
  }
}

resource "shipa_app_deploy" "tf-app-deploy" {
  depends_on = [shipa_app.tf-app]
  app = shipa_app.tf-app.app[0].name
  deploy {
    image = "ghcr.io/podtato-head/podtatoserver:v0.1.1"
  }
}

Save the file as app-deploy.tf

Lets breakdown our application definition:

  • It loads the Shipa provider for Terraform
  • The second part connects Terraform to your Shipa Cloud account. To find your Shipa token, just use the command shipa token show while logged in through the Shipa CLI
  • It creates the application on Shipa, binding it to your existing Shipa policy framework. Make sure you change that to reflect the name of the framework you created before.
  • The last part of the definition deploys a Docker image to the application you created in the previous step.

You can find further information on how to define environment variables and more here.

With the file saved, just run:

terraform init

Result of the terraform init command

This will initialize the working directory. Run the command above in the same directory where you created the app-deploy.tf file. 

Once initialized, run the command below:

terraform apply

Result of the terraform apply command

Once Terraform apply command is complete, you can see your application through the Shipa Cloud dashboard:

Shipa Cloud dashboard

By clicking on the application name, you can then see detailed information about application ownership, monitoring metrics, audit, security, dependencies, and more:

Application dependency map

Conclusion

Implementing Shipa in conjunction with Terraform enables developer experience and self-service while enabling your DevOps team to continue advancing the adoption of microservices and Kubernetes.

Join our community, ask questions, and send suggestions on topics we should cover next.