阿里云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同一账号下创建自定义VPC并配置不同区域的对等链接
网络·云计算·aws
東雪蓮☆3 小时前
K8s 平滑升级
linux·运维·云原生·kubernetes
AKAMAI3 小时前
数据孤岛破局之战 :跨业务分析的难题攻坚
运维·人工智能·云计算
三坛海会大神5558 小时前
k8s(十)Helm详解
云原生·容器·kubernetes
K_i1349 小时前
Kubernetes流量管理:从Ingress到GatewayAPI演进
云原生·容器·kubernetes
蓝色土耳其love10 小时前
centos 7.9 安装单机版k8s
linux·运维·服务器·kubernetes·centos
小熊h13 小时前
Kubernetes(K8s) —— 部署(保姆级教程)
云原生·容器·kubernetes
@HNUSTer14 小时前
基于 GEE 的 MODIS 昼夜地表温度数据可视化与导出全流程解决方案
云计算·数据集·遥感大数据·gee·云平台·modis·地表温度(lst)
王道长服务器 | 亚马逊云17 小时前
AWS WAF 实战篇|如何防御爬虫、CC攻击与恶意POST请求
云计算·aws
@HNUSTer17 小时前
基于 GEE MODIS 数据实现 7 大遥感指数计算与可视化
云计算·数据集·遥感大数据·gee·云平台·modis·遥感指数