Connect to Kubernetes using Boundary
In this tutorial you will take on the role of the developer
team to connect to
Kubernetes using Boundary with brokered credentials from Vault.
Prerequisites
This tutorial requires you to have completed the Connect to Kubernetes using Boundary configuration tutorial.
Connect to Kubernetes using the Boundary CLI
To connect to Kubernetes, a developer
will need a Kubernetes service account
and token. You will simulate this process using the Boundary administrative
user.
You can learn how to create users in Boundary, and assign roles in the HCP administration or Self-managed administration tutorials.
Ensure you have logged in to Boundary as the admin user. Enter the username and password for your Boundary instance.
Authorize a new session.
Example output:
Create and switch to an empty
kubectl
context. This is done to ensure thekubectl
config is not overriding parameters to connect to the Kubernetes cluster.Use the brokered service account token to authenticate with the minikube cluster. The
server
parameter is passed to the minikube cluster because the currentkubectl
config is set to an invalid cluster context.
Connect to Kubernetes using Boundary Desktop
Lastly, test the experience of connecting to the Kubernetes cluster using the Boundary Desktop app.
To log into Boundary using the Desktop App, the BOUNDARY_ADDR
(Boundary
cluster address) must be gathered.
If you use HCP Boundary, you can locate the BOUNDARY_ADDR
in the HCP Boundary
Admin Console, as demonstrated in the HCP Boundary Getting
Started
tutorial.
If you use Boundary in dev mode, the BOUNDARY_ADDR
is http://127.0.0.1:9200
.
Open the Boundary desktop app.
Enter the Boundary cluster URL (for example,
https://ffee961b-5fd8-4e68-ba1d-2bbb487b576e.boundary.hashicorp.cloud
) and click Submit.Authenticate using your Boundary admin user credentials.
Under the Targets page, notice the target details for
kubernetes-api
. Click Connect.You are presented with a Proxy URL port number and a service_account_token.
Click on the copy icon for the
service_account_token
.On your local terminal, paste the service account token into an environment variable:
Next, paste the proxy port number from the Proxy URL into an environment variable:
Test the
kubectl
connection:
You can now use kubectl
to connect to the Kubernetes API from Boundary.
Set the Kubernetes context
To decrease friction when using the kubectl
command, you can set the
Kubernetes context. This will automatically pass the TLS server name, server
address, and brokered token when envoking kubectl
.
Create a new kubectl
context set called boundary
. Set the server address,
TLS server name, and path to the certificate authority file.
Set the credentials for the cluster context by creating a new user names
boundary-user
, and passing the BROKERED_KUBE_TOKEN
.
Set the new context.
And lastly, use the new context.
Test the kubectl
CLI without any additional options.
Note
When the Boundary session is terminated, the context will no longer be valid.
Once a new session is authorized, set the boundary-cluster
port again using
KUBERNETES_PORT
, and the boundary-user
with BROKERED_KUBE_TOKEN
.
Cleanup and teardown
Clean up Boundary.
If you used an HCP Boundary test cluster, consider cleaning up the cluster by deleting it, or deleting the org and its associated projects used for testing the Boundary and Kubernetes integration.
Clean up Vault.
If you use a HCP Vault Dedicated test cluster, consider cleaning up the cluster by deleting it. Ensure you only delete the cluster used for testing the Boundary and Kubernetes integration.
Locate the terminal session used to execute the
kubectl proxy --disable-filter=true
server command, and executectrl+c
.Delete the minikube cluster.
Unset the environment variables used in any active terminal windows for this tutorial.
Summary
This tutorial demonstrated configuring Boundary and Vault to facilitate just-in-time access to Kubernetes deployments.
To continue learning about Boundary, check out the Credential management tutorials.