Use this template to:
This repo has the following folder structure:
modules: This folder contains stand alone modules that are relevant to the main template.
samples: This repository features two sample applications that generate metrics and limited logs that are pushed to IBM Cloud Monitoring and Log Analysis instances.
You must have a Pay-as-You-Go account in IBM Cloud™ to follow the steps in this repository to create resources. Since the costs for these resources will vary, use the Pricing Calculator to generate a cost estimate based on your projected usage.
Some of the services listed above offer a limited free tier, i.e. IBM Cloud Monitoring, IBM Cloud Log Analysis, and IBM Cloud Activity Trackler which you can use for testing and will work perfectly for our example application. Please note the implication of using the free services as some will be deleted automatically after 30 days.
If you deploy paid services, make sure to delete them when they are no longer required in order to not incur charges in your account.
Before you start, make sure to have all the items completed below as the template requires them.
Determine which region you want to use. The value we will need is in the Region column and between the parentheses,i.e jp-tok, us-south, etc...
This template requires an IBM Cloud API Key that will run with your permissions. Either create a new API key for use by this template or provide an existing one. An API key is a unique code that is passed to an API to identify the application or user that is calling it. To prevent malicious use of an API, you can use API keys to track and control how that API is used. For more information about API keys and how to create them, see Understanding API keys and Managing user API keys.
Activity Tracker is a service that allows only one instance per IBM Cloud region, this template does not create an Activity Tracker instance for you, it requires instead that you provide the name of an existing Activity Tracker instance. If you don't have one, follow these steps to create one: https://cloud.ibm.com/docs/activity-tracker?topic=activity-tracker-provision
Follow the steps outlined in the Kubernetes Service - Creating clusters topic to create a Kubernetes cluster. You should create a cluster in a VPC, as this template only supports VPC based clusters. Once the instance is created, save the cluster ID for quick reference and proceed to the steps described below. To obtain the cluster ID
Note 1: If you are using an existing cluster in which you have already deployed the monitoring agent, you must import the configuration of the agent deployment into your Terraform state, however please note that when you run a Terraform destroy the agent will be removed from the cluster.
Note 2: To obtain the cluster ID either use the CLI:
ibmcloud ks clusters
or the Kubernetes console >> Overview page.Note 3: If using an existing cluster, ensure the VPC subnets have a Public Gateway attached as this is required to install the Logging and Monitoring agents.
Note 4: If you do not already have a VPC Kubernetes cluster, you can also use the module found under modules/vpc to create a VPC and cluster. Follow the steps found in the modules/vpc/README.md.
If you are running on a Windows operating system install Git, this template includes a shell script written in Bash and Git when installed on Windows will also include Git Bash that you can use to run the script.
Install IBM Cloud CLI and required plugins:
Setup the Terraform CLI and the latest IBM Cloud Provider plug-in
This template will configure monitoring Teams integrated with IAM, as the owner of the instance, you will have full visibility into all of the teams that you create, i.e. you can switch to them and see what other users would see if they were added to those teams. However, in order to get a more immersive experience, you need to have at minimum two additional users invited to the IBM Cloud account in which you will be creating these resources, follow the steps outlined below to invite users to your account:
observability-teams
directory.Build and push the Docker image to the IBM Cloud container registry.
From a terminal window identify your IBM Cloud Container Registry hostname and save it for later use:
a. Log in to the Container Registry service:
ibmcloud cr login
b. Obtain the hostname:
ibmcloud cr region
Pick one of your existing registry namespaces or create a new one. To list existing namespaces, use:
ibmcloud cr namespaces
To add a new namespace, use:
ibmcloud cr namespace-add <your_registry_namespace>
samples/go-app
directory.docker build -t <your_region_registry>/<your_registry_namespace>/metrics-go-app .
docker image push <your_region_registry>/<your_registry_namespace>/metrics-go-app
samples/node-app
directory.docker build -t <your_region_registry>/<your_registry_namespace>/metrics-node-app .
docker image push <your_region_registry>/<your_registry_namespace>/metrics-node-app
export TF_LOG=TRACE
export TF_LOG_PATH=./config/config.log
terraform init
Modify the config/config.tfvars to your own values.
ibmcloud_api_key = "<your_ibm_cloud_api_key>"
resource_group = "<your_resource_group>"
activity_tracker_resource_group = "<resource_group_for_existing_activity_tracker_instance>"
cluster_resource_group = "<resource_group_for_kubernetes_cluster>"
region = "<your_region>"
resources_prefix = "<used_to_prefix_resources>"
cluster_id = "<your_kubernetes_cluster_id>"
go_image_repository = "<location_of_go_app_container_image>"
node_image_repository = "<location_of_node_app_container_image>"
team_go_members = ["<email_address_of_an_invited_user_to_your_ibm_cloud_account>"]
team_node_members = ["<email_address_of_an_invited_user_to_your_ibm_cloud_account>"]
activity_tracker_instance_name = "<name of existing activity tracker instance>"
activity_tracker_service_key = "Your service key can be generated or retrieved from the LogDNA web application. Navigate to Settings > Organization > API Keys"
logging_service_key = ""
Note: The template expects the Kubernetes cluster to have been created in a VPC Infrastructure.
Note: Both
activity_tracker_resource_group
andcluster_resource_group
are empty values which will cause the template to use the value supplied forresource_group
, if you require it specifiy a different value for each.
terraform plan -var-file=config/config.tfvars -state=config/config.tfstate -out=config/config.plan
Apply terraform plan by specifying the location of plan file:
terraform apply -state-out=config/config.tfstate config/config.plan
Note: If you plan on building for multiple environments or regions, you may want to maintain separate state files for each of these environments, you can use a different
config
directory for each environment or region. Another solution is to use Terraform workspaces which is discussed in our Plan, create and update deployment environments tutorial.
logging_service_key
variable of your config/config.tfvars
file.activity_tracker_service_key
variable of your config/config.tfvars
file.terraform plan -var-file=config/config.tfvars -state=config/config.tfstate -out=config/config.plan
terraform apply -state-out=config/config.tfstate config/config.plan
Destroy resource when done by specifying the location of variable files, and state file:
terraform destroy -var-file=config/config.tfvars -state=config/config.tfstate -refresh
Note: This is not reversible all resources stored in the Terraform state will be removed.
Terraform will not delete the group that was created in Activity Tracker, you will need to delete this group manualy. Follow the steps outlined in the documentation here: https://cloud.ibm.com/docs/activity-tracker?topic=activity-tracker-group_data_access#groups_data_access_editing
Importing the namespace in which the monitoring agent was deployed:
terraform import -var-file=config/config.tfvars -state-out=config/config.tfstate kubernetes_namespace.ibm_observe ibm-observe
Importing the service account for the monitoring agent:
terraform import -var-file=config/config.tfvars -state-out=config/config.tfstate kubernetes_service_account.sysdig_agent ibm-observe/sysdig-agent
Importing the cluster role and cluster role binding:
terraform import -var-file=config/config.tfvars -state-out=config/config.tfstate kubernetes_cluster_role.sysdig_agent sysdig-agent
terraform import -var-file=config/config.tfvars -state-out=config/config.tfstate kubernetes_cluster_role_binding.sysdig_agent sysdig-agent
Tutorial: Analyze logs and monitor application health.
Tutorial: Plan, create and update deployment environments
See License.txt for license information.