相关参考文章
LOOKLOOK项目里相遇相关问题描述 链接
官方微信公众号相关参考文章 链接
原理请看上面的文章理解,这里记录步骤和代码
第一步:创建命名空间 my-gozero-namespace
第二步:创建账号 gozero-find-endpoints
点击右上角YAML创建资源
apiVersion: v1
kind: ServiceAccount
metadata:
namespace: my-gozero-namespace
name: gozero-find-endpoints
查看一下账号是否新建成功,这个账号是某个命名空间的,注意查看的时候选择命名空间
第三步:创建集群角色 gozero-discov-endpoints
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: gozero-discov-endpoints
rules:
- apiGroups: [""]
resources: ["endpoints"]
verbs: ["get","list","watch"]
同理检查下可视化页面 角色是否创建成功
第四步创建账户和集群角色绑定关系
在授权管理---->ClusterRoleBinding里查看
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: gozero-find-endpoints-discov-endpoints
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: gozero-discov-endpoints
subjects:
- kind: ServiceAccount
name: gozero-find-endpoints
namespace: my-gozero-namespace
同理检查下可视化页面 角色是否创建成功
第五步 特别注意Deployment创建pod的时候需要制定账户
可视化新建Deployment或者StatefulSet,编辑yaml文件新增serviceAccountName(SA)
spec---->template--->spec--->serviceAccountName设置成gozero-find-endpoints
serviceAccountName: gozero-find-endpoints
新增后效果
下面是参考资料,其实就是可视化生成以后在 参考资料
apiVersion: apps/v1
kind: Deployment
metadata:
name: alpine-deployment
labels:
app: alpine
spec:
replicas: 1
selector:
matchLabels:
app: alpine
template:
metadata:
labels:
app: alpine
spec:
serviceAccountName: gozero-find-endpoints
containers:
- name: alpine
image: alpine
command:
- sleep
- infinity
最后还是说看透开头的两篇文章的核心思路
快捷设置1
#创建账号
apiVersion: v1
kind: ServiceAccount
metadata:
namespace: demo # 修改点1命名空间
name: demo-account # 修改点2账户名称
---
#创建角色对应操作
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: goZero #修改点3角色名称
rules:
- apiGroups: [""]
resources: ["endpoints"]
verbs: ["get","list","watch"]
---
#给账号绑定角色
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: demo-goZero #修改点4绑定关系名称
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: goZero #修改点5角色名称
subjects:
- kind: ServiceAccount
name: demo-account #修改点6账户名称
namespace: demo #修改点7账户名称对应的命名空间
快捷设置2
serviceAccountName: demo-account