阿里云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
相关推荐
键盘鼓手苏苏8 小时前
Kubernetes与GitOps最佳实践
云原生·kubernetes·k8
运维行者_14 小时前
使用 Applications Manager 实现 AWS 云监控:保障业务应用高效运行
大数据·运维·服务器·网络·数据库·云计算·aws
明天…ling15 小时前
Xshell远程连接阿里云ECS超详细教程
阿里云·云计算
云布道师17 小时前
【云故事探索】NO.24 | 让教育因云而无界:易康思科技如何用阿里云打破“算力孤岛”?
科技·阿里云·云计算
今夕资源网18 小时前
uvr5下载 人声伴奏分离软件 Ultimate Vocal Remover 终极声乐去除器 GUI v5.6
云计算·uvr5·uvr5下载·人声伴奏分离软件·人声分离软件·人生分离·伴奏分离
恼书:-(空寄19 小时前
K8s Ingress 七层网关 + 灰度发布 + HTTPS 实战
容器·kubernetes
不是书本的小明19 小时前
ACK+ESS实现K8s节点自动扩缩容
容器·kubernetes
恼书:-(空寄20 小时前
Docker Swarm + K8s 集群部署完整指南
docker·容器·kubernetes
admin and root21 小时前
AWS S3 对象存储攻防&云安全之OSS存储桶漏洞
微信小程序·小程序·渗透测试·云计算·aws·src·攻防演练