背景
今天通過配置創建了一個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]#
