kubectl run --generator=run-pod/v1 nginx --image=nginx --dry-run -o yaml ## generate pod yaml file
kubectl run --generator=run-pod/v1 nginx --image=nginx --restart=Never --dry-run -o yaml ## generate pod yaml file with restartPolicy: Never
kubectl run --generator=run-pod/v1 nginx --image=nginx -l="app=web,env=dev" --dry-run -o yaml ## generate pod yaml file with labels provided
kubectl run --generator=run-pod/v1 nginx --image=nginx --env="hello=world" --env="me=naresh" --dry-run -o yaml ## generate pod yaml with env variables
kubectl run --generator=run-pod/v1 nginx --image=nginx --restart=OnFailure --env='hello=world' -l='app=web' --limits='cpu=100m,memory=150Mi' --dry-run -o yaml ## generate pod yaml with various parametes
kubectl run --generator=run-pod/v1 nginx --image=nginx --port=80 --expose --dry-run -o yaml ## generate pod yaml file & Service yaml file together
Note: remove --dry-run -o yaml from all above commands to create pods ex as below.
kubectl run --generator=run-pod/v1 nginx --image=nginx # create a pod
kubectl run --generator=deployment/apps.v1 nginx --image=nginx --dry-run -o yaml ## generate Deployment yaml file
kubectl run --generator=deployment/apps.v1 nginx --image=nginx --restart=Never --dry-run -o yaml ## generate Deployment yaml file with restartPolicy: Never
kubectl run --generator=deployment/apps.v1 nginx --image=nginx -l="app=web,env=dev" --dry-run -o yaml ## generate Deployment yaml file with labels provided
kubectl run --generator=deployment/apps.v1 nginx --image=nginx --env="hello=world" --env="me=naresh" --dry-run -o yaml ## generate Deployment yaml with env variables
kubectl run --generator=deployment/apps.v1 nginx --image=nginx --restart=OnFailure --env='hello=world' -l='app=web' --limits='cpu=100m,memory=150Mi' --dry-run -o yaml ## generate Deployment yaml with various parametes
kubectl run --generator=deployment/apps.v1 nginx --image=nginx --port=80 --expose --dry-run -o yaml ## generate Deployment yaml file & Service yaml file together
Note: remove --dry-run -o yaml from all above commands to create Deployment ex as below.
kubectl run --generator=deployment/apps.v1 nginx --image=nginx ## create a Deployment
we can also create a deployment using below commands
kubectl create deployment my-dep --image=nginx ## creates a deployment