I just created a namespace, have done nothing with it and now deleted it. However, when I list contexts I can still see it there. It seems to have been deleted as I can't delete it again. Why can I still see it listed when I get contexts?
kubectl config get-contexts
CURRENT NAME CLUSTER AUTHINFO NAMESPACE
* dev minikube minikube dev
minikube minikube minikube
kubectl delete namespace dev
namespace "dev" deleted
kubectl config get-contexts
CURRENT NAME CLUSTER AUTHINFO NAMESPACE
* dev minikube minikube dev
minikube minikube minikube
I switched contexts just in case but still get the same problem. E.g.
kubectl delete namespace dev
Error from server (NotFound): namespaces "dev" not found
kubectl config get-contexts
CURRENT NAME CLUSTER AUTHINFO NAMESPACE
dev minikube minikube dev
* minikube minikube minikube
Interestingly, I don't see it when I list namespaces. E.g.
kubectl get namespaces
答案 0 :(得分:2)
context
中的kubectl
只是一个本地配置,其中包含有关特定集群或名称空间的详细信息(元数据)。这是使用kubectl
客户端进行群集/命名空间管理所需的配置。
因此,当您键入kubectl config <any_command>
时,它只是在计算机本地存储的文件中进行查找。
运行以下命令以了解有关此命令以及如何控制配置文件位置的更多信息:
kubectl config --help
删除集群或名称空间不会删除关联的上下文。原因是删除集群或名称空间是在集群上运行的异步操作。实际完成此操作可能需要几秒钟的时间。因此,kubectl
无法在将删除操作发布给集群主服务器后立即从配置文件中删除上下文。
要回答您的问题,您必须使用以下方法手动删除上下文:
kubectl config delete-context dev