kubernetes secret 和 serviceaccount删除
2019-09-05 11:39 williamzheng 阅读(5389) 评论(0) 编辑 收藏 举报背景
今天通过配置创建了一个serviceaccounts和secret,后面由于某种原因想再次创建发现已存在一个serviceaccounts和rolebindings.rbac.authorization.k8s.io,如下:
[root@master mysql-operator-master]# cat <<EOF | kubectl create -f -
> apiVersion: v1
> kind: ServiceAccount
> metadata:
> name: mysql-agent
> namespace: mysql-operator
> ---
> kind: RoleBinding
> apiVersion: rbac.authorization.k8s.io/v1beta1
> metadata:
> name: mysql-agent
> namespace: mysql-operator
> roleRef:
> apiGroup: rbac.authorization.k8s.io
> kind: ClusterRole
> name: mysql-agent
> subjects:
> - kind: ServiceAccount
> name: mysql-agent
> namespace: mysql-operator
> EOF
Error from server (AlreadyExists): error when creating "STDIN": serviceaccounts "mysql-agent" already exists
Error from server (AlreadyExists): error when creating "STDIN": rolebindings.rbac.authorization.k8s.io "mysql-agent" already exists
解决过程
于是删除这两个东西,删不掉,如下:
[root@master mysql-operator-master]# kubectl get sa
NAME SECRETS AGE
default 1 33d
mysql-agent 1 15m
[root@master mysql-operator-master]# kubectl delete secret mysql-agent
Error from server (NotFound): secrets "mysql-agent" not found
[root@master mysql-operator-master]# kubectl get sa
NAME SECRETS AGE
default 1 33d
mysql-agent 1 16m
[root@master mysql-operator-master]#
尝试换了一个命令,提示删掉了,但是查看依然存在
[root@master mysql-operator-master]# kubectl delete serviceaccount -n mysql-operator mysql-agent
serviceaccount "mysql-agent" deleted
You have new mail in /var/spool/mail/root
[root@master mysql-operator-master]# kubectl get sa
NAME SECRETS AGE
default 1 33d
mysql-agent 1 25m
再次删除sa,这次不指定ns,删除成功
[root@master mysql-operator-master]# kubectl delete serviceaccounts mysql-agent
serviceaccount "mysql-agent" deleted
[root@master mysql-operator-master]#
[root@master mysql-operator-master]# kubectl get serviceaccounts
NAME SECRETS AGE
default 1 33d
[root@master mysql-operator-master]#
WilliamZheng©版权所有 转载请注明出处! 觉得对您有帮助请点个赞哟~ 运维架构师群:833329925