Kubernetes
containers
CLI
Pod
orchestration

How to run a container in Kubernetes without creating Deployment or Job?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

You do not need a Deployment or a Job just to run one container in Kubernetes. If the goal is an ad hoc test, a debugging shell, or a single long-running process with no controller, a plain Pod is the simplest answer.

Use kubectl run for a Quick Pod

The fastest path is kubectl run, which creates a Pod from an image. For a simple web server:

bash
kubectl run demo-nginx \
  --image=nginx:1.25 \
  --restart=Never

That creates a single Pod named demo-nginx. The --restart=Never flag matters because it makes the intent explicit: create a Pod, not a higher-level controller.

Check the result with:

bash
kubectl get pods
kubectl describe pod demo-nginx
kubectl logs demo-nginx

For interactive debugging, attach a shell immediately:

bash
1kubectl run toolbox \
2  --image=busybox:1.36 \
3  --restart=Never \
4  -it -- sh

This pattern is useful when you want to test DNS resolution, curl an internal service, or inspect mounted files from inside the cluster.

Use a Pod Manifest When You Want Repeatability

kubectl run is convenient, but a Pod manifest is easier to review, reapply, and commit to version control. A minimal example looks like this:

yaml
1apiVersion: v1
2kind: Pod
3metadata:
4  name: one-off-worker
5spec:
6  restartPolicy: Never
7  containers:
8    - name: worker
9      image: python:3.12-slim
10      command: ["python", "-c", "print('hello from kubernetes')"]

Create it with:

bash
kubectl apply -f pod.yaml
kubectl get pod one-off-worker
kubectl logs one-off-worker

This is still "just a Pod." There is no Deployment managing replicas and no Job managing completion state. Kubernetes schedules the Pod, starts the container, and then stops there.

When a Plain Pod Is the Right Tool

Using a Pod directly makes sense when:

  • You are testing an image quickly
  • You need a temporary shell inside the cluster
  • You want to reproduce an issue with the fewest moving parts
  • You have a one-off process and you are managing cleanup yourself

It is also a good choice when you want to understand the raw Pod spec before adding controllers on top.

For example, if you only need to inspect environment variables or mounted volumes, a Pod is often easier to reason about than a Deployment because there is only one object in play.

Observe, Debug, and Remove the Pod

Once the container is running, normal kubectl commands still apply:

bash
1kubectl logs demo-nginx
2kubectl exec -it demo-nginx -- sh
3kubectl get pod demo-nginx -o wide
4kubectl delete pod demo-nginx

If the image exits immediately, inspect its status:

bash
kubectl describe pod one-off-worker

That will show whether the container completed successfully, crashed, or failed to pull the image.

You can also preview the Pod definition that kubectl run would generate:

bash
1kubectl run demo-nginx \
2  --image=nginx:1.25 \
3  --restart=Never \
4  --dry-run=client -o yaml

That is a practical way to move from a one-liner command to a reusable manifest.

Know the Tradeoff: No Controller Means No Safety Net

A plain Pod is intentionally bare-bones. If the Pod is deleted, it stays deleted. If the node disappears, Kubernetes does not recreate it somewhere else unless a controller owns it.

That is the biggest tradeoff compared with a Deployment or Job:

  • No rollout history
  • No replica management
  • No automatic recreation after deletion
  • No completion tracking beyond the Pod's own status

So a Pod is excellent for experiments and targeted operational work, but it is usually not the right long-term shape for production services.

Common Pitfalls

  • Assuming a standalone Pod will be recreated automatically after failure or deletion.
  • Forgetting --restart=Never and ending up with behavior you did not intend.
  • Using a plain Pod for batch work that really needs retry and completion semantics, which is what a Job is for.
  • Expecting a Pod to provide scaling or rolling updates, which are Deployment responsibilities.
  • Leaving debug Pods running after you are done, which creates clutter and sometimes cost.

Summary

  • You can run a container in Kubernetes without a Deployment or Job by creating a plain Pod.
  • 'kubectl run ... --restart=Never is the quickest way to do it from the command line.'
  • A Pod manifest is better when you want repeatability and reviewable configuration.
  • Standalone Pods are good for testing, debugging, and one-off tasks.
  • The tradeoff is that no controller is watching or recreating the Pod for you.

Course illustration
Course illustration

All Rights Reserved.