Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added service account token generation step and formatted some yaml #3988

Open
wants to merge 1 commit into
base: fix-kubeconfig-script
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 18 additions & 21 deletions website/docs/cluster-management/managing-clusters-without-capi.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,22 @@ kubectl create secret generic demo-01-kubeconfig \

Here's how to create a kubeconfig secret.

1. Create a new service account on the remote cluster:
1. Create a new service account on the remote cluster with a token:

```yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: demo-01
namespace: default
name: demo-01
namespace: default
---
apiVersion: v1
kind: Secret
metadata:
name: demo-01-token
annotations:
kubernetes.io/service-account.name: demo-01
type: kubernetes.io/service-account-token
```

2. Add RBAC permissions for the service account:
Expand All @@ -58,8 +66,8 @@ Here's how to create a kubeconfig secret.
name: impersonate-user-groups
subjects:
- kind: ServiceAccount
name: demo-01
namespace: default
name: demo-01
namespace: default
roleRef:
kind: ClusterRole
name: user-groups-impersonator
Expand All @@ -71,11 +79,11 @@ Here's how to create a kubeconfig secret.
name: user-groups-impersonator
rules:
- apiGroups: [""]
resources: ["users", "groups"]
verbs: ["impersonate"]
resources: ["users", "groups"]
verbs: ["impersonate"]
- apiGroups: [""]
resources: ["namespaces"]
verbs: ["get", "list"]
resources: ["namespaces"]
verbs: ["get", "list"]
```

</details>
Expand All @@ -87,18 +95,7 @@ Here's how to create a kubeconfig secret.
3. Retrieve the token from the service account. First, run this command to get the list of secrets of the service accounts:

```bash
kubectl get secrets --field-selector type=kubernetes.io/service-account-token
NAME TYPE DATA AGE
default-token-lsjz4 kubernetes.io/service-account-token 3 13d
demo-01-token-gqz7p kubernetes.io/service-account-token 3 99m
```

(`demo-01-token-gqz7p` is the secret that holds the token for `demo-01` service account.)

Then, run the following command to get the service account token:

```bash
TOKEN=$(kubectl get secret demo-01-token-gqz7p -o jsonpath={.data.token} | base64 -d)
TOKEN=$(kubectl get secret demo-01-token -o jsonpath={.data.token} | base64 -d)
```

4. Create a kubeconfig secret. We'll use a helper script to generate the kubeconfig, and then save it into `static-kubeconfig.sh`:
Expand Down