阿里云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
相关推荐
workflower26 分钟前
AI 产业链带动效应加速,催生AI 原生企业
人工智能·机器学习·机器人·云计算·无人机
安易算力1 小时前
GPU集群调度实践:Slurm/K8s混合部署与GPU共享优化 —— 从批处理到在线推理的统一调度架构
容器·架构·kubernetes
GPU实战笔记16 小时前
云端服务启动后浏览器访问失败:先查端口链路还是重装应用?
云计算·web服务·故障排查·端口访问
sbjdhjd19 小时前
云安全 | Docker 容器逃逸复盘(二):2375 未授权接口如何突破容器管理边界
网络安全·docker·云原生·数据挖掘·开源·云计算·云安全
star_start_sky1 天前
华为认证 HCIA、HCIP、HCIE 怎么选?数通、云、存储、安全路线详解
华为云·云计算·华为认证·技术学习·备考指南
翼龙云_cloud1 天前
阿里云国际代理商:ECS部署DeepSeek大模型指南
服务器·阿里云·大模型·云计算
MrSYJ1 天前
Docker端口映射咋做的,模拟下。
docker·云原生·kubernetes
GPU实战笔记1 天前
云端任务输出增长后:本地扩容数据盘与项目网盘的关机计费边界
云计算·gpu租用·云端gpu·存储计费·项目网盘
张小凡vip1 天前
Kubernetes--k8s---了解和使用configmap挂载配置文件
云原生·容器·kubernetes
小小龙学IT2 天前
Kubernetes 深度实践:架构、API 与避坑指南
容器·架构·kubernetes