1. Deploy the castai-agent helm chart on Google Kubernetes Engine (GKE)


    Deploying a Helm chart to a Kubernetes cluster, including a Google Kubernetes Engine (GKE) cluster, usually involves several steps. First, you'll need a Kubernetes cluster running. For our purpose, we'll create a GKE cluster using Pulumi. Once the cluster is up, you'll configure kubectl to connect to the cluster, and then you can deploy the Helm chart to it.

    In this guide, I'll walk you through how to:

    1. Define a GKE cluster using Pulumi.
    2. Configure kubectl to connect to the newly created cluster.
    3. Install the castai-agent Helm chart onto the cluster.

    The @pulumi/gcp Pulumi package will be used to create the GKE cluster and the @pulumi/kubernetes package to deploy the Helm chart.

    Here's a Pulumi program written in TypeScript that accomplishes these steps:

    import * as pulumi from "@pulumi/pulumi"; import * as gcp from "@pulumi/gcp"; import * as k8s from "@pulumi/kubernetes"; // Initialize a Pulumi project. const projectName = pulumi.getProject(); // Configure the GKE cluster const cluster = new gcp.container.Cluster("castai-gke-cluster", { initialNodeCount: 1, nodeVersion: "latest", minMasterVersion: "latest", location: "us-central1-c", }); // Export the cluster name export const clusterName = cluster.name; // Obtain the `kubeconfig` from the cluster which is used by // `kubectl` and other Kubernetes clients to connect to the cluster 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 `; }); // Export the kubeconfig. export const kubeConfig = kubeconfig; // Create a Kubernetes provider that uses our cluster kubeconfig. const k8sProvider = new k8s.Provider("gkeK8s", { kubeconfig }); // Deploy the castai-agent helm chart into the Kubernetes cluster const castaiHelmChart = new k8s.helm.v3.Chart("castai-agent-chart", { chart: "castai-agent", version: "0.1.0", // replace with the desired chart version fetchOpts: { repo: "https://charts.cast.ai", }, }, { provider: k8sProvider }); // Export the status of the Helm release export const helmChartStatus = castaiHelmChart.status;

    In this code block:

    • We create a new GKE cluster with an initial node count of just one minimally-sized VM, which is suitable for learning and small workloads.
    • We retrieve the kubeconfig file that will allow kubectl to communicate with our new GKE cluster.
    • We create a new instance of the @pulumi/kubernetes Provider pointing at our newly created cluster.
    • We deploy the castai-agent Helm chart to our cluster using this provider.

    The chart parameter specifies the name of the Helm chart (castai-agent), and version is where you would specify the version of the Helm chart you wish to deploy. Lastly, the fetchOpts are used to point Pulumi at the Helm repository hosting the castai-agent chart.

    Make sure you replace version with the correct version of the Helm chart you want to deploy.

    To run this Pulumi program:

    1. Ensure you have Pulumi and the Google Cloud SDK installed and configured on your system.
    2. Create a new directory and initialize a new Pulumi project within that directory.
    3. Install the required Pulumi packages by running npm install @pulumi/pulumi @pulumi/gcp @pulumi/kubernetes.
    4. Place the TypeScript code from above into an index.ts file in the new directory.
    5. Run pulumi up to create the GKE cluster and deploy the Helm chart.

    Pulumi will then execute the program, display a preview of the actions to be taken, and prompt you to proceed with the deployment.

    Please remember Kubernetes clusters can incur costs in the cloud provider, so be sure to delete the resources with pulumi destroy when you're done experimenting to avoid unnecessary charges.