阿里云k8s如何创建可用的api token

阿里云的 Kubernetes 配置文件(如您所提供的 YAML 格式文件)通常不会直接包含用于连接 Kubernetes 集群的令牌。而是包含了客户端证书和私钥数据,这些是用于通过证书验证而不是令牌验证的方式来与 Kubernetes API 服务器进行安全交互的。

1.创建一个 ServiceAccount:

复制代码
kubectl create serviceaccount [service-account-name]

2.通过 YAML 文件创建 ClusterRoleBinding

复制代码
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: example-clusterrolebinding
subjects:
- kind: ServiceAccount
  name: example-serviceaccount
  namespace: example-namespace
roleRef:
  kind: ClusterRole
  name: example-clusterrole
  apiGroup: rbac.authorization.k8s.io

3.手动创建服务账号令牌

复制代码
apiVersion: v1
kind: Secret
metadata:
  name: [secret-name]
  namespace: [your-namespace]
  annotations:
    kubernetes.io/service-account.name: [service-account-name]
type: kubernetes.io/service-account-token

4.定义pod-exec-role

复制代码
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  namespace: your-namespace
  name: pod-exec-role
rules:
- apiGroups: [""]
  resources: ["pods/exec", "pods/log"]
  verbs: ["create", "get", "list"]

5.创建ClusterRoleBinding

复制代码
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: pod-exec-binding
  namespace: your-namespace
subjects:
- kind: User
  name: "your-username"
  apiGroup: rbac.authorization.k8s.io
roleRef:
  kind: Role
  name: pod-exec-role
  apiGroup: rbac.authorization.k8s.io

6.创建view的roleBinding

复制代码
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: cao-crb
subjects:
- kind: User
  name: "your-username"  # 替换为实际的用户名
  apiGroup: rbac.authorization.k8s.io
roleRef:
  kind: ClusterRole
  name: view  # 确保这是正确的 ClusterRole 名称
  apiGroup: rbac.authorization.k8s.io
相关推荐
三不原则3 小时前
故障案例:容器启动失败排查(AI运维场景)——从日志分析到根因定位
运维·人工智能·kubernetes
孤岛悬城3 小时前
54 安装k8s-1.20.11
云原生·容器·kubernetes
AKAMAI5 小时前
分布式边缘推理正在改变一切
人工智能·分布式·云计算
dmonstererer8 小时前
【k8s设置污点/容忍】
java·容器·kubernetes
Serverless社区8 小时前
AgentRun 实战:快速构建 AI 舆情实时分析专家
阿里云·云原生·serverless·函数计算
VermiliEiz10 小时前
二进制文件部署k8s方式(4)
云原生·容器·kubernetes
2501_9418036211 小时前
在奥斯陆智能水利场景中构建实时水资源调度与高并发水质数据分析平台的工程设计实践经验分享
数据挖掘·数据分析·云计算
咕噜企业分发小米11 小时前
阿里云AI教育产品如何助力企业提升客户粘性?
人工智能·microsoft·阿里云
oMcLin11 小时前
如何在CentOS 8上配置并优化Docker与Kubernetes结合的容器集群,提升微服务部署效率?
docker·kubernetes·centos
翼龙云_cloud11 小时前
阿里云渠道商:阿里云自动扩缩容配置教程
运维·服务器·阿里云·云计算