title | description | videoBanner |
---|---|---|
Enroll a Kubernetes Cluster |
Demonstrates how to enroll a Kubernetes cluster as a resource protected by Teleport. |
3AUGrOZ5me0 |
This guide demonstrates how to enroll a Kubernetes cluster as a Teleport resource by deploying the Teleport Kubernetes Service on the Kubernetes cluster you want to protect.
In this scenario, the Teleport Kubernetes Service pod detects that it is running on Kubernetes and enrolls the Kubernetes cluster automatically. The following diagram provides a simplified overview of this deployment scenario with the Teleport Kubernetes Service running on the Kubernetes cluster:
For information about other ways to enroll and discover Kubernetes clusters, see Registering Kubernetes Clusters with Teleport.
-
Access to a running Teleport cluster,
tctl
admin tool, andtsh
client tool, version >= (=teleport.version=).You can verify the tools you have installed by running the following commands:
$ tctl version # Teleport v(=teleport.version=) go(=teleport.golang=) $ tsh version # Teleport v(=teleport.version=) go(=teleport.golang=)
You can download these tools by following the appropriate Installation instructions for your environment.
(!docs/pages/includes/kubernetes-access/helm-k8s.mdx!)
- (!docs/pages/includes/tctl.mdx!)
To authenticate to a Kubernetes cluster using Teleport, you must have a Teleport role that grants access to the Kubernetes cluster you plan to interact with.
In this step, we show you how to create a Teleport role called kube-access
that enables a user to send requests to any Teleport-protected Kubernetes
cluster as a member of the viewers
group. The Teleport Kubernetes Service
impersonates the viewers
group when proxying requests from the user.
-
Create a file called
kube-access.yaml
with the following content:kind: role metadata: name: kube-access version: v7 spec: allow: kubernetes_labels: '*': '*' kubernetes_resources: - kind: '*' namespace: '*' name: '*' verbs: ['*'] kubernetes_groups: - viewers deny: {}
-
Apply your changes:
$ tctl create -f kube-access.yaml
(!docs/pages/includes/create-role-using-web.mdx!)
-
(!docs/pages/includes/add-role-to-user.mdx role="kube-access"!)
While you have authorized the kube-access
role to access Kubernetes clusters
as a member of the viewers
group, this group does not yet have permissions
within its Kubernetes cluster. To assign these permissions, create a Kubernetes
RoleBinding
or ClusterRoleBindings
that grants permission to the viewers
group.
-
Create a file called
viewers-bind.yaml
with the following contents:apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: viewers-crb subjects: - kind: Group # Bind the group "viewers" to the kubernetes_groups assigned in the "kube-access" role name: viewers apiGroup: rbac.authorization.k8s.io roleRef: kind: ClusterRole # "view" is a default ClusterRole that grants read-only access to resources # See: https://kubernetes.io/docs/reference/access-authn-authz/rbac/#user-facing-roles name: view apiGroup: rbac.authorization.k8s.io
-
Apply the
ClusterRoleBinding
withkubectl
:$ kubectl apply -f viewers-bind.yaml
Your Teleport user now has permissions to assume membership in the viewers
group when accessing your Kubernetes cluster, and the viewers
group now has
permissions to view resources in the cluster. The next step is to deploy the
Teleport Kubernetes Service in the cluster to proxy user requests.
In this step, you will deploy the Teleport Kubernetes Service on your Kubernetes cluster by copying a script from the Teleport Web UI and running it on your terminal.
-
Open the Teleport Web UI and sign in using your administrative account.
-
Click Enroll New Resource.
-
Type all or part of Kubernetes in the Search field to filter the resource types displayed, then click Kubernetes.
-
Copy the command to add the
teleport-agent
chart repository and paste it in a terminal on your workstation. -
Type
teleport-agent
for namespace where you will deploy the Teleport Kubernetes Service and the display name to use when connecting to this cluster, then click Next.After you click Next, Teleport generates a script to configure and enroll the Kubernetes cluster as a resource in the Teleport cluster.
-
Copy the command displayed in the Teleport Web UI and run it in your terminal.
The Teleport Web UI displays "Successfully detected your new Kubernetes cluster" as confirmation that your cluster is enrolled. When you see this message, click Next to continue.
Now that you have deployed the Teleport Kubernetes Service on your Kubernetes
cluster and enrolled the cluster as a Teleport resource, confirm that you can
access your Kubernetes cluster as a member of the viewers
group.
If you followed the previous steps in this guide, the Set Up Access view
populates the Kubernetes Groups field with viewers
.
To set up and test access:
-
Click Next.
-
Specify the
teleport-agent
namespace, the Kubernetesviewers
group from the previous step, and your Teleport user name. -
Copy and run the commands displayed in the Teleport Web UI to interact with the Kubernetes cluster and verify access through Teleport. Alternatively, run the commands shown below:
Authenticate to your Teleport cluster, assigning to your cluster domain and to your Teleport username:
$ tsh login --proxy=<Var name="teleport.example.com"/>:443 --auth=local --user=<Var name="[email protected]"/> <Var name="teleport.example.com"/>
List Kubernetes clusters available for you to access:
$ tsh kube ls
Retrieve credentials to access your Kubernetes cluster, replacing with your Kubernetes cluster name:
$ tsh kube login <Var name="Kubernetes-cluster-name"/>
The Teleport Kubernetes Service proxies
kubectl
commands:$ kubectl get pods -n teleport-agent
You should see the Teleport Kubernetes Service pod you deployed earlier:
NAME READY STATUS RESTARTS AGE teleport-agent-0 1/1 Running 0 8m6s
-
Click Finish.
This guide demonstrated how to enroll a Kubernetes cluster by running the Teleport Kubernetes Service within the Kubernetes cluster.
- For information about discovering Kubernetes clusters hosted on cloud providers, see Kubernetes Cluster Discovery.
- To learn about other ways you can register a Kubernetes cluster with Teleport, see Registering Kubernetes Clusters with Teleport.
- For a complete list of the parameters you can configure in the
teleport-kube-agent
helm chart, see the Chart Reference.