Files
jenkins-pipeline/k8s_yaml/ServiceAccount/Jenkins.yaml
2025-11-03 09:25:50 +08:00

34 lines
1.1 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 创建 ServiceAccount放在任意命名空间这里用 default 举例)
apiVersion: v1
kind: ServiceAccount
metadata:
name: jenkins-deployer
namespace: default # 明确 ServiceAccount 所在的命名空间(必填)
---
# 为 test-lessie 命名空间创建 Role仅允许操作 test-lessie 下的资源)
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: jenkins-test-role
namespace: test-lessie # 绑定到 test-lessie 命名空间
rules:
- apiGroups: ["", "apps", "extensions"]
resources: ["pods", "deployments", "services", "configmaps", "secrets"]
verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]
---
# 将 test-lessie 命名空间的 Role 绑定到 ServiceAccount
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: jenkins-test-binding
namespace: test-lessie # 与 Role 同命名空间
subjects:
- kind: ServiceAccount
name: jenkins-deployer
namespace: default # 注意:这里是 SA 所在的命名空间default
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: jenkins-test-role