Deploy Vault on Amazon EKS Anywhere
This tutorial provides guidance on deploying Vault in Amazon Elastic Kubernetes Service (EKS) Anywhere. Amazon EKS Anywhere is a new deployment option for Amazon EKS that allows customers to create and operate Kubernetes clusters on customer-managed infrastructure, supported by AWS. There are several layers in this stack and this tutorial will help you set up your infrastructure end-to-end.
The bottom-most layer of the stack consists of Bare Metal with VMware's vSphere as the first layer of abstraction. Amazon EKS runs on top of that as the Kubernetes distribution with Vault running as the secrets manager for it.
Prerequisites
The following prerequisites are required to follow the steps in this tutorial:
AWS account with permissions for S3 and EKS services
One of the following:
- Amazon EKS Anywhere cluster already deployed
- Access to VMware vCenter cluster
- Equinix bare metal, Terraform and VMware account with access to vCenter Server Appliance (VCSA) binary
Vault Enterprise license (if using Enterprise version of Vault)
Administrative machine prerequisites:
- Docker 20.x.x
- Kubernetes command-line interface (CLI)
- Helm CLI installed
- Mac OS (10.15) or Ubuntu (20.04.2 LTS)
- 4 CPU cores
- 16GB memory
- 30GB free disk space
Note
If you already have a Amazon EKS Anywhere cluster, skip to deploy Vault on Amazon EKS Anywhere section.
Note
If you already have a VMware vCenter deployment with these prerequisites, skip to the deploy Amazon EKS Anywhere on vCenter section.
Download required files
Launch the vSphere downloads page. Under Enterprise, select VMware vCenter Server 7.0.3 (or the latest version). Select the GO TO DOWNLOAD link, and then click the DOWNLOAD NOW button.
Launch the vSan Management SDK for Python page. Click the DOWNLOAD button to download v7.0.3 (or the corresponding latest version to the previous step).
Upload the
VMware-VCSA-all-<version>.iso
into Amazon S3 bucket to a folder path of your choice, usingvcsa-iso-image
.List S3 objects to discover the
vcsa-iso-image
path.Upload the
VMware-VCSA-all-<version>.iso
into Amazon S3 bucket.Upload the Python scripts you downloaded earlier which is located at bindings > vsanmgmtObjects.py to the Amazon S3 folder.
Upload the Python scripts located at samplecode > vsanapiutils.py to the Amazon S3 bucket.
The Amazon S3 bucket should look simiar to following
Note
For more information, refer the Equinix vSphere GitHub repository.
Deploy vCenter
To setup vCenter cluster using Equinix Bare Metal services follow these steps, for a more detailed setup follow the instructions on their website.
Create a
eksa
folder and change the working directory toeksa
.Clone the terraform repository.
Set the working directory to
terraform-metal-vsphere
.Launch the Equinix console, and select Personal settings > Personal API keys > create. Make a note of the API key value.
From the Equinix console, click top-right on your name and select settings > org settings > General > Account Id. Make a note of the org ID.
From the Equinix console, select Personal settings > Project Id and copy the project ID.
Use your preferred text editor, create a file named,
terraform.tfvars
as follow. Change the facility value matches to your preference.terraform.tfvars1 2 3 4 5 6 7 8 9 101112131415
Perform a
terraform init
to pull down the necessary provider resources.Run
terraform apply
and review the planned actions. Your terminal output should indicate the plan is running and what resources will be created.When prompted, enter
yes
to confirm and resume.Warning
If you get the “folder not present” error at any step, destroy the terraform resources using `terraform destroy` and edit the `main.tf`. Replace all locations of `$HOME` to `/root`. The output includes the following.
Setup VPN to connect to vCenter cluster via CLI (Optioal)
Note
This step is optional, you can SSH into the bastion to perform all of the vCenter operations.
There is an L2TP IPsec VPN client for every platform. You need to reference your operating system's documentation on how to connect to an L2TP IPsec VPN. Make sure to enable all traffic to use the VPN (aka do not enable split tunneling) on your L2TP client.
Warning
Some corporate networks block outbound L2TP traffic. If you are experiencing issues connecting, try a guest network or personal hotspot to see if that is the case.
Deploy Amazon EKS Anywhere on vCenter
If you’re using a self deployed vCenter cluster, refer the Amazon EKS Anywhere create production cluster guide.
Login to vCenter and create resource pool under Metal (Datacenter) > Metal1 (Cluster) > EKSA (New resource Pool).
Install
eksctl
andeksctl-anywhere
with homebrew.Note
Refer to the Install EKS Anywhere documentation for more details.
Verify the installed version.
Generate a yaml file to deploy Amazon EKS Anywhere.
Edit the control plane configuration in
eksa-mgmt-cluster.yaml
.eksa-mgmt-cluster.yamlThe CIDR block is defined, and the first 100 IPs are reserved for DHCP, so a good one would be
172.16.0.150
.Install
govc
CLI from thevmware/govmomi
repository.Set the
GOVC_INSECURE
environment variable value to 1 to disable certificate verification.Set the
GOVC_URL
environment variable to the URL of ESXi or vCenter instance to connect to.Set the
GOVC_USERNAME
environment variable to the usename to use if not specified in GOVC_URL.Set the
GOVC_PASSWORD
environment variable value to the password to use if not specified in GOVC_URL.Use
govc
CLI to retrieve info about vCenter cluster.Use the private network for VMs in configuration: vCenter console > Network.
Generate thumbprint for vSphere. This is required when the connection is not insecure.
Edit the vSphere Data center configuration with the information gathered from the previous step.
eksa-mgmt-cluster.yamlWarning
There are some issues when setting the connection as insecure (as of Feb 2022), the Amazon EKS Anywhere team is working on resolving it.
Edit vSphere machine configs to use the appropriate datastore and resource pool.
eksa-mgmt-cluster.yamlSet the
EKSA_VSPHERE_USERNAME
environment variable.Set the
EKSA_VSPHERE_PASSWORD
environment variable.Set the
EKSA_LICENSE
environment variable. This is not required if you already have one.Deploy Amazon EKS Anywhere.
Store the
kubeconfig
file. You need to storekubeconfig
in bastion or use VPN from the optional step.Display the nodes of the cluster.
Deploy Vault on Amazon EKS Anywhere
Vault installation on Amazon EKS Anywhere is same as any kubernetes installation. For a step-by-step intruction, refer to the Vault on Kubernetes Deployment Guide.
Create a
vault
directory and change the working directory to thevault
directory.Create a configuration file to configure Vault installation.
Create a new namespace for the Vault installation.
To access the Vault Helm chart, add the Hashicorp Helm repository.
Install the Vault helm chart.
Initialize and unseal Vault.
The output displays the key shares and initial root key generated.
Note
These keys are critical to both the security and the operation of Vault and should be treated as per your company's sensitive data policy.
Unseal the Vault server using the unseal keys until the key threshold is met.
When prompted, enter the Unseal Key 1 value.
When prompted, enter the Unseal Key 2 value.
When prompted, enter the Unseal Key 3 value.
Validate that Vault is up and running.
Display all Vault services.
Display the nodes of the cluster.
Install the HashiCorp tap, a repository of all our Homebrew packages.
Install Vault with hashicorp/tap/vault.
Set the
VAULT_ADDR
environment variable. Since we exposed Vault usingNodePort
, Vault will be available at172.16.0.97:8200
. Access it from your bastion host or VPN from the optional step.Set the
VAULT_TOKEN
environment variable value to the initial root token value generated during the Vault initialization.Enable the kv secrets engine.
Store some test data at
kv/hello
.Read the stored data to verify.
Configure Kubernetes auth method
Note
Refer to the Vault Agent with Kubernetes tutorial for more details.
Retrieve the additional configuration by cloning the
hashicorp/learn-vault-agent
repository from GitHub.Change the working directory to
learn-vault-agent/vault-agent-k8s-demo
.Update the vault-auth service account.
Create a read-only policy,
myapp-kv-ro
in Vault.Create some test data at the
secret/myapp
path.Set the
K8S_HOST
environment variable value to minikube IP address.Enable the Kubernetes auth method at the default path.
Configure the kubernetes auth method.
Version compatibility
Starting in v1.24, Kubernetes will no longer auto-generate the Secret object. So, for the best compatibility with recent Kubernetes versions, ensure you are using Vault v1.9.3 or greater.
Output:
Create a role named,
example
, that maps the Kubernetes Service Account to Vault policies and default token TTL.Output:
Verify the Kubernetes auth method configuration
Create a variable named
EXTERNAL_VAULT_ADDR
.Define a Pod with a container.
The Pod is named
devwebapp
and runs with thevault-auth
service account.Create the
devwebapp
pod in thedefault
namespaceDisplay all the pods in the default namespace.
Wait until the
devwebapp
pod is running and ready (1/1
).Start an interactive shell session on the
devwebapp
pod.Your system prompt is replaced with a new prompt
#
.Set
KUBE_TOKEN
to the service account token.Authenticate with Vault through the
example
role with theKUBE_TOKEN
.Example output:
Next steps
In this tutorial, you deployed Vault on an Amazon EKS Anywhere cluster. Also, you enabled Kubernetes auth method so that Vault clients can authenticate with Vault using the trusted service account.