feat: improved service_account docs

This commit is contained in:
Simon Cornet 2025-09-17 08:32:27 +02:00
commit b8988dcd65

View file

@ -1,42 +1,38 @@
# Service Account
Lets create a service account for ci/cd activities in a new namespace.
Let's create a service account for CI/CD activities in a new namespace.
## Namespace
```yaml
cat <<EOF | kubectl apply -f -
---
apiVersion: "v1"
kind: "Namespace"
apiVersion: v1
kind: Namespace
metadata:
name: "my-namespace"
EOF
name: my-namespace
```
## ServiceAccount
```yaml
cat <<EOF | kubectl apply -f -
---
apiVersion: "v1"
kind: "ServiceAccount"
apiVersion: v1
kind: ServiceAccount
metadata:
name: "buzz"
namespace: "my-namespace"
EOF
name: buzz
namespace: my-namespace
```
## Role
```yaml
cat <<EOF | kubectl apply -f -
---
apiVersion: "rbac.authorization.k8s.io/v1"
kind: "Role"
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
namespace: "my-namespace"
name: "buzz-role"
namespace: my-namespace
name: buzz-role
rules:
- apiGroups: ["apps"]
resources: ["deployments"]
@ -47,39 +43,36 @@ rules:
- apiGroups: ["networking.k8s.io"]
resources: ["ingresses"]
verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]
EOF
```
## RoleBinding
```yaml
cat <<EOF | kubectl apply -f -
---
apiVersion: "rbac.authorization.k8s.io/v1"
kind: "RoleBinding"
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: "buzz-binding"
namespace: "my-namespace"
name: buzz-binding
namespace: my-namespace
subjects:
- kind: "ServiceAccount"
name: "buzz"
namespace: "my-namespace"
- kind: ServiceAccount
name: buzz
namespace: my-namespace
roleRef:
kind: "Role"
name: "buzz-role"
apiGroup: "rbac.authorization.k8s.io"
EOF
kind: Role
name: buzz-role
apiGroup: rbac.authorization.k8s.io
```
## Token and KubeConfig (OmnI)
Get the token for the user.
Get the token for the service account:
```shell
kubectl create token buzz -n my-namespace
```
When using OmnI you can get the service account details (kubeconfig) using the following command;
When using Omni, you can get the service account kubeconfig using:
```shell
omnictl kubeconfig --service-account -c <cluster-name> --user buzz /tmp/buzz-kubeconfig.yaml