index.ts


Overview

The [index.ts](/projects/291/68798) file serves as the main entry point for deploying a comprehensive Kubernetes monitoring stack tailored for the ShapeShift Unchained platform. Utilizing Pulumi's infrastructure-as-code framework, it provisions a fully integrated observability solution combining Prometheus, Grafana, Alertmanager, and supporting components via the popular `kube-prometheus-stack` Helm chart.

This deployment includes customized storage configurations, dashboard provisioning, alerting rules, and external access setup through Grafana Ingress. The file orchestrates the infrastructure resources necessary to gather, visualize, and alert on metrics from blockchain coinstacks and their Kubernetes environments.


Detailed Explanation

Exported Async Function (Default Export)

export = async (): Promise<Outputs> => { ... }

Internal Workflow and Logic

  1. Configuration Loading

    const { kubeconfig, domain, additionalDomain } = await getConfig()
    
    • Imports runtime configuration values:

      • kubeconfig: Kubernetes cluster access credentials.

      • domain: Primary domain for services.

      • additionalDomain: Optional secondary domain for multi-domain support.

  2. Namespace and Provider Setup

    const name = 'unchained'
    const namespace = `${name}-monitoring`
    const provider = new k8s.Provider('kube-provider', { kubeconfig })
    
    • Defines consistent naming for resources.

    • Creates a Pulumi Kubernetes provider instance to interact with the target cluster.

  3. Helm Chart Deployment: kube-prometheus-stack

    new k8s.helm.v3.Release(
      name,
      {
        name,
        chart: 'kube-prometheus-stack',
        version: '52.1.0',
        repositoryOpts: { repo: 'https://prometheus-community.github.io/helm-charts' },
        namespace,
        values: { ... } // extensive custom values object
      },
      { provider }
    )
    
    • Deploys the complete Prometheus monitoring stack via Helm.

    • Specifies the chart version and repository.

    • Targets the dedicated namespace ${name}-monitoring.

    • Customizes various components via values:

      • Prometheus: retention, storage with AWS EBS gp3 tuning.

      • Grafana: admin password, persistence, dashboards, GitHub OAuth for authentication.

      • Alertmanager: storage, custom configuration loaded from files, templating for Discord notifications.

      • Additional Prometheus Rules: loaded from JSON file.

      • Kube-State-Metrics: label allowlists for metrics filtering.

    • Uses readFileSync to load local dashboard JSON and alerting config files, injecting environment variables into alertmanager config dynamically.

  4. Grafana Ingress Deployment

    new grafana.Ingress(
      name,
      {
        namespace,
        domain,
        additionalDomain,
      },
      { provider }
    )
    
    • Instantiates a Grafana Ingress resource defined in the grafana module.

    • This manages external access routing to Grafana, including TLS and domain configuration.

  5. Outputs

    • Returns an empty outputs object for now. Can be extended to export resource information or endpoints.


Important Implementation Details


Interaction with Other System Components


Usage Example

This file is not directly invoked by users but run by Pulumi during deployment:

pulumi up

Pulumi executes the exported async function, which applies the Helm release and ingress resources defined herein, deploying the full monitoring stack into the Kubernetes cluster.


Mermaid Diagram: File Structure and Workflow

flowchart TD
  Start[Pulumi Entry Point]
  Start --> Config[getConfig()]
  Config --> K8sProvider[Kubernetes Provider]
  K8sProvider --> HelmRelease[k8s.helm.v3.Release (kube-prometheus-stack)]
  HelmRelease --> Prometheus[Prometheus Component]
  HelmRelease --> Grafana[Grafana Component]
  HelmRelease --> Alertmanager[Alertmanager Component]
  HelmRelease --> KubeStateMetrics[Kube-State-Metrics]
  HelmRelease --> Dashboards[Load Dashboards & Rules]
  HelmRelease --> Storage[Persistent Volume Claims]
  K8sProvider --> GrafanaIngress[grafana.Ingress]
  GrafanaIngress --> GrafanaDashboard[Expose Grafana UI]
  HelmRelease --> Outputs[Return Outputs Object]

Summary

The [index.ts](/projects/291/68798) file is the orchestrator for deploying a highly customized Prometheus and Grafana monitoring stack into a Kubernetes cluster using Pulumi. It integrates:

This deployment script is a cornerstone for enabling observability, alerting, and operational insights into the ShapeShift Unchained blockchain infrastructure.


Additional Notes


End of Documentation for index.ts