Enroll one Kubernetes cluster in the same Teleport cluster that runs your beams. Then start a beam that can list pods in one namespace.
Prerequisites
- A Teleport cluster with Beams enabled. You need permission to enroll Kubernetes resources, manage roles and create beams.
- A workstation with
tsh,tctl, Helm andkubectl. Sign in to Teleport and configurekubectlwith administrative access to the target Kubernetes cluster. - A beam image with
kubectlinstalled. The beam already hastshand its own Teleport identity.
Enroll the cluster
Follow Teleport’s guided Kubernetes enrollment:
- In the Teleport Web UI, select Enroll New Resource → Kubernetes.
- On your workstation, verify that
kubectl config current-contextpoints to the cluster you want to enroll. Run the chart repository command from the wizard. - Enter
teleport-agentas the agent namespace andexample-k8sas the cluster’s display name. - Run the generated Helm command on your workstation. Add
--set labels.beams-access=example-k8sto the Helm invocation. This sets the Teleport resource label used by the role below; it is not a Kubernetes object label. - Wait for the wizard to detect the new cluster. Keep any enrollment token in the generated command out of the beam and out of source control.
Grant read-only pod access
On your workstation, save this as beams-pod-reader.yaml. This example uses the existing default namespace. Replace default in this file, the Teleport role and the proxy command if you want to use another namespace.
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: beams-pod-reader
namespace: default
rules:
- apiGroups: [""]
resources: [pods]
verbs: [get, list]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: beams-pod-reader
namespace: default
subjects:
- kind: Group
name: beams-pod-readers
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: Role
name: beams-pod-reader
apiGroup: rbac.authorization.k8s.ioSave this Teleport role as beam-kube-reader.yaml. This Teleport role permits only pod reads for the matching cluster and namespace. The Kubernetes role grants those reads to the group that Teleport impersonates.
kind: role
version: v8
metadata:
name: beam-kube-reader
spec:
allow:
kubernetes_labels:
beams-access: example-k8s
kubernetes_groups: [beams-pod-readers]
kubernetes_resources:
- kind: pods
api_group: ""
namespace: default
name: "*"
verbs: [get, list]Apply both files on your workstation:
kubectl apply -f beams-pod-reader.yaml
tctl create -f beam-kube-reader.yamlAssign beam-kube-reader to your Teleport user through your user or SSO role mapping, then sign in again. Your cluster must allow you to delegate the role.
List pods from a beam
Start a beam with the pod-reader role. If your default image doesn’t include kubectl, add --phase=kubectl-tools and replace kubectl-tools with the name of a phase that provides it.
tsh beams add --roles=beam-kube-reader --no-share-connected-accountsInside the beam, confirm that Teleport lists example-k8s. Then start a local proxy for a single kubectl command:
tsh kube ls
tsh proxy kube --exec-cmd=kubectl --exec-arg=get --exec-arg=pods --exec-arg=-n --exec-arg=default example-k8stsh proxy kube sets a temporary KUBECONFIG for kubectl and stops the proxy when the command exits. An empty pod list is valid if the namespace has no pods. For several commands, run tsh proxy kube --exec example-k8s to open a shell with the proxy configured, and exit that shell when finished.
Kubernetes isn’t connected to VNet in a beam. Use tsh proxy kube for kubectl rather than tsh kube login; use tsh kube ls directly for discovery. Do not copy your workstation’s kubeconfig into the beam.
When you’re done, delete the beam. For other enrollment methods, see Teleport Auto-Discovery.