Deploy the tyk-data-plane helm chart on Google Kubernetes Engine (GKE)
TypeScriptTo deploy the
tyk-data-plane
Helm chart on Google Kubernetes Engine (GKE) using Pulumi, you will need to perform the following steps:- Set up a GKE cluster.
- Install the Helm chart on the cluster.
Below is a Pulumi program written in TypeScript that accomplishes these tasks.
Firstly, we will create a GKE cluster by using the
gcp.container.Cluster
resource. Then, we will deploy thetyk-data-plane
Helm chart to the cluster using thepulumi-kubernetes
package that allows Pulumi to interact with Kubernetes' resources, including Helm charts.Make sure you have Pulumi installed and set up with the necessary GCP credentials. Also, ensure that
kubectl
is configured to interact with your GKE cluster.Here is the complete program:
import * as pulumi from "@pulumi/pulumi"; import * as gcp from "@pulumi/gcp"; import * as k8s from "@pulumi/kubernetes"; // Step 1: Create a GKE cluster const cluster = new gcp.container.Cluster("tyk-gke-cluster", { initialNodeCount: 2, nodeConfig: { machineType: "n1-standard-1", // or any other desired machine type }, }); // Step 2: Deploy the tyk-data-plane Helm chart on GKE // Export the Cluster name export const clusterName = cluster.name; // Manufacture a Kubeconfig string that we can use to interact with the cluster externally const kubeconfig = pulumi. all([ cluster.name, cluster.endpoint, cluster.masterAuth ]). apply(([ name, endpoint, auth ]) => { const context = `${gcp.config.project}_${gcp.config.zone}_${name}`; return `apiVersion: v1 clusters: - cluster: certificate-authority-data: ${auth.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 `; }); // Create a Kubernetes Provider using the Kubeconfig from the newly created GKE Cluster const provider = new k8s.Provider("tyk-k8s-provider", { kubeconfig: kubeconfig, }); // Deploy the tyk-data-plane Helm chart const tykDataPlaneChart = new k8s.helm.v3.Chart("tyk-data-plane-chart", { chart: "tyk-headless", // This is the name of the chart in the Helm registry namespace: "default", // Specify the namespace if not 'default' // You can add any additional Chart values here values: { // Values to configure Tyk Data Plane }, }, { provider: provider }); // Make sure to associate the Helm chart with the Kubernetes provider // Export the Kubeconfig to access the cluster with kubectl export const kubeConfigOutput = kubeconfig;
Explanation:
- We import the required Pulumi packages for GCP (
@pulumi/gcp
) and Kubernetes (@pulumi/kubernetes
). - We create a new GKE cluster with an initial node count and a specific machine type for the nodes.
- We generate a kubeconfig file for external interaction with the cluster, which is necessary for the Kubernetes provider to deploy resources to this cluster.
- We create a Kubernetes provider and associate it with the generated kubeconfig from our GKE cluster.
- We deploy the
tyk-data-plane
Helm chart using thek8s.helm.v3.Chart
resource. The Helm chart is referenced by name (tyk-headless
). You can override the default values by including avalues
object with the necessary configurations. - We export the
kubeconfig
content, so you can access the cluster usingkubectl
and interact with your deployment.
To use this Pulumi program, save the code into a file (e.g.,
index.ts
), runpulumi up
, and follow the prompts by Pulumi to deploy the resources. After the deployment, the exportedkubeConfigOutput
will be available in your Pulumi stack outputs, which you can use to set up your localkubectl
config.