1. Deploy the plex-media-server helm chart on Google Kubernetes Engine (GKE)


    Deploying the Plex Media Server on Google Kubernetes Engine (GKE) can be a straightforward process with Pulumi using the harness package. Pulumi allows you to manage Kubernetes resources in a declarative way, using code. Below, you'll find a program written in TypeScript that sets up a GKE cluster and deploys the Plex Media Server using a Helm chart.

    To begin, we'll set up the necessary infrastructure and configurations:

    1. GKE Cluster: We need a Kubernetes cluster on GKE where our Plex Media Server will run. We'll create this cluster using Pulumi's GKE resources.
    2. Helm Chart Deployment: Once we have our Kubernetes cluster, we will deploy the Plex Media Server Helm chart to the cluster.

    Here is the Pulumi program that accomplishes these steps:

    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("plex-media-cluster", { initialNodeCount: 2, nodeVersion: "latest", minMasterVersion: "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 Cluster name export const clusterName = cluster.name; // Export the Kubeconfig to access the cluster with kubectl 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 `; }); // Create a Kubernetes provider instance that uses our cluster from above. const k8sProvider = new k8s.Provider("gkeK8s", { kubeconfig: kubeconfig, }); // Deploy Plex Media Server Helm chart to the cluster const plexChart = new k8s.helm.v3.Chart("plex-media-server", { chart: "plex-media-server", version: "1.1.0", // specify the exact chart version fetchOpts:{ repo: "https://k8s-at-home.com/charts/", }, values: { claimToken: "INSERT_YOUR_CLAIM_TOKEN_HERE", // Replace with your Plex claim token persistence: { config: { enabled: true, size: "10Gi", }, }, }, }, { provider: k8sProvider }); // Export the Helm chart resources created export const plexDeploymentName = plexChart.getResource("v1/Service", "plex-media-server");


    • First, we import the necessary Pulumi packages for GCP, Kubernetes, and basic Pulumi functions.
    • We define a GKE cluster with a specific node count and machine type, suitable for running the Plex server.
    • We export the GKE cluster name and the kubeconfig, which provides the credentials to interact with the cluster via kubectl.
    • Then, we set up a Kubernetes provider, k8sProvider, which knows how to communicate with our GKE cluster using the generated kubeconfig.
    • With the Kubernetes provider in place, we deploy the Plex Media Server Helm chart using k8s.helm.v3.Chart.
      • We specify the chart name, version, and the Helm repository URL where the Plex chart can be found.
      • In the values object, you'll need to insert your own Plex claim token which uniquely identifies your server to your plex.tv account.
      • Optional configurations, such as persistence for storing the Plex configuration, is included in values.
    • Lastly, we export the name of the Plex deployment as a Stack output, which can be useful for further reference or automation.

    Before Running the Program:

    1. Ensure you have Pulumi CLI installed and set up with your GCP credentials.
    2. If you don't have a Plex claim token, you need to generate one at Plex's website.

    Once this Pulumi program is run, it will set up the GKE cluster and deploy the Plex Media Server for you. You can then manage your infrastructure and application as code!