1. Answers
  2. Deploy The Csi-driver-nfs Helm Chart On TypeScriptogle Kubernetes Engine (GKE)

Deploy the Csi-Driver-Nfs Helm Chart on TypeScriptogle Kubernetes Engine (GKE)

Introduction

In this guide, we will deploy the csi-driver-nfs Helm chart on a Google Kubernetes Engine (GKE) cluster using Pulumi with TypeScript. The key services involved include GKE for the Kubernetes cluster and Helm for managing the deployment of the csi-driver-nfs chart.

Step-by-Step Explanation

Step 1: Set Up Pulumi and Install Dependencies

  1. Ensure you have Pulumi CLI installed. If not, follow the installation guide.
  2. Create a new Pulumi project:
    pulumi new typescript
    
  3. Install the necessary Pulumi packages:
    npm install @pulumi/pulumi @pulumi/gcp @pulumi/kubernetes
    

Step 2: Configure GKE Cluster

  1. Define the GKE cluster configuration in your index.ts file:
    import * as gcp from "@pulumi/gcp";
    import * as k8s from "@pulumi/kubernetes";
    
    const cluster = new gcp.container.Cluster("gke-cluster", {
        initialNodeCount: 3,
        minMasterVersion: "1.21",
        nodeVersion: "1.21",
        nodeConfig: {
            machineType: "n1-standard-1",
            oauthScopes: [
                "https://www.googleapis.com/auth/cloud-platform",
            ],
        },
    });
    
    const kubeconfig = pulumi.interpolate`apiVersion: v1
    

kind: Config clusters:

  • cluster: certificate-authority-data: ${cluster.masterAuth.clusterCaCertificate} server: https://${cluster.endpoint} name: gke-cluster contexts:

  • context: cluster: gke-cluster user: gke-cluster name: gke-cluster current-context: gke-cluster kind: Config preferences: {} users:

  • name: gke-cluster user: auth-provider: config: access-token: ${gcp.config.accessToken} cmd-args: config config-helper –format=json cmd-path: gcloud expiry: ${gcp.config.tokenExpiry} expiry-key: ‘{.credential.token_expiry}’ token-key: ‘{.credential.access_token}’ name: gcp `;

    export const clusterName = cluster.name; export const kubeconfig = kubeconfig;

Step 3: Deploy the csi-driver-nfs Helm Chart

  1. Define the Helm chart deployment in your index.ts file:
    const provider = new k8s.Provider("k8s-provider", {
        kubeconfig: kubeconfig,
    });
    
    const nfsDriver = new k8s.helm.v3.Chart("csi-driver-nfs", {
        chart: "csi-driver-nfs",
        version: "latest",
        fetchOpts: {
            repo: "https://kubernetes-sigs.github.io/nfs-ganesha-server-and-external-provisioner/",
        },
    }, { provider });
    

Step 4: Deploy the Stack

  1. Run the Pulumi commands to deploy the stack:
    pulumi up
    

Summary

By following these steps, you have successfully deployed the csi-driver-nfs Helm chart on a GKE cluster using Pulumi with TypeScript. This setup ensures that your Kubernetes cluster is equipped with the NFS CSI driver for managing NFS volumes efficiently.

Full Code Example

import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
import * as k8s from "@pulumi/kubernetes";

const cluster = new gcp.container.Cluster("gke-cluster", {
    initialNodeCount: 3,
    minMasterVersion: "1.21",
    nodeVersion: "1.21",
    nodeConfig: {
        machineType: "n1-standard-1",
        oauthScopes: [
            "https://www.googleapis.com/auth/cloud-platform",
        ],
    },
});

const kubeconfig = pulumi.interpolate\`apiVersion: v1
kind: Config
clusters:
- cluster:
    certificate-authority-data: \${cluster.masterAuth.clusterCaCertificate}
    server: https://\${cluster.endpoint}
  name: gke-cluster
contexts:
- context:
    cluster: gke-cluster
    user: gke-cluster
  name: gke-cluster
current-context: gke-cluster
kind: Config
preferences: {}
users:
- name: gke-cluster
  user:
    auth-provider:
      config:
        access-token: \${gcp.config.accessToken}
        cmd-args: config config-helper --format=json
        cmd-path: gcloud
        expiry: \${gcp.config.accessToken}
        expiry-key: '{.credential.token_expiry}'
        token-key: '{.credential.access_token}'
      name: gcp
\`;

export const clusterName = cluster.name;
export const kubeconfigOutput = kubeconfig;

const provider = new k8s.Provider("k8s-provider", {
    kubeconfig: kubeconfig,
});

const nfsDriver = new k8s.helm.v3.Chart("csi-driver-nfs", {
    chart: "csi-driver-nfs",
    version: "latest",
    fetchOpts: {
        repo: "https://kubernetes-sigs.github.io/nfs-ganesha-server-and-external-provisioner/",
    },
}, { provider });

Deploy this code

Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.

Sign up

New to Pulumi?

Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.

Sign up