Search code examples
kubernetesminikube

How to start a pod in command line without deployment in kubernetes?


I want to debug the pod in a simple way, therefore I want to start the pod without deployment.

But it will automatically create a deployment

$ kubectl run nginx --image=nginx --port=80
deployment "nginx" created

So I have to create the nginx.yaml file

---
apiVersion: v1
kind: Pod
metadata:
  name: nginx
spec:
  containers:
    - name: nginx
      image: nginx
      ports:
        - containerPort: 80

And create the pod like below, then it creates pod only

kubectl create -f nginx.yaml
pod "nginx" created

How can I specify in the command line the kind:Pod to avoid deployment?

// I run under minikue 0.20.0 and kubernetes 1.7.0 under Windows 7


Solution

  • kubectl run nginx --image=nginx --port=80 --restart=Never
    

    --restart=Always: The restart policy for this Pod. Legal values [Always, OnFailure, Never]. If set to Always a deployment is created, if set to OnFailure a job is created, if set to Never, a regular pod is created. For the latter two --replicas must be 1. Default Always [...]

    see official document https://kubernetes.io/docs/reference/kubectl/generated/kubectl_run/