认证 证书申请信息 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Country Name (2 letter code) [XX]: 国家 State or Province Name (full name) []: 省 Locality Name (eg, city) [Default City]: 市 Organization Name (eg, company) [Default Company Ltd]: 组织名称 Organizational Unit Name (eg, section) []: 组织单位名称 Common Name (eg, your name or your server's hostname) []: 主机名 对应简写 C 国家 ST 省 L 城市 O 组织名称 # 对应K8S的组名 OU 组织单位名称 CN 主机名 # 对应K8S的用户名
查看K8S资源 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 # 非名称空间级别的资源(集群资源) [root@master1 ~]# kubectl api-resources --namespaced=false NAME SHORTNAMES APIVERSION NAMESPACED KIND componentstatuses cs v1 false ComponentStatus namespaces ns v1 false Namespace nodes no v1 false Node persistentvolumes pv v1 false PersistentVolume mutatingwebhookconfigurations admissionregistration.k8s.io/v1 false MutatingWebhookConfiguration validatingwebhookconfigurations admissionregistration.k8s.io/v1 false ValidatingWebhookConfiguration customresourcedefinitions crd,crds apiextensions.k8s.io/v1 false CustomResourceDefinition ... ... # 名称空间级别的资源 [root@master1 ~]# kubectl api-resources --namespaced=true NAME SHORTNAMES APIVERSION NAMESPACED KIND bindings v1 true Binding configmaps cm v1 true ConfigMap endpoints ep v1 true Endpoints events ev v1 true Event limitranges limits v1 true LimitRange persistentvolumeclaims pvc v1 true PersistentVolumeClaim pods po v1 true Pod podtemplates v1 true PodTemplate replicationcontrollers rc v1 true ReplicationController resourcequotas quota v1 true ResourceQuota secrets v1 true Secret serviceaccounts sa v1 true ServiceAccount services svc v1 true Service controllerrevisions apps/v1 true ControllerRevision daemonsets ds apps/v1 true DaemonSet deployments deploy apps/v1 true Deployment replicasets rs apps/v1 true ReplicaSet statefulsets sts apps/v1 true StatefulSet localsubjectaccessreviews authorization.k8s.io/v1 true LocalSubjectAccessReview horizontalpodautoscalers hpa autoscaling/v2 true HorizontalPodAutoscaler cronjobs cj batch/v1 true CronJob jobs batch/v1 true Job ... ...
RBAC RBAC API声明了四种Kubernetes对象:
1 2 3 4 5 User------RoleBinding-------------Role # 名称空间资源 授予对某一个名称空间级别资源的权限(限制在名称空间中) User------RoleBinding-------------ClusterRole # 名称空间资源(包含多个) 授予对多个名称空间级别资源的权限(限制在多个名称空间中,不能对集群资源进行操作) User------ClusterRoleBinding------ClusterRole # 集群资源
主体
User(用户)
Group(组)
ServiceAccount(SA服务账号)
权限
create (创建)
delete(删除)
deletecollection(删除集合)
get(获取)
list(列出)
patch(补丁)
update(更新)
watch(查看)
*(所有)
Role 1 2 3 4 5 6 7 8 9 apiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: namespace: default name: pod-reader rules: - apiGroups: ["" ] resources: ["pods" ] verbs: ["get" , "watch" , "list" ]
ClusterRole 1 2 3 4 5 6 7 8 9 10 apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: name: secret-reader rules: - apiGroups: ["" ] resources: ["secrets" ] verbs: ["get" , "watch" , "list" ]
RoleBinding 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 apiVersion: rbac.authorization.k8s.io/v1 kind: RoleBinding metadata: name: read-pods namespace: default subjects: - kind: User name: jane apiGroup: rbac.authorization.k8s.io roleRef: kind: Role name: pod-reader apiGroup: rbac.authorization.k8s.io ======================================================= apiVersion: rbac.authorization.k8s.io/v1 kind: RoleBinding metadata: name: read-secrets namespace: development subjects: - kind: User name: dave apiGroup: rbac.authorization.k8s.io roleRef: kind: ClusterRole name: secret-reader apiGroup: rbac.authorization.k8s.io
ClusterRoleBinding 1 2 3 4 5 6 7 8 9 10 11 12 13 apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: read-secrets-global subjects: - kind: Group name: manager apiGroup: rbac.authorization.k8s.io roleRef: kind: ClusterRole name: secret-reader apiGroup: rbac.authorization.k8s.io
对资源的引用 子资源 1 2 3 4 5 6 7 8 9 10 apiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: namespace: default name: pod-and-pod-logs-reader rules: - apiGroups: ["" ] resources: ["pods" , "pods/log" ] verbs: ["get" , "list" ]
单实例 1 2 3 4 5 6 7 8 9 10 11 12 apiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: namespace: default name: configmap-updater rules: - apiGroups: ["" ] resources: ["configmaps" ] resourceNames: ["my-configmap" ] verbs: ["update" , "get" ]
所有资源 1 2 3 4 5 6 7 8 9 apiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: namespace: default name: example.com-superuser rules: - apiGroups: ["" ] resources: ["*" ] verbs: ["*" ]
API组 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 apiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: namespace: default name: example.com-superuser rules: - apiGroups: ["apps" ] resources: ["deployments" ] verbs: ["get" , "list" , "watch" , "create" , "update" , "patch" , "delete" ] ============================================= apiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: namespace: default name: example.com-superuser rules: - apiGroups: ["apps" ] resources: ["*" ] verbs: ["get" , "list" , "watch" , "create" , "update" , "patch" , "delete" ] ============================================== apiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: namespace: default name: example.com-superuser rules: - apiGroups: ["apps" ] resources: ["deployments" ] resourcesName: ["具体deploy的名称" ] verbs: ["get" , "list" , "watch" , "create" , "update" , "patch" , "delete" ]
apps包含如下资源
1 2 3 4 5 6 [root@xiaowangc ~]# kubectl api-resources --namespaced | grep apps controllerrevisions apps/v1 true ControllerRevision daemonsets ds apps/v1 true DaemonSet deployments deploy apps/v1 true Deployment replicasets rs apps/v1 true ReplicaSet statefulsets sts apps/v1 true StatefulSet
资源查看命令 1 2 3 4 5 6 7 8 [root@master1 ~ ] [root@master1 ~ ] [root@master1 ~ ] [root@master1 ~ ]