Skip to content

Use Terraform to stand up a EKS K8s cluster, deploy Consul using consul-k8s

Notifications You must be signed in to change notification settings

cthain/consul-eks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Consul EKS

This project contains the basics for deploying Consul on an AWS EKS cluster using Terraform and consul-k8s.

Requirements

Note

The following steps create AWS resources that will incur costs in your AWS account.

Usage

  1. Initialize terraform

    terraform init
  2. Deploy the EKS cluster via Terraform. This step also generates the values.yaml file that is used to install Consul.

    terraform apply -var name=$USER
  3. Configure kubectl to target your newly minted EKS cluster.

    $(terraform output -json | jq -r '.update_kubeconfig_cmd.value')
  4. View the nodes in your EKS cluster.

    kubectl get nodes
  5. Deploy Consul via consul-k8s.

    consul-k8s install -namespace default -config-file values.yaml
  6. View the Consul deployment in K8s.

    kubectl get pods
  7. Export environment variables to interact with Consul

    export CONSUL_HTTP_ADDR=https://localhost:8501
    export CONSUL_HTTP_TOKEN=$(terraform output -json | jq -r '.consul_http_token.value')
    export CONSUL_HTTP_SSL_VERIFY=false
  8. Interact with your Consul deployment. The easiest way to do this is to use kubectl port-forward to route traffic directly from localhost to the pods running in your EKS cluster.

    1. Open a separate terminal (make sure you reconfigure your AWS credentials for that terminal). Forward traffic from your local machine to the Consul server running on EKS.

      kubectl port-forward services/consul-server 8501
    2. In the original shell, use curl or consul to list the services catalog

      curl -ks -H "x-consul-token: $CONSUL_HTTP_TOKEN" https://localhost:8501/v1/catalog/services | jq .
      consul catalog services
  9. You can do the same port forwarding magic for the Consul UI.

    1. Port-forward the Consul UI

      kubectl port-forward services/consul-ui 8501:443
    2. Use a web browser to view the Consul UI at https://localhost:8501

    3. Use the CONSUL_HTTP_TOKEN to log in

      echo $CONSUL_HTTP_TOKEN

Clean up

Uninstall Consul

consul-k8s uninstall -name consul -namespace default -wipe-data -auto-approve

Remove the EKS cluster

terraform destroy -var name=$USER

About

Use Terraform to stand up a EKS K8s cluster, deploy Consul using consul-k8s

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages