Deploy the telegraf-ds helm chart on Google Kubernetes Engine (GKE)
TypeScriptTo deploy the Telegraf DaemonSet (telegraf-ds) Helm chart on Google Kubernetes Engine (GKE), you'll need to follow these steps:
- Create a GKE Cluster: Define and create a GKE cluster in your Pulumi program.
- Install the Helm chart: Use the Helm package for Pulumi to install the Telegraf DaemonSet chart into your GKE cluster.
Below is a Pulumi program written in TypeScript that shows how to carry out these steps. The program assumes that you have already set up your GCP credentials and Pulumi configuration for the GCP project.
Detailed Program Explanation
1. Importing Necessary Modules: We start by importing the modules required for defining a GKE cluster and for working with Helm charts.
2. Creating a GKE Cluster: We use
gcp.container.Cluster
to create a new GKE cluster. This step includes specifying the project, region, and the configuration for the nodes.3. Installing the Helm chart: With the GKE cluster in place, we use the
Helm.chart
function to deploy the Telegraf DaemonSet Helm chart. We specify the chart's name, version, and the namespace where it should be deployed—if you don't specify a namespace, it will be deployed to the default namespace.4. Exporting the GKE Cluster's Name and Kubeconfig: As outputs, the program exports the cluster's name and kubeconfig. This allows you to interact with the cluster using
kubectl
after the deployment.Here is the program that automates this process:
import * as pulumi from '@pulumi/pulumi'; import * as gcp from '@pulumi/gcp'; import * as k8s from '@pulumi/kubernetes'; // Create a GKE cluster. const cluster = new gcp.container.Cluster('telegraf-cluster', { initialNodeCount: 1, nodeVersion: 'latest', minMasterVersion: 'latest', nodeConfig: { machineType: 'n1-standard-1', // Depending on the Telegraf plugins you intend to use, you may need to attach additional permissions. oauthScopes: [ "https://www.googleapis.com/auth/compute", "https://www.googleapis.com/auth/devstorage.read_only", "https://www.googleapis.com/auth/logging.write", "https://www.googleapis.com/auth/monitoring" ], }, }); // Export the Cluster name export const clusterName = cluster.name; // Export the Kubeconfig so that we can interact with the cluster through kubectl. export const kubeconfig = pulumi. all([cluster.name, cluster.endpoint, cluster.masterAuth]). apply(([name, endpoint, masterAuth]) => { const context = `${gcp.config.project}_${gcp.config.zone}_${name}`; return `apiVersion: v1 clusters: - cluster: certificate-authority-data: ${masterAuth.clusterCaCertificate} server: https://${endpoint} name: ${context} contexts: - context: cluster: ${context} user: ${context} name: ${context} current-context: ${context} kind: Config preferences: {} users: - name: ${context} user: auth-provider: config: cmd-args: config config-helper --format=json cmd-path: gcloud expiry-key: '{.credential.token_expiry}' token-key: '{.credential.access_token}' name: gcp `; }); // Set up the Helm chart for Telegraf DaemonSet const telegrafRelease = new k8s.helm.v3.Release('telegraf-ds', { name: 'telegraf', chart: 'stable/telegraf-ds', version: '1.7.22', // specify the version you'd like to deploy namespace: 'monitoring', // values: {}, // you can define additional configuration values }, { provider: new k8s.Provider('k8s-provider', { kubeconfig: kubeconfig }) }); // Export the Helm release name export const telegrafReleaseName = telegrafRelease.name;
In the example, a new GKE cluster with one node is created. Next, a Helm chart for Telegraf DaemonSet is deployed in the
monitoring
namespace. Make sure that the Helm chart version specified (1.7.22
in this case) is available or change it according to the chart version you need.Deploying the Program
Assuming you have the Pulumi CLI set up, you would run the following command to deploy the program:
pulumi up
This would create the GKE cluster and deploy the Telegraf DaemonSet Helm chart within it. If this is your first time running Pulumi, you will be prompted to create a new stack, which represents an isolated environment for your project.
If you want to manage and observe your Kubernetes resources using the Pulumi console, you can define a stack output for the Helm release.
Remember, you should have
gcloud
CLI installed and authenticated, andHelm
CLI available for Pulumi to deploy the resources correctly.