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

Viewed 35877

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

5 Answers

I'm relatively new to kubernetes, but it seems it has evolved quite a bit since this question was asked. As of its latest versions(I'm running v1.16) generators are deprecated and they are completely removed in v1.18. See the corresponding ticket and the release notes. Release notes explicitly say:

Remove all the generators from kubectl run. It will now only create pods.

I've tested kubectl run with various --restart flags and never got any deployments created. What we do have now is called "naked" Pod. And while you might be tempted to use it, it goes against k8s best practices:

Don’t use naked Pods (that is, Pods not bound to a ReplicaSet or Deployment) if you can avoid it. Naked Pods will not be rescheduled in the event of a node failure.

When you are using "kubectl run nginx --image=nginx --port=80" it creates a deployment by default. To create a pod you have two options.

  1. kubectl run --generator=run-pod/v1 nginx --image=nginx --port=80
  2. kubectl create pod nginx --image=nginx --port=80
Related