1. ---
  2. apiVersion: v1
  3. kind: ServiceAccount
  4. metadata:
  5. name: hivesec-central-sa
  6. labels:
  7. name: hivesec-central-sa
  8. role: security
  9. namespace: hivesec
  10. ---
  11. apiVersion: rbac.authorization.k8s.io/v1
  12. kind: ClusterRole
  13. metadata:
  14. name: hivesec-central-cr
  15. labels:
  16. name: hivesec-central-cr
  17. role: security
  18. rules:
  19. - apiGroups: ["", "extensions", "apps", "batch"] #支持api组的列表," ":表示核心api群
  20. resources: ["namespaces", "nodes", "pods", "services", "endpoints", "daemonsets", "configmaps", "deployments", "replicationcontrollers", "replicasets", "statefulsets", "jobs", "cronjobs"] #支持的资源对象列表
  21. verbs: ["get", "list", "watch"] # 允许对资源对象操作方法列表
  22. 【上面的意思结合起来就是,security用户对apiGroupsresourcesverbs的操作权限】
  23. - apiGroups: [""]
  24. resources: ["services/proxy"]
  25. resourceNames: ["heapster", "http:heapster", "https:heapster"]
  26. verbs: ["get"]
  27. - apiGroups: ["metrics.k8s.io"]
  28. resources: ["pods", "nodes", "configmaps", "nodes/stats"]
  29. verbs: ["get", "list"]
  30. ---
  31. apiVersion: rbac.authorization.k8s.io/v1
  32. kind: ClusterRoleBinding
  33. metadata:
  34. name: hivesec-central-crb
  35. labels:
  36. name: hivesec-central-crb
  37. role: security
  38. roleRef:
  39. apiGroup: rbac.authorization.k8s.io
  40. kind: ClusterRole
  41. name: hivesec-central-cr
  42. subjects:
  43. - kind: ServiceAccount
  44. name: hivesec-central-sa
  45. namespace: hivesec
  46. ---
  47. apiVersion: rbac.authorization.k8s.io/v1
  48. kind: Role
  49. metadata:
  50. namespace: hivesec
  51. name: hivesec-central-role
  52. labels:
  53. name: hivesec-central-role
  54. rules:
  55. - apiGroups: ["", "extensions", "apps"]
  56. resources: ["pods", "services", "endpoints", "daemonsets", "configmaps", "deployments"]
  57. verbs: ["get", "list", "create", "delete", "update"]
  58. ---
  59. apiVersion: rbac.authorization.k8s.io/v1
  60. kind: RoleBinding #角色绑定,将同一个namespace中的subject绑定到某个Role下
  61. metadata:
  62. namespace: hivesec
  63. name: hivesec-central-rob
  64. labels:
  65. name: hivesec-central-rob
  66. roleRef: #指向的角色
  67. apiGroup: rbac.authorization.k8s.io
  68. kind: Role
  69. name: hivesec-central-role
  70. subjects: #定义用户
  71. - kind: ServiceAccount
  72. name: hivesec-central-sa
  73. namespace: hivesec
  74. 【将hivesec-central-role角色绑定到ServiceAccount用户上,用户就拥有了角色的权限。】

https://zhuanlan.zhihu.com/p/121736064

ServiceAccount

kubernetes管理的账号,用于为Pod中的服务进程在访问Kubernetes时提供身份标识。

ClusterRole:在集群中的角色
Role:在命名空间中的角色

kubectl create secret docker-registry hivesec-secret --namespace=hivesec \
    --docker-server=192.168.222.140/hivesec \
    --docker-username='admin' \
    --docker-password='Harbor12345'

k8s secrets用于存储和管理一些敏感数据,比如密码,token,密钥等敏感信息。它把 Pod 想要访问的加密数据存放到 Etcd 中。然后用户就可以通过在 Pod 的容器里挂载 Volume 的方式或者环境变量的方式访问到这些 Secret 里保存的信息了。