未找到命名空间

A. *_*ner 5 namespaces kubernetes minikube

我在运行部署时看到以下错误:

Error from server (NotFound): error when creating "n3deployment.yaml": namespaces "n2" not found

我的 n3deployment.yaml 没有提到 n2?

一步步

  1. 确保一切都是空的
c:\temp\k8s>kubectl get pods
No resources found.

c:\temp\k8s>kubectl get svc
No resources found.

c:\temp\k8s>kubectl get deployments
No resources found.

c:\temp\k8s>kubectl get namespaces
NAME          STATUS    AGE
default       Active    20h
docker        Active    20h
kube-public   Active    20h
kube-system   Active    20h
Run Code Online (Sandbox Code Playgroud)
  1. 创建文件
n3namespace.yaml
apiVersion: v1
kind: Namespace
metadata:
  name: n3

n3service.yaml
apiVersion: v1
kind: Service
metadata:
  name: my-app-n3
  namespace: n3
  labels:
    app: my-app-n3
spec:
  type: LoadBalancer
  ports:
  - name: http
    port: 80
    targetPort: http
    protocol: TCP
  selector:
    app: my-app-n3

n3deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app-n3
  labels:
    app: my-app-n3
spec:
  replicas: 1
  selector:
    matchLabels:
      app: my-app-n3
  template:
    metadata:
      labels:
        app: my-app-n3
    spec:
      containers:
      - name: waiter
        image: waiter:v1
        ports:
        - containerPort: 80
Run Code Online (Sandbox Code Playgroud)
  1. 应用配置
c:\temp\k8s>kubectl apply -f n3namespace.yaml
namespace "n3" created

c:\temp\k8s>kubectl apply -f n3service.yaml
service "my-app-n3" created

c:\temp\k8s>kubectl apply -f n3deployment.yaml
Error from server (NotFound): error when creating "n3deployment.yaml": namespaces "n2" not found
Run Code Online (Sandbox Code Playgroud)

我曾经有一个命名空间,n2但正如您所见,它不再存在。

dav*_*rez 6

就我而言,我之前没有执行过:

kubectl create namespace n3
Run Code Online (Sandbox Code Playgroud)


A. *_*ner 3

我之前创建了两个上下文,并且我的 minikube 集群仍设置在该n2上下文中。我删除了上下文,重新运行命令,它起作用了。