Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Setting up Kubernetes  ›  Lesson

Deploying your First Application

Deploying your First Application 12 minAn app can be deployed with imperative kubectl commands for quick trials or with declarative files applied by kubectl apply, then checked with get, describe and logs.

Deploying your First Application

The local cluster is running. Now the notes app goes in — and you can reach it from your browser. There are two ways to get it there, and knowing why teams prefer one of them is the real lesson.

The rule

Commands are for trying; files are for keeping.

The imperative way tells the cluster what to do, one command at a time:

kubectl create namespace notes
kubectl create deployment notes-web --image=ghcr.io/example/notes-web:1.2 -n notes
kubectl expose deployment notes-web --port=80 --target-port=8080 -n notes

Quick, but the only record of what you did is your shell history.

The declarative way writes the desired state in a file and applies it:

kubectl apply -f notes-web.yaml

The file can be reviewed, stored in Git and applied again. apply is safe to repeat: if nothing in the file changed, nothing in the cluster changes.

To reach the app from your laptop without any public address:

kubectl port-forward service/notes-web 8080:80 -n notes

Notice the -n notes on every command. Objects live in a namespace, and a command without -n looks in default, where notes-web does not exist. "Not found" errors right after a deploy are usually a missing -n.

Cleaning up mirrors creating: kubectl delete -f notes-web.yaml removes exactly what the file created.

Now http://localhost:8080 reaches the app. Port-forward is a debugging tunnel, not a way to serve real users.

The shortcut

Use the "get, describe, logs" ladder whenever you deploy anything: each step looks one level deeper.

Is notes-web really running?Step 1 of 4
  1. get

    kubectl get pods -n notes shows notes-web-6f7b… 1/1 Running. The overview looks healthy.

A useful habit: generate a starting file from a command, then keep the file.

kubectl create deployment notes-web --image=ghcr.io/example/notes-web:1.2 --dry-run=client -o yaml > notes-web.yaml

Drills

Answer fast — trust the rule.

quick drill

Why do teams prefer kubectl apply -f files over one-off commands?

quick drill

You run kubectl apply -f notes-web.yaml twice without editing the file. What happens the second time?

quick drill

A pod is Running but the app returns errors. Which command shows the app's own output?

quick drill

What does kubectl port-forward service/notes-web 8080:80 -n notes do?

Remember

  • Commands are for trying; files are for keeping — kubectl apply -f.
  • Check a deploy with the ladder: get, describe, logs.
  • Trap: using port-forward as if it were real public access.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainCommands or files?

Explain the difference between deploying notes-web with kubectl create deployment and with kubectl apply -f notes-web.yaml, and say which you would use for a team project and why.