I want to debug the pod in simple way, therefore I want to start the pod without deployment.
But it will automatically create 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 in command line to specify the kind:Pod
to avoid deployment
?
// I run under minikue 0.20.0 and kubernetes 1.7.0 under Windows 7
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.
kubectl run nginx --image=nginx --port=80 --restart=Never
--restart=Always
: The restart policy for this Pod. Legal values [Always
,OnFailure
,Never
]. If set toAlways
a deployment is created, if set toOnFailure
a job is created, if set toNever
, a regular pod is created. For the latter two--replicas
must be1
. DefaultAlways
[...]
see official document https://kubernetes.io/docs/user-guide/kubectl-conventions/#generators
Now there are two ways one can create pod through command line.
kubectl run nginx --image=nginx --restart=Never
OR
kubectl run --generator=run-pod/v1 nginx1 --image=nginx
See official documentation. https://kubernetes.io/docs/reference/kubectl/conventions/#generators
Use generators for this, default kubectl run will create a deployment object. If you want to override this behavior use "run-pod/v1" generator.
kubectl run --generator=run-pod/v1 nginx1 --image=nginx
You may refer the link below for better understanding.
https://kubernetes.io/docs/reference/kubectl/conventions/#generators
Do you mean "expose a service"? I think this command line will help you to do it.
kubectl expose pod nginx --type=LoadBalancer --port=80