Deploy the Wordpress helm chart on AWS EKS
TypeScriptTo deploy a WordPress Helm chart on Amazon EKS with Pulumi, we'll go through a few steps. First, we need to create an EKS cluster. Then we'll deploy the WordPress application using the Helm chart. The following Pulumi TypeScript code performs these actions.
Here's the breakdown of the process:
-
EKS Cluster Creation: Using the
eks.Cluster
resource from thepulumi/eks
package, we will set up a new AWS EKS cluster. This resource automates the setup of the required resources like the EKS control plane, worker nodes, and supporting AWS infrastructure such as VPC and IAM roles. -
Deployment of WordPress Helm Chart: After the EKS cluster is up and running, we'll use the
kubernetes.helm.v3.Chart
resource frompulumi/kubernetes
to deploy WordPress using its Helm chart. Helm is a package manager for Kubernetes, which lets you define, install, and upgrade applications running on a Kubernetes cluster.
Note that the following program assumes you have AWS credentials and Pulumi CLI set up and configured on your machine. The code doesn't include the creation of an RDS database for WordPress, which you would want to consider for a production setup.
import * as pulumi from "@pulumi/pulumi"; import * as eks from "@pulumi/eks"; import * as k8s from "@pulumi/kubernetes"; import * as awsx from "@pulumi/awsx"; // Create an EKS cluster with the default configuration. const cluster = new eks.Cluster("wp-cluster", { desiredCapacity: 2, minSize: 1, maxSize: 2, storageClasses: "gp2", // for dynamic provisioning }); // Export the cluster's kubeconfig. export const kubeconfig = cluster.kubeconfig; // Create a Kubernetes provider instance that uses our EKS cluster's kubeconfig. const provider = new k8s.Provider("wp-provider", { kubeconfig: cluster.kubeconfig, }); // Deploy WordPress using the Helm chart. const wordpress = new k8s.helm.v3.Chart("wp-wordpress", { chart: "wordpress", version: "9.0.3", // specify the version of the chart to deploy namespace: "default", fetchOpts: { // This specifies the repository to fetch the chart from repo: "https://charts.bitnami.com/bitnami", }, values: { // Here you can provide overrides to the default chart values mariadb: { enabled: false, // As an example, we are disabling the mariadb deployment bundled with the chart }, externalDatabase: { // External database configuration (example values) host: "your-database-host", user: "your-database-user", password: "your-database-password", database: "your-database-name", }, service: { type: "LoadBalancer", // Exposes WordPress on a LoadBalancer so you can access it over the internet }, }, }, { providers: { kubernetes: provider } }); // Export the public LoadBalancer endpoint to access your WordPress instance export const wordpressEndpoint = wordpress.getResource("v1/Service", "wp-wordpress-wordpress") .status.apply(status => status.loadBalancer.ingress[0].hostname);
How to read and use this program:
- The
eks.Cluster
class creates a new AWS Elastic Kubernetes Service (EKS) cluster. - After the EKS cluster is provisioned, the
kubernetes.Provider
class sets up a provider for deploying resources to this cluster using the generated kubeconfig. k8s.helm.v3.Chart
is then used to deploy the WordPress Helm chart from Bitnami's Helm repository.- We have disabled the bundled MariaDB in the chart (
mariadb.enabled: false
) and are using an external database configuration. You need to provide your external database's hostname, username, password, and database name. - The service type is set to
LoadBalancer
, which provisions an AWS load balancer for your WordPress service, making your blog accessible over the internet. - Finally,
wordpressEndpoint
is exported, providing you with the DNS name to access your WordPress site.
Assuming you have your Pulumi stack set up, run
pulumi up
to deploy this program. After the update is complete, the exportedwordpressEndpoint
will give you the URL to access your WordPress blog.-