<p>I’m attempting to execute a Jenkins &amp; Docker CLI container on Kubernetes. Here are my steps:</p>
<p>I create the pod using:</p>
<pre><code>kubectl --kubeconfig my-kubeconfig.yml run my-jenkins-pod --image=trion/jenkins-docker-client --restart=Never
</code></pre>
<p>Which creates a pod-based on the image <a href="https://hub.docker.com/r/trion/jenkins-docker-client" rel="nofollow noreferrer">https://hub.docker.com/r/trion/jenkins-docker-client</a></p>
<p>I create the deployment using:</p>
<pre><code>kubectl --kubeconfig my-kubeconfig.yml apply -f /kub/kube
</code></pre>
<p><code>/kub/kube</code> contains <code>jenkins-deployment-yaml</code> which I have configured as:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: my-jenkins-pod
spec:
  ports:
    - protocol: &quot;TCP&quot;
      port: 50000
      targetPort: 5001
  selector:
    app: my-jenkins-pod
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-jenkins-pod
spec:
  selector:
    matchLabels:
      app: my-jenkins-pod
  replicas: 1
  template:
    metadata:
      labels:
        app: my-jenkins-pod
    spec:
      containers:
        - name: ml-services
          image: trion/jenkins-docker-client
          ports:
            - containerPort: 5001
</code></pre>
<p>To access the Jenkins container I expose the IP using:</p>
<pre><code>kubectl --kubeconfig my-kubeconfig.yml expose deployment my-jenkins-pod --type=LoadBalancer --name=my-jenkins-pod-public
</code></pre>
<p>To return the IP of the Jenkins and Docker image I use :</p>
<pre><code>kubectl --kubeconfig my-kubeconfig.yml get services my-jenkins-pod-public
</code></pre>
<p>Which returns:</p>
<pre><code>NAME                    TYPE           CLUSTER-IP       EXTERNAL-IP     PORT(S)          AGE
my-jenkins-pod-public   LoadBalancer   9.5.52.28   161.61.222.16   5001:30878/TCP   10m
</code></pre>
<p>To test I open the URL at location:</p>
<p><a href="http://161.61.222.16:5001/" rel="nofollow noreferrer">http://161.61.222.16:5001/</a></p>
<p>Which returns:</p>
<pre><code>This page isn’t working
161.61.222.16 didn’t send any data.
ERR_EMPTY_RESPONSE
</code></pre>
<p>It seems the service has started but the port mappings are incorrect?</p>
<p>The log of the pod my-jenkins-pod contains:</p>
<blockquote>
<p>Running from: /usr/share/jenkins/jenkins.war webroot:
EnvVars.masterEnvVars.get(&quot;JENKINS_HOME&quot;) 2021-04-03 11:15:42.899+0000
[id=1]    INFO    org.eclipse.jetty.util.log.Log#initialized: Logging
initialized @274ms to org.eclipse.jetty.util.log.JavaUtilLog
2021-04-03 11:15:43.012+0000 [id=1]   INFO    winstone.Logger#logInternal:
Beginning extraction from war file 2021-04-03 11:15:44.369+0000
[id=1]    WARNING o.e.j.s.handler.ContextHandler#setContextPath: Empty
contextPath 2021-04-03 11:15:44.416+0000
[id=1]    INFO    org.eclipse.jetty.server.Server#doStart:
jetty-9.4.39.v20210325; built: 2021-03-25T14:42:11.471Z; git:
9fc7ca5a922f2a37b84ec9dbc26a5168cee7e667; jvm 1.8.0_282-b08 2021-04-03
11:15:44.653+0000
[id=1]    INFO    o.e.j.w.StandardDescriptorProcessor#visitServlet: NO JSP
Support for /, did not find org.eclipse.jetty.jsp.JettyJspServlet
2021-04-03 11:15:44.695+0000
[id=1]    INFO    o.e.j.s.s.DefaultSessionIdManager#doStart:
DefaultSessionIdManager workerName=node0 2021-04-03 11:15:44.695+0000
[id=1]    INFO    o.e.j.s.s.DefaultSessionIdManager#doStart: No
SessionScavenger set, using defaults 2021-04-03 11:15:44.696+0000
[id=1]    INFO    o.e.j.server.session.HouseKeeper#startScavenging: node0
Scavenging every 660000ms 2021-04-03 11:15:45.081+0000
[id=1]    INFO    hudson.WebAppMain#contextInitialized: Jenkins home
directory: /var/jenkins_home found at:
EnvVars.masterEnvVars.get(&quot;JENKINS_HOME&quot;) 2021-04-03 11:15:45.203+0000
[id=1]    INFO    o.e.j.s.handler.ContextHandler#doStart: Started
w.@24f43aa3{Jenkins
v2.286,/,file:///var/jenkins_home/war/,AVAILABLE}{/var/jenkins_home/war}
2021-04-03 11:15:45.241+0000
[id=1]    INFO    o.e.j.server.AbstractConnector#doStart: Started
ServerConnector@4f0f2942{HTTP/1.1, (http/1.1)}{0.0.0.0:8080}
2021-04-03 11:15:45.241+0000
[id=1]    INFO    org.eclipse.jetty.server.Server#doStart: Started @2616ms
2021-04-03 11:15:45.245+0000 [id=21]  INFO    winstone.Logger#logInternal:
Winstone Servlet Engine running: controlPort=disabled 2021-04-03
11:15:46.479+0000 [id=26] INFO    jenkins.InitReactorRunner$1#onAttained:
Started initialization 2021-04-03 11:15:46.507+0000
[id=26]   INFO    jenkins.InitReactorRunner$1#onAttained: Listed all
plugins 2021-04-03 11:15:47.654+0000
[id=27]   INFO    jenkins.InitReactorRunner$1#onAttained: Prepared all
plugins 2021-04-03 11:15:47.660+0000
[id=26]   INFO    jenkins.InitReactorRunner$1#onAttained: Started all
plugins 2021-04-03 11:15:47.680+0000
[id=27]   INFO    jenkins.InitReactorRunner$1#onAttained: Augmented all
extensions 2021-04-03 11:15:48.620+0000
[id=26]   INFO    jenkins.InitReactorRunner$1#onAttained: System config
loaded 2021-04-03 11:15:48.621+0000
[id=26]   INFO    jenkins.InitReactorRunner$1#onAttained: System config
adapted 2021-04-03 11:15:48.621+0000
[id=27]   INFO    jenkins.InitReactorRunner$1#onAttained: Loaded all jobs
2021-04-03 11:15:48.622+0000
[id=27]   INFO    jenkins.InitReactorRunner$1#onAttained: Configuration for
all jobs updated 2021-04-03 11:15:48.704+0000
[id=40]   INFO    hudson.model.AsyncPeriodicWork#lambda$doRun$0: Started
Download metadata 2021-04-03 11:15:48.722+0000
[id=40]   INFO    hudson.util.Retrier#start: Attempt #1 to do the action
check updates server 2021-04-03 11:15:49.340+0000
[id=26]   INFO    jenkins.install.SetupWizard#init:</p>
<hr />
<hr />
<p>************************************************************* Jenkins initial setup is required. An admin user has been created and a
password generated. Please use the following password to proceed to
installation: ab5dbf74145c405fb5a33456d4b97436 This may also be found
at: /var/jenkins_home/secrets/initialAdminPassword</p>
<hr />
<hr />
<p>************************************************************* 2021-04-03 11:16:08.107+0000
[id=27]   INFO    jenkins.InitReactorRunner$1#onAttained: Completed
initialization 2021-04-03 11:16:08.115+0000
[id=20]   INFO    hudson.WebAppMain$3#run: Jenkins is fully up and running
2021-04-03 11:16:08.331+0000
[id=40]   INFO    h.m.DownloadService$Downloadable#load: Obtained the
updated data file for hudson.tasks.Maven.MavenInstaller 2021-04-03
11:16:08.332+0000 [id=40] INFO    hudson.util.Retrier#start: Performed
the action check updates server successfully at the attempt #1
2021-04-03 11:16:08.334+0000
[id=40]   INFO    hudson.model.AsyncPeriodicWork#lambda$doRun$0: Finished
Download metadata. 19,626 ms</p>
</blockquote>
<p>Is Jenkins server is started at port 8080? because of this log message:</p>
<blockquote>
<p>11:15:45.241+0000 [id=1] INFO o.e.j.server.AbstractConnector#doStart:
Started ServerConnector@4f0f2942{HTTP/1.1, (http/1.1)}{0.0.0.0:8080}
2021-04-03</p>
</blockquote>
<p>I tried changing <code>jenkins-deployment-yaml</code> to point at port <code>8080</code> instead of <code>50000</code>, resulting in the updated <code>jenkins-deployment-yaml</code> :</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: my-jenkins-pod
spec:
  ports:
    - protocol: &quot;TCP&quot;
      port: 8080
</code></pre>
<p>But the same error is returned when I attempt to access <a href="http://161.61.222.16:5001/" rel="nofollow noreferrer">http://161.61.222.16:5001/</a></p>
<p>Are my port mappings incorrect? Is this a correct method of adding an existing docker container that is available on the docker hub to a Kubernetes cluster?</p>
<p>Update:</p>
<p>The result of command <code>kubectl describe services my-jenkins-pod-public</code> is :</p>
<pre><code>Name:                     my-jenkins-pod-public
Namespace:                default
Labels:                   &lt;none&gt;
Annotations:              kubernetes.digitalocean.com/load-balancer-id: d46ae9ae-6e8a-4fd8-aa58-43c08310059a
Selector:                 app=my-jenkins-pod
Type:                     LoadBalancer
IP Families:              &lt;none&gt;
IP:                       10.245.152.228
IPs:                      10.245.152.228
LoadBalancer Ingress:     161.61.222.16
Port:                     &lt;unset&gt;  5001/TCP
TargetPort:               5001/TCP
NodePort:                 &lt;unset&gt;  30878/TCP
Endpoints:                10.214.12.12:5001
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   &lt;none&gt;
</code></pre>
<p>Trying to access <a href="http://161.61.222.16:30878/" rel="nofollow noreferrer">http://161.61.222.16:30878/</a> via browser returns:</p>
<blockquote>
<p>This site can’t be reached159.65.211.46 refused to connect. Try:</p>
<p>Checking the connection Checking the proxy and the firewall
ERR_CONNECTION_REFUSED</p>
</blockquote>
<p>Trying to access <a href="http://161.61.222.16:5001/" rel="nofollow noreferrer">http://161.61.222.16:5001/</a> via browser returns:</p>
<blockquote>
<p>This page isn’t working
161.61.222.16 didn’t send any data.
ERR_EMPTY_RESPONSE</p>
</blockquote>
<p>Seems the port <code>5001</code> is exposed/accessible but is not sending any data.</p>
<p>I also tried accessing <code>10.214.12.12</code> on ports <code>5001</code> &amp; <code>30878</code> but both requests time out.</p>

blue-sky
<p>You need to use <a href="http://161.61.222.16:30878/" rel="nofollow noreferrer">http://161.61.222.16:30878/</a> from outside of the host which is running containers on. Port 5001 is just accessible inside the cluster with internal IP (9.5.52.28 is in your case). Whenever you expose your deployment, automatically (also you can define manually) one of the NodePort (by default between 30000 - 32767)assign to the service for external request.</p>
<p>For service details, you need to run the below command. The command output will give you NodePort and another details.</p>
<pre><code>kubectl describe services my-service
</code></pre>
<p>Please check related kubernetes <a href="https://kubernetes.io/docs/tutorials/stateless-application/expose-external-ip-address/" rel="nofollow noreferrer">documentation</a></p>
<p>Also you have configured service with port 5001  but Jenkins working with 8080 as far as I see in logs. Try to change target port of service to 8080 from 5001</p>
