<p>I use a private online server to set a jenkins environment though kubernetes.</p>
<p>I have the following service file:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: jenkins
  namespace: jenkins
spec:
  type: NodePort
  ports:
  - port: 8080
    targetPort: 8080
  selector:
    app: jenkins
</code></pre>
<p>It works, meaning that I can wget from my server the jenkins pod.
However I cannot reach my service from my local computer web-browser.</p>
<p>To do so, I have to type the following command:</p>
<pre><code>kubectl port-forward -n jenkins service/jenkins 8080:8080 --address=&lt;localServerIp&gt;
</code></pre>
<p>I have read that port-forward is debug only (<a href="https://stackoverflow.com/questions/61032945/difference-between-kubectl-port-forwarding-and-nodeport-service/61055177#61055177">Difference between kubectl port-forwarding and NodePort service</a>).
But I cannot find how to configure my service to be visible from the internet. I want the equivalent of the port-forward rule for a persistent port-forward.</p>

<p>Configuration you provided should be fine, but you would have to configure additional firewall rules on the nodes to make it possible to connect to your Jenkins Service on <code>NodeIP:NodePort</code> externally.</p>
<p>There are certain <a href="https://kubernetes.github.io/ingress-nginx/deploy/baremetal/" rel="nofollow noreferrer">considerations</a> when provisioning bare-metal clusters, because you have to configure your own load balancer to give your Services externally available IP addresses. Cloud environments use their own load balancer making this easier. You might configure your own load balancer, then create a <code>LoadBalancer</code> type of Service and connect to your app that way. Check <a href="https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types" rel="nofollow noreferrer">different types of Services here</a></p>
<p>Another thing you can try, although not recommended, is to make your <code>kubectl port-forward</code> command persistant. You can set <a href="https://kubernetes.io/docs/tasks/administer-cluster/kubelet-config-file/" rel="nofollow noreferrer">kubelet parameter</a> <code>streaming-connection-idle-timeout</code> to 0 - this will never close your forwarding. If you don't want to change any configuration you can run:</p>
<p><code>while true; do kubectl port-forward -n jenkins service/jenkins 8080:8080 --address=&lt;localServerIp&gt;; done</code></p>
<p>Some links you might find useful: <a href="https://stackoverflow.com/questions/47484312/kubectl-port-forwarding-timeout-issue">similar case</a>, <a href="https://kubernetes.io/docs/tutorials/stateless-application/expose-external-ip-address/" rel="nofollow noreferrer">exposing apps in kubernetes</a>.</p>
