Search code examples
kuberneteskubectl

How to create a Kubernetes Deployment with the 'kubectl run' command?


As per an article I read, while using the 'kubectl run' command,

  • --restart Always creates a deployment,
  • --restart Never creates a pod
  • --restart OnFailure creates a job

However, when I try that on my Minikube installation it is creating a resource of kind: Pod

k run ngingx --image=nginx -o yaml --dry-run=client --restart Always
apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: ngingx
  name: ngingx
spec:
  containers:
  - image: nginx
    name: ngingx
    resources: {}
  dnsPolicy: ClusterFirst
  restartPolicy: Always
status: {}

Has the feature been deprecated or am I doing something wrong ?

Thank You


Solution

  • it should be like this

    kubectl create deployment ngingx --image=nginx -o yaml --dry-run=client

    Nope the restart: Always does not create pod or deplyoment it's about the container restart policy which is used for restarting container if pod crashes it tries restart.