Kubectl run command for yaml creation

I am looking for different set of commands for kubectl run to generate yaml file.
Service (different options)
I checked Kubectl Reference Docs
but I am unable to figure out which command need to run for which option

$ run NAME --image=image [–env=“key=value”] [–port=port] [–replicas=replicas] [–dry-run=bool] [–overrides=inline-json] [–command] – [COMMAND] [args…]

For example :

$ kubectl run NAME --image=IMAGE-NAME --labels=run=LABLE --dry-run -o yaml > test.yaml
It creates deployment but I dont know what needs to be change to create other types of yaml.

Have you taken a look at using generators?


Thanks for your comment, with the help of above link I figure out way to create pod and deployment yaml files
kubectl run --restart=Never NAME-pod --image=IMAGE-NAME --labels=run=LABLE --dry-run -o yaml > pod.yaml
kubectl run --restart=Always NAME-deployment --image=IMAGE-NAME --labels=run=LABLE --dry-run --replicas=REPLICAS -o yaml > deployment.yaml
Still I am unable to find how to create yaml files for Deamonset, service (node port, cluster ip and loadbalancer).

I think that the easier way is searching on the kubernetes.io documentation for service template or daemonset template:

Thus, you’ll find more template examples.

Or, if you prefer, you can start from an existing resource, export to a YAML file, then edit it. See the following example:

kubectl get ds kube-proxy -n kube-system -o yaml > new-ds.yaml
vi new-ds.yaml

With the help of “kubectl run -h” I found below mentioned parameters

–restart=‘Always’: The restart policy for this Pod. If set to ‘Always’ a deployment is created, if set to ‘Never’, a regular pod is created.

–expose=false: If true, a public, external service is created for the container(s) which are run

Now I am able to create Pod/deployment and service with help of it same time. I am looking for how to pass NodePort into it.

With the help of “kubectl expose -h” I am able to identify below mentioned parameters

Possible resources include (case insensitive):
pod (po), service (svc), replicationcontroller (rc), deployment (deploy), replicaset (rs)

–dry-run=false: If true, only print the object that would be sent, without sending it.
-o, --output=’’: Output format. One of:
–type=’’: Type for this service: ClusterIP, NodePort, LoadBalancer, or ExternalName. Default is ‘ClusterIP’.

For example :
kubectl expose deployment Deployment-Name --name=Service-Name --port=80 --target-port=80 --type=NodePort --dry-run -o yaml >deploy-service.yaml