Full lesson
Explore the full explanation, examples, and visuals at your own pace.
deployment.yaml + kubectl apply
Kubernetes says your namespace doesn't exist. You just wrote it. Look at the Deployment: under metadata, it sets namespace to shop. But when we run kubectl apply, the server answers with NotFound, namespaces "shop" not found. The file mentions shop, yet the cluster doesn't know it.
# deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
namespace: shop
$ kubectl apply -f deployment.yaml
Error from server (NotFound): namespaces "shop" not foundBefore vs after: the shop box must exist
A namespace is a named folder inside your cluster. The namespace line in your file only points to that folder, it doesn't create it. On the left, the web Deployment bounces off an empty outline where shop should be. On the right, shop exists, so web lands inside.
Fix: create the namespace first
There are two fixes. You can run kubectl create namespace shop, then apply the Deployment again, and it's created. Or write a Namespace object in namespace.yaml and apply that first. Option two takes a few more lines, but your setup stays in version-controlled files.
# Option 1: create it by command
$ kubectl create namespace shop
$ kubectl apply -f deployment.yaml
deployment.apps/web created
# Option 2: namespace.yaml, apply first
apiVersion: v1
kind: Namespace
metadata:
name: shopNaming a room doesn't build it.
The namespace has to exist before anything can reference it. Create it first, then apply. Naming a room doesn't build it.
