<p>I have build a custom tcserver image exposing port 80 8080 and 8443. Basically you have an apache and inside the configuration you have a proxy pass to forward it to the tcserver tomcat.<br/></p>

<pre><code>EXPOSE 80 8080 8443
</code></pre>

<p>After that I created a kubernetes yaml to build the pod exposing only port 80.</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: tcserver
  namespace: default
spec:
  containers:
  - name: tcserver
    image: tcserver-test:v1
    imagePullPolicy: IfNotPresent
    ports:
    - containerPort: 80
</code></pre>

<p>And the service along with it.</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: tcserver-svc
  labels:
    app: tcserver
spec:
  type: NodePort
  ports:
  - port: 80
    nodePort: 30080
  selector:
    app: tcserver
</code></pre>

<p>But the problem is that I'm unable to access it.<br/>
If I log to the pod (<code>kubectl exec -it tcserver -- /bin/bash</code>), I'm able to do a <code>curl -k -v http://localhost</code> and it will reply.<br/><br/></p>

<p>I believe I'm doing something wrong with the service, but I don't know what.<br/>
Any help will be appreciated. </p>

<p><strong>SVC change</strong> <br/>
As suggested by sfgroups, I added the <code>targetPort: 80</code> to the svc, but still not working.</p>

<p>When I try to curl the IP, I get a <strong>No route to host</strong></p>

<pre><code>[root@testmaster tcserver]# curl -k -v http://172.30.62.162:30080/
* About to connect() to 172.30.62.162 port 30080 (#0)
*   Trying 172.30.62.162...
* No route to host
* Failed connect to 172.30.62.162:30080; No route to host
* Closing connection 0
curl: (7) Failed connect to 172.30.62.162:30080; No route to host
</code></pre>

<p>This is the describe from the svc:</p>

<pre><code>[root@testmaster tcserver]# kubectl describe svc tcserver-svc
Name:                   tcserver-svc
Namespace:              default
Labels:                 app=tcserver
Annotations:            &lt;none&gt;
Selector:               app=tcserver
Type:                   NodePort
IP:                     172.30.62.162
Port:                   &lt;unset&gt; 80/TCP
NodePort:               &lt;unset&gt; 30080/TCP
Endpoints:              &lt;none&gt;
Session Affinity:       None
Events:                 &lt;none&gt;
</code></pre>

<p>When you look at the <code>kubectl describe service</code> output, you'll see it's not actually attached to any pods:</p>

<pre><code>Endpoints:              &lt;none&gt;
</code></pre>

<p>That's because you say in the service spec that the service will attach to pods <em>labeled</em> with <code>app: tcserver</code></p>

<pre><code>spec:
  selector:
    app: tcserver
</code></pre>

<p>But, in the pod spec's metadata, you don't specify any labels at all</p>

<pre><code>metadata:
  name: tcserver
  namespace: default
  # labels: {}
</code></pre>

<p>And so the fix here is to add to the pod spec the appropriate label</p>

<pre><code>metadata:
  labels:
    app: tcserver
</code></pre>

<p>Also note that it's a little unusual in practice to deploy a bare pod.  Usually they're wrapped up in a higher-level controller, most often a deployment, that actually creates the pods.  The deployment spec has a template pod spec and it's the pod's labels that matter.</p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: tcserver
  # Labels here are useful, but the service doesn't look for them
spec:
  template:
    metadata:
      labels:
        # These labels are what the service cares about
        app: tcserver
    spec:
      containers: [...]
</code></pre>
