I have created a deployment for jenkins in Kubernetes.
The pod is running fine, I've created a service to access jenkins on service-ip:8080 but it seems not to work.
When I create an ingress
above the service I can access it using the public ip.
kind: Service
apiVersion: v1
metadata:
name: jenkins-ui
namespace: jenkins
spec:
type: NodePort
selector:
app: jenkins
ports:
- protocol: TCP
port: 8080
targetPort: 8080
name: ui
I created my service as described above:
$ kubectl get svc --namespace=jenkins
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
jenkins-ui NodePort 10.47.xx.xx <none> 8080:30960/TCP 1d
I tried to access: 10.47.xx.xx:8080
but I was not able to access the jenkins UI. What am I doing wrong? I also tried 10.47.xx.xx:30960
I want to access my jenkins UI using a service but I want to keep it private in my cluster. (ingress makes it public).
UPDATE:
$ kubectl describe svc jenkins-ui --namespace jenkins
Name: jenkins-ui
Namespace: jenkins
Labels: <none>
Annotations: <none>
Selector: app=jenkins
Type: NodePort
IP: 10.47.xx.xx Port: ui 8080/TCP
TargetPort: 8080/TCP
NodePort: ui 30960/TCP
Endpoints: 10.44.10.xx:8080
Session Affinity: None
External Traffic Policy: Cluster
Events: <none>
accessing the pod on 10.44.10.xx:8080 does not work too.
Form the URL with one of the worker node IP addresses and the NodePort. Example: http://192.0.2.23:30872 . For VPC clusters, you must be connected to the private network, such as through a VPN connection, to access the worker node private IP address and NodePort.
Declaring a service as NodePort exposes the Service on each Node's IP at the NodePort (a fixed port for that Service , in the default range of 30000-32767). You can then access the Service from outside the cluster by requesting <NodeIp>:<NodePort> .
Ways to connectUse a service with type NodePort or LoadBalancer to make the service reachable outside the cluster. See the services and kubectl expose documentation. Depending on your cluster environment, this may only expose the service to your corporate network, or it may expose it to the internet.
Open the web browser from the local machine and access type the Kubernetes node IP along with the Node port. Nginxwebpage. We are able to access the Nginx homepage successfully. It's a containerized web server listening in the port 80 and we mapped it to 30080 in every node in the cluster.
If I understand correctly, you want any container running in your cluster to be able to access your jenkins service, but you don't want your jenkins service to be accessible outside your cluster to something like your browser?
In this case:
curl http://jenkins-ui.default:8080
curl http://10.47.10.xx:8080
will work perfectly fine from inside any container in your kubernetes cluster.
Also, you cannot access it 10.47.10.xx:8080
from outside your cluster because that IP is only valid/available inside your kubernetes cluster.
If you want to access it from outside the cluster an ingress controller or to connect on http://<node-ip>: 30960
is the only way to connect to the jenkins-ui
k8s service and thus the pod behind it.
EDIT: Use kubectl port-forward
In development mode, if you want to access a container running internally, you can use kubectl port-forward
:
kubectl port-forward <jenkins-ui-pod> 9090:8080
This way, http://localhost:9090
will show you the jenkins-ui screen because you have kubectl access.
kubectl port-forward
doesn't work for services yet: https://github.com/kubernetes/kubernetes/issues/15180
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