Assume you have a deployment running and you need to create a Service for exposing the pods. This is what is required/known:
- Deployment name: jabulik
- Target port: 8080
- Service type: NodePort
- Selector: jabulik-app
- Port: 8080
Answer
kubectl expose deployment jabulik --name=jabulik-service --target-port=8080 --type=NodePort --port=8080 --dry-run=client -o yaml -> svc.yaml
vi svc.yaml (make sure selector is set to jabulik-app)
k apply -f svc.yaml