---apiVersion: v1kind: ServiceAccountmetadata:name: hivesec-central-salabels:name: hivesec-central-sarole: securitynamespace: hivesec---apiVersion: rbac.authorization.k8s.io/v1kind: ClusterRolemetadata:name: hivesec-central-crlabels:name: hivesec-central-crrole: securityrules:- apiGroups: ["", "extensions", "apps", "batch"] #支持api组的列表," ":表示核心api群resources: ["namespaces", "nodes", "pods", "services", "endpoints", "daemonsets", "configmaps", "deployments", "replicationcontrollers", "replicasets", "statefulsets", "jobs", "cronjobs"] #支持的资源对象列表verbs: ["get", "list", "watch"] # 允许对资源对象操作方法列表【上面的意思结合起来就是,security用户对apiGroups的resources有verbs的操作权限】- apiGroups: [""]resources: ["services/proxy"]resourceNames: ["heapster", "http:heapster", "https:heapster"]verbs: ["get"]- apiGroups: ["metrics.k8s.io"]resources: ["pods", "nodes", "configmaps", "nodes/stats"]verbs: ["get", "list"]---apiVersion: rbac.authorization.k8s.io/v1kind: ClusterRoleBindingmetadata:name: hivesec-central-crblabels:name: hivesec-central-crbrole: securityroleRef:apiGroup: rbac.authorization.k8s.iokind: ClusterRolename: hivesec-central-crsubjects:- kind: ServiceAccountname: hivesec-central-sanamespace: hivesec---apiVersion: rbac.authorization.k8s.io/v1kind: Rolemetadata:namespace: hivesecname: hivesec-central-rolelabels:name: hivesec-central-rolerules:- apiGroups: ["", "extensions", "apps"]resources: ["pods", "services", "endpoints", "daemonsets", "configmaps", "deployments"]verbs: ["get", "list", "create", "delete", "update"]---apiVersion: rbac.authorization.k8s.io/v1kind: RoleBinding #角色绑定,将同一个namespace中的subject绑定到某个Role下metadata:namespace: hivesecname: hivesec-central-roblabels:name: hivesec-central-robroleRef: #指向的角色apiGroup: rbac.authorization.k8s.iokind: Rolename: hivesec-central-rolesubjects: #定义用户- kind: ServiceAccountname: hivesec-central-sanamespace: hivesec【将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 里保存的信息了。
