Deploy the mssql-linux helm chart on Google Kubernetes Engine (GKE)
TypeScriptTo deploy the
mssql-linux
Helm chart on Google Kubernetes Engine (GKE), you'll need to follow a few steps. First, a GKE cluster is created. Second, Helm is used to deploy the chart onto the cluster. The Pulumi program below is split into two main parts: the creation of the GKE cluster and the deployment of the Helm chart.Before you proceed with the code, ensure you have the following prerequisites:
- Pulumi CLI installed and configured with a Pulumi account.
- Google Cloud SDK installed and configured with the necessary credentials.
- Kubernetes command-line tool (
kubectl
) installed. - Helm v3 installed.
Our first step is to create a GKE cluster. We use
google-native.container/v1.Cluster
to provision the GKE cluster.Next, we deploy the
mssql-linux
Helm chart. To do this, we'll utilize thehelm.v3.Chart
resource that Pulumi provides for deploying Helm charts.Here is the full Pulumi program in TypeScript:
import * as gcp from "@pulumi/gcp"; import * as k8s from "@pulumi/kubernetes"; import * as pulumi from "@pulumi/pulumi"; // Create a GKE cluster const cluster = new gcp.container.Cluster("cluster", { initialNodeCount: 2, minMasterVersion: "latest", nodeVersion: "latest", location: "us-central1-a", // You should choose a region that's closest to you or your users nodeConfig: { machineType: "n1-standard-1", // Adjust the machine type depending on your needs 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; // Obtain the Kubeconfig for the cluster // Secure way to handle kubeconfig 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 `; }); // Create a Kubernetes provider instance that uses our cluster from above. const k8sProvider = new k8s.Provider("gkeK8s", { kubeconfig: kubeconfig, }); // Deploy mssql-linux using a Helm Chart const mssqlLinuxChart = new k8s.helm.v3.Chart("mssql-linux", { chart: "mssql-linux", version: "0.11.0", // Use the version that suits your needs fetchOpts:{ repo: "https://example.com/helm/charts", // Replace with the correct helm chart repository }, values: { acceptLicense: "Y", edition: "Developer", // Choose the edition that suits your needs // Add additional custom values }, }, { provider: k8sProvider }); // Export the Helm chart deployment name export const mssqlLinuxChartName = mssqlLinuxChart.releaseName;
Explanation of the program:
-
The first part of the program uses the
@pulumi/gcp
package to create a GKE cluster. TheinitialNodeCount
,minMasterVersion
,nodeVersion
,location
, andnodeConfig
parameters are set for the cluster, which are customizable based on the requirements. -
The kubeconfig is generated dynamically using the cluster details, relying on
gcloud
as the command-line tool for authentication. -
A Pulumi Kubernetes provider is then set up, and the kubeconfig obtained in the previous step is used as its configuration.
-
The Helm chart
mssql-linux
is deployed using the@pulumi/kubernetes
package. Thechart
,version
, andfetchOpts.repo
parameters are set to specify the Helm chart repository and version. Thevalues
object in the chart configuration can be adjusted to set any custom values needed for the MSSQL server. -
At the end, we export two values: the name of the GKE cluster and the release name of the Helm chart deployment, which can be used for further commands like port-forwarding or getting deployment status with
kubectl
.
Remember to replace placeholder values like
"https://example.com/helm/charts"
with the actual values that apply to the chart you want to deploy. Additionally, consult the Helm chart documentation formssql-linux
for the specific values you can set.Running this Pulumi program would create a fully configured GKE cluster and deploy the MSSQL server within it.