kubernetes Error creating: No API token found for service account “default”

近期在研究kubernetes集群,搭建过程中也中有这样那样的错误,接下来会将我这边遇到的坑一一列出来,给各位先探探路。

执行测试创建docker:

kubectl run nginxexample --image=nginx

kubectl get pods -l run=nginxexample
NAME                            READY     STATUS              RESTARTS   AGE
nginxexample-2412748312-8grvr   0/1       ContainerCreating   0          1m

日志中有很多报错:

Mar  6 11:54:01 sudops-vm04 kube-controller-manager: E0306 11:54:01.936464    3206 replica_set.go:505] unable to create pods: No API token found for service account "default", retry after the token is automatically created and added to the service account
Mar  6 11:54:01 sudops-vm04 kube-controller-manager: I0306 11:54:01.936540    3206 event.go:217] Event(api.ObjectReference{Kind:"ReplicaSet", Namespace:"default", Name:"nginxexample-2412748312", UID:"26cc3dec-0220-11e7-8463-52540017b78a", APIVersion:"extensions", ResourceVersion:"4633", FieldPath:""}): type: 'Warning' reason: 'FailedCreate' Error creating: No API token found for service account "default", retry after the token is automatically created and added to the service account
Mar  6 11:54:31 sudops-vm04 kube-controller-manager: E0306 11:54:31.937162    3206 replica_set.go:505] unable to create pods: No API token found for service account "default", retry after the token is automatically created and added to the service account
Mar  6 11:54:31 sudops-vm04 kube-controller-manager: I0306 11:54:31.937634    3206 event.go:217] Event(api.ObjectReference{Kind:"ReplicaSet", Namespace:"default", Name:"nginxexample-2412748312", UID:"26cc3dec-0220-11e7-8463-52540017b78a", APIVersion:"extensions", ResourceVersion:"4633", FieldPath:""}): type: 'Warning' reason: 'FailedCreate' Error creating: No API token found for service account "default", retry after the token is automatically created and added to the service account
Mar  6 11:55:01 sudops-vm04 systemd: Created slice user-995.slice.
Mar  6 11:55:01 sudops-vm04 systemd: Starting user-995.slice.
Mar  6 11:55:01 sudops-vm04 systemd: Started Session 1271 of user pcp.
Mar  6 11:55:01 sudops-vm04 systemd: Starting Session 1271 of user pcp.
Mar  6 11:55:01 sudops-vm04 systemd: Removed slice user-995.slice.
Mar  6 11:55:01 sudops-vm04 systemd: Stopping user-995.slice.
Mar  6 11:55:01 sudops-vm04 kube-controller-manager: E0306 11:55:01.936908    3206 replica_set.go:505] unable to create pods: No API token found for service account "default", retry after the token is automatically created and added to the service account
Mar  6 11:55:01 sudops-vm04 kube-controller-manager: I0306 11:55:01.937365    3206 event.go:217] Event(api.ObjectReference{Kind:"ReplicaSet", Namespace:"default", Name:"nginxexample-2412748312", UID:"26cc3dec-0220-11e7-8463-52540017b78a", APIVersion:"extensions", ResourceVersion:"4633", FieldPath:""}): type: 'Warning' reason: 'FailedCreate' Error creating: No API token found for service account "default", retry after the token is automatically created and added to the service account

下面是解决办法:

# cat /etc/kubernetes/apiserver
去掉SecurityContextDeny,ServiceAccount
编辑如下行:
#KUBE_ADMISSION_CONTROL="--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ServiceAccount,ResourceQuota"
改成:
KUBE_ADMISSION_CONTROL="--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,ResourceQuota"

重启kube-apiserver服务
# systemctl restart kube-apiserver.service

稍后可以再次看下,pod状态:

# kubectl get pods -l run=nginxexample
NAME                            READY     STATUS    RESTARTS   AGE
nginxexample-2412748312-8grvr   1/1       Running   0          1h

u2

Related Posts

rancher v2.x 初体验

rancher v2x

Docker下如何导入导出neo4j数据

[摘要] 运行在Docker容器中的neo4j数据库,如何使…

You Missed

从”养虾”到AI Agent爆发:2026年技术圈的新范式转移

  • u2
  • 3月 9, 2026
  • 17 views

提示词注入:AI时代最危险的漏洞,正在吞噬你的数据

  • u2
  • 3月 7, 2026
  • 48 views
提示词注入:AI时代最危险的漏洞,正在吞噬你的数据

潘多拉魔盒已打开:开源AI攻击平台正在血洗全球防火墙

  • u2
  • 3月 4, 2026
  • 83 views
潘多拉魔盒已打开:开源AI攻击平台正在血洗全球防火墙

雇佣AI员工,花钱上班:开发者的新”职场”荒诞剧

  • u2
  • 3月 1, 2026
  • 71 views
雇佣AI员工,花钱上班:开发者的新”职场”荒诞剧

OpenClaw 完整使用指南:自托管 AI Agent 的架构与实战

  • u2
  • 2月 25, 2026
  • 193 views
OpenClaw 完整使用指南:自托管 AI Agent 的架构与实战

Anthropic 推出 Claude Code Security:AI 驱动的代码安全神器

  • u2
  • 2月 24, 2026
  • 108 views