Challenge 1: jekyll service using imperative commands only

What is the best imperative command to create the jekyll service?

kubectl create service nodeport jekyll --tcp=8080:4000 --node-port=30097 --namespace=development --dry-run=client -o jekyll-node-service.yaml

This requires a change from app=jekyll to run=jekyll in spec.selector.

kubectl expose pod jekyll --name=jekyll --target-port=4000 --port=8080 --namespace=development --dry-run=client -o yaml > jekyll-node-service.yaml

This requires adding the type: NodePort and nodePort: 30097

Both require a dry-run and editing the yaml. Is there a way to do this using only an imperative command?

Hi @headkaze,

With kubectl expose, you can set the service type with the flag --type=NodePort, but you can’t set the nodePort within this command (only --port and --targetPort available), still need to generate YAML and modify it.
With kubectl create svc nodeport, you also need to change the pod selector.

So we don’t have the imperative command that can cover everything, in your case, need the YAML file. If you accepted the random nodePort, the expose option is the better one.

Thanks,
Trung.