🎓 A1Learner
🔍
0 of 51 lessons completed

Kubernetes: Create Your First Pod

A Pod manifest is a small YAML file that describes one Pod. kubectl apply reads the file and creates the Pod it describes.

Write the manifest

Four lines describe the Pod. The name is web-pod. The container is called web and runs nginx.

apiVersion: v1
kind: Pod
metadata:
  name: web-pod
spec:
  containers:
  - name: web
    image: nginx:1.27-alpine

Create the Pod

apply reads the file and creates the Pod. The output names the Pod it made.

kubectl apply -f web-pod.yaml

Check the Pod is running

Running means the container started. 1/1 means the one container is ready.

kubectl get pods

Remove the Pod

delete with the same file removes the Pod. The manifest stays on disk for next time.

kubectl delete -f web-pod.yaml

Example

kubectl apply -f web-pod.yaml
kubectl get pods

Key points

  • Manifest: a YAML file that describes what Kubernetes should create.
  • YAML: a plain-text format for writing manifests.
  • Use kubectl apply -f to create the objects in a manifest file.
  • kubectl run: a command that starts a Pod from one image.
  • A Pod manifest needs apiVersion v1 and kind Pod.
  • A Pod spec needs containers, and each container needs a name and an image.
  • Use kubectl get pods to check that the Pod is running.
  • Use kubectl delete -f to remove the objects in a manifest file.

In this example, apply reads web-pod.yaml and creates the Pod. get pods then shows web-pod running. The manifest is the source of truth, and kubectl turns it into a live Pod.

Note

YAML is fussy about spaces, so keep the indent the same at each level.

Try it Yourself

Edit the code, then press Run.

Running is simulated · Rust Playground

Exercise

Which command creates a Pod from a YAML file called web-pod.yaml?