阿里云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
相关推荐
练习两年半的工程师1 小时前
AWS TechFest 2025: 适合使用 Agentic AI 的场景、代理(Agents)应用的平衡之道、数据战略优先级矩阵、新治理模式
人工智能·云计算·aws
pwj去战斗吧2 小时前
k8s+jenkins+harbor构建Devops平台
kubernetes·jenkins·devops
ChaITSimpleLove3 小时前
零代码入侵:Kubernetes 部署时自动注入 kube-system UID 到 .NET 9 环境变量
kubernetes·.net·环境变量·uid·kube-system·集群环境唯一id
观测云4 小时前
AWS SQS 可观测性最佳实践
云计算·aws
無名之輩4 小时前
Nvidia Device Plugin入门三之volume mount策略
kubernetes
TG_yunshuguoji6 小时前
阿里云国际代理:云数据库RDS及上云方案
服务器·数据库·阿里云·云计算
秃头菜狗6 小时前
下载CentOS 7——从阿里云上下载不同版本的 CentOS 7
linux·阿里云·centos
Lin_Aries_04216 小时前
使用阿里云容器镜像服务 ACR
linux·阿里云·docker·云原生·centos·云计算
Clownseven6 小时前
阿里云ECS安装Windows Server 2022教程 | 纯文字分步指南
windows·阿里云·云计算
TG_yunshuguoji6 小时前
阿里云国际代理:稳定、高效、便捷的数据库服务-云数据库RDS
运维·服务器·数据库·阿里云·云计算