This project contains the basics for deploying Consul on an AWS EKS cluster using Terraform and consul-k8s
.
The following steps create AWS resources that will incur costs in your AWS account.
-
Initialize terraform
terraform init
-
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
-
Configure
kubectl
to target your newly minted EKS cluster.$(terraform output -json | jq -r '.update_kubeconfig_cmd.value')
-
View the nodes in your EKS cluster.
kubectl get nodes
-
Deploy Consul via
consul-k8s
.consul-k8s install -namespace default -config-file values.yaml
-
View the Consul deployment in K8s.
kubectl get pods
-
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
-
Interact with your Consul deployment. The easiest way to do this is to use
kubectl port-forward
to route traffic directly fromlocalhost
to the pods running in your EKS cluster.-
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
-
In the original shell, use
curl
orconsul
to list the services catalogcurl -ks -H "x-consul-token: $CONSUL_HTTP_TOKEN" https://localhost:8501/v1/catalog/services | jq . consul catalog services
-
-
You can do the same port forwarding magic for the Consul UI.
-
Port-forward the Consul UI
kubectl port-forward services/consul-ui 8501:443
-
Use a web browser to view the Consul UI at https://localhost:8501
-
Use the
CONSUL_HTTP_TOKEN
to log inecho $CONSUL_HTTP_TOKEN
-
Uninstall Consul
consul-k8s uninstall -name consul -namespace default -wipe-data -auto-approve
Remove the EKS cluster
terraform destroy -var name=$USER