阿里云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
相关推荐
wanhengidc18 分钟前
海外云手机是指什么
运维·服务器·游戏·智能手机·云计算
AWS官方合作商1 小时前
AWS Lambda的安全之道:S3静态加密与运行时完整性检查的双重保障
安全·云计算·aws
skyeeeeee2 小时前
kubeadm安装k8s集群
后端·kubernetes
高旭博4 小时前
7. kubernetes资源——service服务
云原生·容器·kubernetes
skywalk81634 小时前
阿里云服务器FreeBSD新系统从登录、配置到升级:从14.1升级到FreeBSD 14.3 Release
linux·服务器·阿里云·freebsd
boonya13 小时前
ChatBox AI 中配置阿里云百炼模型实现聊天对话
人工智能·阿里云·云计算·chatboxai
AKAMAI14 小时前
AI 边缘计算:决胜未来
人工智能·云计算·边缘计算
天一生水water16 小时前
ubuntu使用毫秒镜像方式安装docker mysql
ubuntu·阿里云·docker
阿里云云原生16 小时前
阿里云微服务引擎 MSE 及 API 网关 2025 年 10 月产品动态
阿里云·微服务·云原生·云计算