A Step-by-Step Guide to Easily Deploying EKS Infrastructure and Applications Using Terraform

Sulaiman Olubiyi - Feb 4 - - Dev Community

Terraform is like the wizard of deployment tools. It's an open-source Infrastructure as Code (IaC) tool that lets you define and provision infrastructure using a declarative configuration language. Instead of manually setting up infrastructure such as servers, databases, and other resources, you can easily describe your desired infrastructure in code using HashiCorp Configuration Language (HCL).

This article focus on project using terraform for EKS , deploying applications using respective manifest files, and an application load balancer ingress controller using Helm.

The Github repository for this project EKS Terraform with application deployment

Below contains the detailed steps in this project, ensure you have an active AWS account before getting started;

  • List the contents of the terraform files

image

  • Initialize terraform on the directory to download required providers

terraform init

image

  • Validate the terraform file using :

terraform plan

image

image

  • Apply the terraform configuraton file

terraform apply --auto-approve

image

image

  • Copy the output of the terraform configuration to the ~/.kube/config

  • Installing aws-iam-authenticator
    This enables using AWS IAM credentials to authenticate to a Kubernetes cluster

curl -Lo aws-iam-authenticator https://github.com/kubernetes-sigs/aws-iam-authenticator/releases/download/v0.5.9/aws-iam-authenticator_0.5.9_linux_amd64
chmod +x ./aws-iam-authenticator
mkdir -p $HOME/bin && cp ./aws-iam-authenticator $HOME/bin/aws-iam-authenticator && export PATH=$PATH:$HOME/bin
echo 'export PATH=$PATH:$HOME/bin' >> ~/.bashrc
Enter fullscreen mode Exit fullscreen mode
  • Communicate with Kuberbetes cluster using kubectl get all

image

  • Get the pods in the cluster using 'kubectl get pods --all-namespaces'

image

  • Deploy the manifest for the pods deployment

kubectl apply -f manifests/deployment.yaml

image

  • Validate the deployment using kubectl get pods

image

  • Testing the deployment using the port forward

kubectl port-forward hello-kubernetes-6bf86759db-7jf7j 8080:8080

image

  • ALB Ingress Controller can be installed with Helm
  • Install Helm package
$ curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
$ chmod 700 get_helm.sh
$ ./get_helm.sh
Enter fullscreen mode Exit fullscreen mode

image

  • Install the collection of YAML files necessary to run the ALB Ingress Controller. Add the following repository

helm repo add incubator https://charts.helm.sh/incubator

  • Install the ALB Ingress Controller in my cluster
helm install ingress incubator/aws-alb-ingress-controller \
  --set autoDiscoverAwsRegion=true \
  --set autoDiscoverAwsVpcID=true \
  --set clusterName=terraform-eks
Enter fullscreen mode Exit fullscreen mode

image

  • Deploy the service loadbalancer on the cluster kubectl apply -f manifest/loadbalancer.yaml

image

image

  • Deploy the ingress.yaml for the service
wget https://raw.githubusercontent.com/kubernetes-sigs/aws-alb-ingress-controller/v1.1.9/docs/examples/alb-ingress-controller.yaml
kubectl apply -f https://raw.githubusercontent.com/kubernetes-sigs/aws-alb-ingress-controller/v1.1.9/docs/examples/rbac-role.yaml
Enter fullscreen mode Exit fullscreen mode

the cluster name and vpc id is change in the alb-ingress-controller.yaml

image

image

image

. . . . . . .
Terabox Video Player