How to Deploy WordPress to Amazon EKS using Helm
Tags: wordpress, eks, helm, devops
Published: 2023-01-15 21:48:21

In this article, you will learn how to deploy a production ready wordpress site to Amazon Elastic Kubernetes Service(EKS) with just a few easy steps. This is made possible using a package manager known as helm.

## What is Helm?
Helm is a Kubernetes deployment tool for automating creation, packaging, configuration, and deployment of applications and services to Kubernetes clusters. It is an open source package manager that automates the deployment of software for Kubernetes in a simple, consistent way. Helm deploys packaged applications to Kubernetes and structures them into charts. The charts contain all pre-configured application resources along with all the versions into one easily manageable package.

## What is a Helm Chart?
Helm charts are Helm packages consisting of YAML files and templates which convert into Kubernetes manifest files. These charts are reusable by anyone for any environment, which reduces complexity and duplicates.

For this demo, I made use of the [helm chart for wordpress](https://github.com/bitnami/charts/tree/main/bitnami/wordpress/#installing-the-chart) developed and maintained by [bitnami](https://bitnami.com/).

## Prerequisites
Ensure that you have the following utilities installed and configured on your machine.
[AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html), [EKSCTL](https://docs.aws.amazon.com/eks/latest/userguide/eksctl.html), [HELM](https://helm.sh/docs/intro/install/)

## 1. Provision the EKS cluster
Run the following code on your terminal after placing the value for your preferred region and existing keypair name 

```
cat <<EOF>>demo-eks-cluster.yaml
----
apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig

metadata:
  name: demo-eks-cluster
  region: your-region
  version: "1.21"

managedNodeGroups:
  - name: dev-ng-1
    instanceType: t3.large
    minSize: 1
    maxSize: 1
    desiredCapacity: 1
    volumeSize: 20
    volumeEncrypted: true
    volumeType: gp3
    ssh:
      allow: true
      publicKeyName: your-keypair-name
    tags:
      Env: Dev
    iam:
      attachPolicyARNs:
        - arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy
        - arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy
        - arn:aws:iam::aws:policy/ElasticLoadBalancingFullAccess
        - arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly
        - arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy
      withAddonPolicies:
        autoScaler: true
EOF
```
To confirm that the nodes have been provisioned, run: 

```
kubectl get nodes
```

## 2. Deploy Wordpress to EKS
First, add the helm repo to your environment.
```
helm repo add my-repo https://charts.bitnami.com/bitnami
```
Then, install the [helm chart for wordpress](https://github.com/bitnami/charts/tree/main/bitnami/wordpress/#installing-the-chart). For this use case,  I did overwrite the default wordpressPassword value in values.yaml using the command:

```
helm install my-release my-repo/wordpress --set wordpressPassword=password
```
 After successful deployment, check the pods and see if status reads "Running"

```
kubectl get pods
```

## 3. Accessing your wordpress site

To access your WordPress site from outside the cluster follow the steps below:
1. Get the WordPress URL by running these commands:
NOTE: It may take a few minutes for the LoadBalancer IP to be available.

```
export SERVICE_IP=$(kubectl get svc --namespace default wp-demo-wordpress --include "{{ range (index .status.loadBalancer.ingress 0) }}{{ . }}{{ end }}")
echo "WordPress URL: http://$SERVICE_IP/"
echo "WordPress Admin URL: http://$SERVICE_IP/admin"
```
2. Open a browser and access WordPress using the obtained URL.
3. Login with the following credentials below to see your blog:

username: user
password: password
![Wordpress-Default-Page](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zf7d8r86jgd2ldn9e9ty.PNG)
Adding a /admin to the url gives the following:

![adding /admin](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jqvb6ndqo5ig5swrlqpr.PNG)
Login with the credentials and you should hit your wordpress admin page

![wordpress](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8t5whpif349rs6jnt3wk.PNG)

## 4. Cleaning up
To clean up the resources created using the eksctl utility, run the following:

```
eksctl delete cluster demo-eks-cluster
```
Congratulations, your have successfully deployed a production-grade wordpress website to amazon EKS. Feel free to connect with me on [linkedin](https://www.linkedin.com/in/dickson-victor/) if you have any questions.