网站主持人,济南建筑公司,北京网站优化效果,软件商城app下载安卓版文章目录 一、ServiceAccount介绍二、ServiceAccount相关的资源对象三、dashboard空间示例 一、ServiceAccount介绍 ServiceAccount#xff08;服务账户#xff09;概念介绍 1#xff09;ServiceAccount是Kubernetes集群中的一种资源对象#xff0c;用于为Pod或其他资源提供… 文章目录 一、ServiceAccount介绍二、ServiceAccount相关的资源对象三、dashboard空间示例 一、ServiceAccount介绍 ServiceAccount服务账户概念介绍 1ServiceAccount是Kubernetes集群中的一种资源对象用于为Pod或其他资源提供身份验证和授权以便它们能够与Kubernetes API进行交互。 2Service Account仅局限它所在的namespace而每个namespace都会自动创建一个default service account。可以在Pod中通过serviceAccountName来指定使用哪个ServiceAccount。 解决的问题 1身份验证 ServiceAccount为Pod提供一个身份使Pod能够与Kubernetes API进行交互。Kubernetes API会根据ServiceAccount的身份进行授权判断。 2权限控制 通过ServiceAccountKubernetes管理员可以对Pod进行权限控制限制它们能够访问的资源和操作从而增强集群的安全性。 3认证和授权 ServiceAccount使得Pod可以通过自己的身份进行认证和授权而不是依赖于集群中其他的身份。
二、ServiceAccount相关的资源对象 rolek8s角色通过RoleBinding绑定相关权限。它是Namespace级别的资源,只能作用于Namespace之内。 ClusterRole集群角色 ClusterRole定义了一组权限用于控制对Kubernetes集群级别资源的访问。它是一种权限策略定义了哪些操作可以被执行。ClusterRole可以被多个命名空间使用。 RoleBindingRole或 ClusterRole只是用于制定权限集合具体作用于什么对象上需要使用 RoleBinding来进行绑定。可以将Role 或 ClusterRole绑定到User、Group、Service Account 上。 ps相关指令介绍 1查看rolebinding信息kubectl get rolebinding --all-namespaces 2查看指定rolebinding 的配置信息kubectl get rolebinding role_binding_name -n -o yaml ClusterRoleBindingRoleBinding用于在单个命名空间内进行权限控制而ClusterRoleBinding用于在整个集群内进行权限控制。 Secret秘密 Secret是用于存储敏感信息的资源如密码、API密钥、证书等。ServiceAccount通常与Secret关联Kubernetes会自动为每个ServiceAccount创建一个与之关联的Secret其中包含了ServiceAccount的身份令牌。 Service Account Admission Controller介绍 通过Admission Controller插件来实现对pod修改它是apiserver的一部分。创建或更新pod时会同步进行修改pod。当插件处于激活状态(在大多数发行版中都默认情况)创建或修改pod时会按以下操作执行 1如果pod没有设置ServiceAccount则将ServiceAccount设置为default。 2确保pod 引用的ServiceAccount存在否则将会拒绝请求。 3如果pod不包含任何ImagePullSecrets则将ServiceAccount 的 lmagePullSecrets会添加到 pod中。 4为包含API访问的Token 的 pod添加了一个volume。 5把volumeSource添加到安装在pod的每个容器中,挂载在/var/run/secrets/kubernetes.io/serviceaccount。 Service Account Controller介绍 Service Account Controller在namespaces里管理ServiceAccount并确保每个有效的 namespaces中都存在一个名为“default”的ServiceAccount。 其他相关指令介绍 1获取所有空间的ServiceAccountkubectl get sa -A 2获取所有空间的ClusterRole kubectl get clusterrole -A 3查看ClusterRole详情 kubectl get clusterrole ingress-nginx -n ingress-nginx -o yaml
三、dashboard空间示例 查看dashboard的用户列表kubectl get sa -n kubernetes-dashboard 查看用户secrets 并且获取token 1查看secrets kubectl get secrets -n kubernetes-dashboard 2获取密钥kubectl describe secrets default-token-fjzh6 -n kubernetes-dashboard 创建admin用户并且查看secrets和token 1创建访问账号vi /opt/dash.yaml 创建用户–》申明角色–》用户和角色绑定 apiVersion: v1
kind: ServiceAccount
metadata:name: admin-usernamespace: kubernetes-dashboard
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:name: admin-user
roleRef:apiGroup: rbac.authorization.k8s.iokind: ClusterRolename: cluster-admin
subjects:
- kind: ServiceAccountname: admin-usernamespace: kubernetes-dashboard2应用 kubectl apply -f /opt/dash.yaml 3查看dashboard的用户列表get sa -n kubernetes-dashboard 4查看secrets kubectl get secrets -n kubernetes-dashboard 5获取访问令牌 kubectl describe secrets admin-user-token-d8f7x -n kubernetes-dashboard 6查看绑定关系 kubectl get ClusterRoleBinding admin-user -n kubernetes-dashboard -o yaml