'Kubernetes: Error from server (NotFound): deployments.apps "kube-verify" not found

I set up a Kubernetes cluster in my private network and managed to deploy a test pods:

now I want to expose an external ip for the service:

but when I run:

kubectl get deployments kube-verify

i get:

Error from server (NotFound): deployments.apps "kube-verify" not found

EDIT Ok I try a new approach: i have made a namespace called: verify-cluster

My deployment.yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: verify-cluster
  namespace: verify-cluster
  labels:
    app: verify-cluster
spec:
  replicas: 1
  selector:
    matchLabels:
      app: verify-cluster
  template:
    metadata:
      labels:
        app: verify-cluster
    spec:
      containers:
      - name: nginx
        image: nginx:1.18.0
        ports:
        - containerPort: 80

and service.yaml:

apiVersion: v1
kind: Service
metadata:
  name: verify-cluster
  namespace: verify-cluster
spec:
  type: NodePort
  selector:
    app: verify-cluster
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
      nodePort: 30007

then I run:

kubectl create -f deployment.yaml
kubectl create -f service.yaml

than checking

kubectl get all -n verify-cluster

but than I want to check deployment with:

kubectl get all -n verify-cluster

and get:

Error from server (NotFound): deployments.apps "verify-cluster" not found

hope that's better for reproduction ?

EDIT 2 when I deploy it to default namespace it runs directly so the issue must be something in the namespace



Solution 1:[1]

I guess that you might have forgotten to create the namespace:

File my-namespace.yaml

apiVersion: v1
kind: Namespace
metadata:
  name: <insert-namespace-name-here>

Then:

kubectl create -f ./my-namespace.yaml

Solution 2:[2]

I have replicated the use case with the config files you have provided. Everything works well at my end. Make sure that namespace is created correctly without any typo errors. Alternatively, you can create namespace using below command:

kubectl create namespace <insert-namespace-name-here>

Refer this documentation for detailed information on creating a namespace.

Solution 3:[3]

Another approach could be to apply your configuration directly to the requested namespace.

kubectl apply -f deployment.yml -n verify-cluster
kubectl apply -f service.yml -n verify-cluster

Solution 4:[4]

First you need to get the deployment by

$ kubectl get deployment
NAME                READY   UP-TO-DATE   AVAILABLE   AGE
test-deployment   1/1     1            1           15m

If you have used any namespace then

$ kubectl get deployment -n your-namesapce

Then use the exact name in further commands example

kubectl scale deployment test-deployment --replicas=10

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Cassio
Solution 2
Solution 3 GeralexGR
Solution 4 yogesh cl