Kubernetes
kubectl
run command
deprecated features
Kubernetes CLI

What is the current equivalent of kubectl run --generatorrun/v1

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Introduction

The --generator flag for kubectl run was deprecated in Kubernetes 1.18 and removed in 1.21. Previously, kubectl run --generator=run/v1 created a bare Pod, while other generators created Deployments, Jobs, or ReplicationControllers. The modern equivalent is simply kubectl run (which now only creates Pods) or using kubectl create for other resource types.

What the Generators Did

Before deprecation, kubectl run used generators to create different Kubernetes resources:

GeneratorResource CreatedStatus
run/v1PodRemoved — use kubectl run
run-pod/v1PodRemoved — use kubectl run
deployment/v1beta1DeploymentRemoved — use kubectl create deployment
deployment/apps.v1DeploymentRemoved — use kubectl create deployment
job/v1JobRemoved — use kubectl create job
cronjob/v1beta1CronJobRemoved — use kubectl create cronjob

Modern Equivalents

Creating a Pod (was --generator=run/v1)

bash
1# Old way (deprecated)
2kubectl run nginx --generator=run/v1 --image=nginx
3
4# New way — kubectl run now creates only Pods
5kubectl run nginx --image=nginx

With additional options:

bash
1# Run with port exposed
2kubectl run nginx --image=nginx --port=80
3
4# Run with environment variables
5kubectl run myapp --image=myapp:latest --env="DB_HOST=localhost" --env="DB_PORT=5432"
6
7# Run with labels
8kubectl run nginx --image=nginx --labels="app=web,env=dev"
9
10# Run with resource limits
11kubectl run nginx --image=nginx \
12  --requests='cpu=100m,memory=128Mi' \
13  --limits='cpu=200m,memory=256Mi'
14
15# Run interactively and delete after exit
16kubectl run debug --image=busybox --rm -it -- sh

Creating a Deployment

bash
1# Old way
2kubectl run nginx --generator=deployment/apps.v1 --image=nginx --replicas=3
3
4# New way
5kubectl create deployment nginx --image=nginx --replicas=3

With more options:

bash
1# Create and expose
2kubectl create deployment nginx --image=nginx --port=80
3kubectl expose deployment nginx --port=80 --type=LoadBalancer
4
5# Set replicas
6kubectl create deployment myapp --image=myapp:v1 --replicas=5
7
8# Dry run to see the YAML
9kubectl create deployment nginx --image=nginx --dry-run=client -o yaml

Creating a Job

bash
1# Old way
2kubectl run myjob --generator=job/v1 --image=busybox -- echo "hello"
3
4# New way
5kubectl create job myjob --image=busybox -- echo "hello"
bash
1# Job from a CronJob template
2kubectl create job test-job --from=cronjob/my-cronjob
3
4# Job with deadline
5kubectl create job myjob --image=busybox --dry-run=client -o yaml -- echo "hello" | \
6  kubectl apply -f -

Creating a CronJob

bash
1# Old way
2kubectl run mycron --generator=cronjob/v1beta1 --image=busybox \
3  --schedule="*/5 * * * *" -- echo "hello"
4
5# New way
6kubectl create cronjob mycron --image=busybox \
7  --schedule="*/5 * * * *" -- echo "hello"

kubectl run Options Reference

Modern kubectl run creates only Pods. Key options:

bash
1kubectl run <name> --image=<image> [options]
2
3Options:
4  --image          Container image
5  --port           Container port to expose
6  --env            Environment variables (key=value)
7  --labels         Pod labels (key=value,key=value)
8  --requests       Resource requests (cpu=100m,memory=128Mi)
9  --limits         Resource limits
10  --command        Use command mode (args after -- are the command)
11  --rm             Delete pod after it exits
12  -it              Interactive terminal
13  --restart        Restart policy (Always, OnFailure, Never)
14  --dry-run=client Output YAML without creating
15  -o yaml          Output format

Generating YAML Manifests

Use --dry-run=client -o yaml to generate manifests without creating resources:

bash
1# Generate Pod YAML
2kubectl run nginx --image=nginx --port=80 \
3  --dry-run=client -o yaml > pod.yaml
4
5# Generate Deployment YAML
6kubectl create deployment nginx --image=nginx --replicas=3 \
7  --dry-run=client -o yaml > deployment.yaml
8
9# Generate Job YAML
10kubectl create job myjob --image=busybox \
11  --dry-run=client -o yaml -- echo "hello" > job.yaml
12
13# Generate CronJob YAML
14kubectl create cronjob mycron --image=busybox \
15  --schedule="0 * * * *" \
16  --dry-run=client -o yaml -- echo "hello" > cronjob.yaml

This is the recommended approach for creating initial manifest files that you then customize and version control.

Quick Debugging Pods

One of the most common uses of kubectl run is spinning up temporary debug pods:

bash
1# Interactive shell
2kubectl run debug --image=busybox --rm -it -- sh
3
4# Test DNS resolution
5kubectl run dns-test --image=busybox --rm -it -- nslookup kubernetes.default
6
7# Test network connectivity
8kubectl run curl-test --image=curlimages/curl --rm -it -- \
9  curl -s http://my-service.default.svc.cluster.local
10
11# Debug with a specific namespace
12kubectl run debug -n my-namespace --image=nicolaka/netshoot --rm -it -- bash

Common Pitfalls

  • Assuming kubectl run creates Deployments: Since Kubernetes 1.18+, kubectl run creates only bare Pods. For Deployments, use kubectl create deployment. If you see old tutorials using kubectl run for deployments, they are outdated.
  • Bare Pods vs Deployments: Pods created by kubectl run are not managed by a controller. If the pod crashes or the node fails, it is not restarted. Use Deployments for production workloads.
  • --restart flag confusion: In the old generator system, --restart=Never selected the Job generator. Now it just sets the pod's restart policy. kubectl run --restart=Never creates a pod that runs once and stops.
  • --replicas removed: kubectl run --replicas=3 no longer works. Use kubectl create deployment --replicas=3 instead.
  • API version changes: Old tutorials may reference apps/v1beta1 or extensions/v1beta1. These API versions were removed. Modern Kubernetes uses apps/v1 for Deployments and batch/v1 for Jobs.

Summary

  • kubectl run now creates only Pods — all generators were removed in Kubernetes 1.21
  • Use kubectl create deployment for Deployments, kubectl create job for Jobs, kubectl create cronjob for CronJobs
  • Use --dry-run=client -o yaml to generate manifest files without creating resources
  • kubectl run --rm -it is ideal for temporary debug pods
  • Bare Pods are not rescheduled on failure — always use controllers (Deployment, Job) for production workloads

Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.