Deploy the crane helm chart on Google Kubernetes Engine (GKE)
TypeScriptDeploying the Crane Helm chart on Google Kubernetes Engine (GKE) involves several steps:
-
Provision a GKE Cluster: First, you'd need to create a Kubernetes cluster in GKE where the Helm chart will be deployed. You would use the
google-native.container/v1.Cluster
resource for this purpose. -
Install Helm: Helm is a package manager for Kubernetes that allows you to package, configure, and deploy applications onto your clusters.
-
Deploy the Helm Chart: Finally, you'd deploy the Helm chart to your GKE cluster using the
kubernetes.helm.sh/v3.Release
resource, which represents a Helm chart release in Kubernetes.
Let's start by implementing the GKE cluster creation:
GKE Cluster Creation
You'll need to provision a cluster using the
google-native.container/v1.Cluster
resource. The following program describes a basic cluster setup. You would usually customize the number of nodes, machine type, and other configurations according to your needs. However, for simplicity, we'll go with the defaults in this example.After creating the cluster, you'll use the
kubernetes.helm.sh/v3.Release
resource from the Pulumi Kubernetes provider to deploy the Helm chart to your cluster.Here is the full Pulumi program written in TypeScript that achieves this:
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("crane-gke-cluster", { // Define the initial node count and the type of machine to use initialNodeCount: 2, minMasterVersion: 'latest', nodeVersion: 'latest', nodeConfig: { machineType: "n1-standard-1", 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 Kubeconfig for the GKE cluster 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 a Kubernetes provider using the GKE cluster info const k8sProvider = new k8s.Provider("k8s-provider", { kubeconfig: kubeconfig, }); // Deploy the Crane Helm chart into the GKE cluster using the Kubernetes provider const craneHelmChart = new k8s.helm.v3.Chart("crane-helm-chart", { repo: "crane-repo", // Replace with the actual Helm repo name chart: "crane", // Replace with the actual Helm chart name version: "1.0.0", // Specify the chart version // You can define values for the Helm chart in the `values` parameter if necessary }, { provider: k8sProvider }); // Export the Crane Helm chart status export const craneHelmChartStatus = craneHelmChart.status;
Explanation:
-
GKE Cluster Provisioning:
gcp.container.Cluster
creates a new managed Kubernetes cluster in GCP. TheinitialNodeCount
parameter specifies the number of worker nodes,minMasterVersion
andnodeVersion
select the desired Kubernetes versions, andnodeConfig
describes the configuration of the worker nodes, such as machine type and access scopes. -
Kubeconfig: This exports the Kubernetes configuration that
kubectl
or other Kubernetes tools can use to access your newly created cluster. -
Kubernetes Provider:
k8s.Provider
sets up a Pulumi Kubernetes provider that uses the generated Kubeconfig, essentially linking Pulumi to your GKE cluster for further operations. -
Crane Helm Chart Deployment:
k8s.helm.v3.Chart
represents a Helm chart release in Kubernetes. Replace therepo
andchart
with the actual repository and chart names for Crane.version
specifies the chart version to deploy. Thevalues
parameter, if given, can contain the configuration values for the chart.
Remember to replace placeholders like
crane-repo
andcrane
with actual values from the Helm repository that contains the Crane chart. After defining thekubeconfig
, this file can typically be used withkubectl
or other Kubernetes tooling for interacting with the cluster. Ensure that you have Helm installed and properly configured to access the required repositories.To deploy and manage cloud resources with Pulumi, you'll need to install the Pulumi CLI, authenticate with your cloud provider, and then run
pulumi up
to create the resources as per the program. Check the GKE and Pulumi documentation for any additional setup you might need.-