Using kubernetes helm.toolkit.fluxcd.io with aws.upbound.io
TypeScriptIf you're looking to use the Flux Helm Controller with Pulumi to manage resources on AWS, the general process would involve installing the Flux CD Helm Controller into your Kubernetes cluster and then using Pulumi to manage both your Kubernetes cluster resources and your AWS infrastructure.
Flux CD is a set of continuous and progressive delivery solutions for Kubernetes, and is often used for GitOps. It includes the Helm Controller, which allows you to declare the desired state of Helm charts in your version-controlled source and have them automatically applied and maintained in your Kubernetes cluster. On the other hand, AWS (upbound.io) offers Upbound, which can be used to control cloud infrastructure alongside Kubernetes.
In the context of Pulumi, you can create and manage your Kubernetes cluster in AWS using the Pulumi AWS or EKS libraries, manage your resources and then deploy your Helm releases using the Pulumi Kubernetes provider.
Let’s start with setting up an EKS cluster using Pulumi, and then we'll deploy a Helm chart using the Flux Helm Controller within that cluster.
import * as aws from "@pulumi/aws"; import * as eks from "@pulumi/eks"; import * as k8s from "@pulumi/kubernetes"; // Create an EKS cluster with the desired configuration. const cluster = new eks.Cluster("my-cluster", { // Specify the desired version and other settings for the cluster. }); // Export the kubeconfig. export const kubeconfig = cluster.kubeconfig; // Create a k8s provider using the cluster's kubeconfig. const k8sProvider = new k8s.Provider("k8s-provider", { kubeconfig: cluster.kubeconfig, }); // Using the Kubernetes provider, install the Flux Helm Controller. const fluxHelmRelease = new k8s.yaml.ConfigFile("flux-helm-controller", { file: "https://github.com/fluxcd/helm-controller/releases/download/v0.11.1/helm-controller.crds.yaml", }, { provider: k8sProvider }); // After setting up the Flux Helm Controller, you can then deploy Helm releases that // are reconciled by Flux in your EKS cluster. You'd typically commit your HelmRelease // specifications to a Git repository, and Flux will ensure the state of your cluster // matches the desired state declared in your repo. // For illustrative purposes, we're creating a HelmRelease manually here. const helmRelease = new k8s.apiextensions.CustomResource("example-helm-release", { apiVersion: "helm.toolkit.fluxcd.io/v2beta1", kind: "HelmRelease", metadata: { name: "my-helm-release", namespace: "default", // or any namespace where you installed flux }, spec: { interval: "5m", chart: { spec: { chart: "podinfo", version: "5.0.3", sourceRef: { kind: "HelmRepository", name: "podinfo", namespace: "default" }, }, }, }, }, { provider: k8sProvider, dependsOn: fluxHelmRelease }); // Use Pulumi to deploy other AWS resources.... // ... // Export any additional outputs - URLs, resource names, etc. // ...
In the above code:
- We have created an EKS cluster using Pulumi's EKS library.
- A Kubernetes provider is set up with the generated kubeconfig from the EKS cluster.
- We installed the Flux Helm Controller CRDs from the release URL using the Pulumi Kubernetes provider.
- We then declared a HelmRelease custom resource representing a Helm Chart to be applied by the Flux Helm controller.
It's worth noting that in a typical Flux workflow, you would set up a
HelmRepository
resource pointing to your Helm charts' repository and aHelmRelease
resource that references the charts. This would then be committed to your version control system. Flux continually reconciles your cluster's state to match the declared state in your repository.Make sure to replace
"https://github.com/fluxcd/helm-controller/releases/download/v0.11.1/helm-controller.crds.yaml"
with the appropriate URL for the Flux Helm Controller CRDs that you wish to use, and to customize the cluster creation and HelmRelease details as per your specific requirements.