阿里云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
相关推荐
行者Sun19891 小时前
【羊毛资源】华为云开发者云主机免费申请使用指南
华为云·云计算·开发环境·云桌面·云服务器·免费资源
颜淡慕潇2 小时前
【K8S系列】深入解析 Kubernetes 网络策略(二)
网络·容器·kubernetes·网络策略
阿里云大数据AI技术3 小时前
云栖实录 | 开源大数据全面升级:Native 核心引擎、Serverless 化、湖仓架构引领云上大数据发展
大数据·阿里云·开源·serverless·云栖大会
jokeWorld3 小时前
阿里云部署1Panel(失败版)
阿里云·云计算
csncn213 小时前
阿里云k8s发布vue项目
vue.js·阿里云·kubernetes
小美哥13143 小时前
yum使用阿里云的镜像源报错 Failed connect to mirrors.aliyuncs.com:80; Connection refused“
linux·运维·服务器·阿里云·云计算
zqh176736464693 小时前
阿里云ACP认证考试题库
大数据·数据库·人工智能·阿里云·云计算
nfgo3 小时前
一次阿里云ECS免费试用实践
阿里云·云计算
成都渲染101云渲染66664 小时前
渲染太慢?Maya云渲染教程
云计算·图形渲染