I use a private online server to set a jenkins environment though kubernetes.
I have the following service file:
apiVersion: v1
kind: Service
metadata:
name: jenkins
namespace: jenkins
spec:
type: NodePort
ports:
- port: 8080
targetPort: 8080
selector:
app: jenkins
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.
To do so, I have to type the following command:
kubectl port-forward -n jenkins service/jenkins 8080:8080 --address=<localServerIp>
I have read that port-forward is debug only (Difference between kubectl port-forwarding and NodePort service). 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.
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 NodeIP:NodePort externally.
There are certain considerations 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 LoadBalancer type of Service and connect to your app that way. Check different types of Services here
Another thing you can try, although not recommended, is to make your kubectl port-forward command persistant. You can set kubelet parameter streaming-connection-idle-timeout to 0 - this will never close your forwarding. If you don't want to change any configuration you can run:
while true; do kubectl port-forward -n jenkins service/jenkins 8080:8080 --address=<localServerIp>; done
Some links you might find useful: similar case, exposing apps in kubernetes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With