• kubernetes secret 和 serviceaccount删除


    背景

    今天通过配置创建了一个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
  • 相关阅读:
    latex之插入伪代码 [转]
    BIBTeX制作参考文献 [转]
    latex 页眉设置 [转]
    python : list tuple set dictionary [转]
    ctags使用简介 [转]
    conda在指定目录下创建虚拟环境
    Ubuntu系统安装Anaconda3
    ModuleNotFoundError: No module named 'google' 问题解决方案
    PyCharm无法输入中文
    checkpoint文件
  • 原文地址:https://www.cnblogs.com/williamzheng/p/11464883.html
Copyright © 2020-2023  润新知