1. Deploy the kubescape-relevancy helm chart on Oracle Kubernetes Engine (OKE)

    TypeScript

    Deploying a Helm chart on Oracle Kubernetes Engine (OKE) involves several steps: provisioning the OKE cluster, configuring your Kubernetes environment to communicate with the cluster, and then deploying the Helm chart to the cluster.

    First, you'll need to provision an OKE cluster using Pulumi's oci.ContainerEngine.Cluster. Once the cluster is provisioned, you can configure kubectl to interact with it using the cluster's kubeconfig, which can be fetched from the OKE cluster resource's attributes.

    For deploying a Helm chart, we'll use the kubernetes.helm.v3.Chart resource from the Pulumi Kubernetes provider. This resource allows you to deploy Helm charts into a Kubernetes cluster. You'll need to ensure you have the Helm CLI installed on your local machine where you'll run the Pulumi code, and that Helm is configured to interact with your cluster.

    Below is a Pulumi program written in TypeScript that provisions an OKE cluster and deploys the "kubescape-relevancy" Helm chart to it. Note that you should have the necessary OCI credentials configured in your environment for Pulumi to communicate with Oracle Cloud.

    Let's go through the code step by step:

    1. Provision OKE Cluster: Create a new OKE cluster in the specified compartment with the given settings. Adjust the properties like the name, compartment ID, and VCN according to your requirements. After creation, fetch the kubeconfig which is used to configure kubectl.

    2. Deploy Helm Chart: After setting up the OKE cluster, we deploy a Helm chart to it. In this example, we're deploying a Helm chart named "kubescape-relevancy." The chart property specifies the name of the chart, and you may provide additional configuration options via the values property if needed.

    3. Export Cluster Information: After the deployment is complete, the program exports the cluster's ID and the endpoint, which can be used to access the Kubernetes Dashboard or API server.

    Before you run the code, you need to replace the placeholders with actual values for compartmentId, vcnId, and any other necessary configuration specific to your Oracle Cloud environment.

    Here's a complete example:

    import * as oci from "@pulumi/oci"; import * as k8s from "@pulumi/kubernetes"; import * as pulumi from "@pulumi/pulumi"; const compartmentId = "ocid1.compartment.oc1..<unique_id>"; // replace with your Compartment's OCID const vcnId = "ocid1.vcn.oc1..<unique_id>"; // replace with your VCN's OCID // Provision an Oracle Kubernetes Engine (OKE) Cluster const cluster = new oci.ContainerEngine.Cluster("my-oke-cluster", { compartmentId: compartmentId, vcnId: vcnId, kubernetesVersion: "v1.21.5", options: { serviceLbSubnetIds: [], // specify load balancer subnet IDs if needed // Additional options can be provided here }, // Further configuration for the cluster }); // Fetching the kubeconfig of the cluster for kubectl configuration const kubeconfig = cluster.kubeconfig.apply(c => c.content); // Create a provider for the above fetched kubeconfig so it can be used to deploy Helm charts const k8sProvider = new k8s.Provider("my-oke-k8s", { kubeconfig }); // Deploy the "kubescape-relevancy" Helm chart const helmChart = new k8s.helm.v3.Chart("kubescape-relevancy", { chart: "kubescape-relevancy", // If "kubescape-relevancy" is a Helm chart in a custom Helm chart repository, // you will need to specify the `repo` property to point to that repository. // For example: // repo: "https://helm.example.com/", // Specify the namespace if relevant. For example `namespace: "default"`. }, { provider: k8sProvider }); // Export the cluster ID and Management endpoint URL export const clusterId = cluster.id; export const clusterManagementUrl = cluster.endpoints.apply(e => e.kubernetes);

    In this code:

    • oci.ContainerEngine.Cluster is the Pulumi resource that creates an OKE cluster. We need to supply required values such as the compartment ID and the VCN ID within which the cluster will be created.

    • kubeconfig is obtained from the kubeconfig output of the oci.ContainerEngine.Cluster resource, which is necessary to configure kubectl and the Pulumi Kubernetes provider.

    • k8s.Provider is a Pulumi resource that lets us specify which Kubernetes cluster we want to interact with. We pass the kubeconfig from the OKE cluster to it.

    • k8s.helm.v3.Chart is the Pulumi resource to deploy a Helm chart. In this case, we are deploying the "kubescape-relevancy" chart into the cluster associated with the k8sProvider.

    Remember to ensure Helm is installed and the OKE cluster is properly configured to use Helm. You can find more details in the Helm Chart documentation.

    After defining the resources, we export important information that may be useful, such as the cluster ID and the management URL, which can be used to access the Kubernetes Dashboard.

    Finally, to apply this configuration, run pulumi up in your command line from the directory where this code is saved.

    Make sure to review Pulumi's documentation to set up the Oracle Cloud provider and the OCI documentation for details on creating and managing OKE clusters.