<p>I make configuration that my service is builded on 8080 port.</p>

<p>My docker image is also on 8080.</p>

<p>I put my <strong>ReplicaSet</strong> with configuration like this</p>

<pre><code>apiVersion: apps/v1
kind: ReplicaSet
metadata:
 name: my-app-backend-rs
      spec:
       containers:
       - name: my-app-backend
         image: go-my-app-backend
         ports:
         - containerPort: 8080
         imagePullPolicy: Never
</code></pre>

<p>And finally I create service of type <strong>NodePort</strong> also on port 8080 with configuration like below:</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
 labels:
  app: my-app-backend-rs
 name: my-app-backend-svc-nodeport
spec:
 type: NodePort
 ports:
 - port: 8080
   protocol: TCP
   targetPort: 8080
 selector:
  app: my-app-backend
</code></pre>

<p>And after I put describe on NodePort I see that I should hit (e.g. curl <a href="http://127.0.0.1:31859/" rel="nofollow noreferrer">http://127.0.0.1:31859/</a>) to my app on address <code>http://127.0.0.1:31859</code>, but I have no response.</p>

<pre><code>Type:                     NodePort
IP:                       10.110.250.176
Port:                     &lt;unset&gt;  8080/TCP
TargetPort:               8080/TCP
NodePort:                 &lt;unset&gt;  31859/TCP
Endpoints:                172.17.0.6:8080
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   &lt;none&gt;
</code></pre>

<p>What am I not understanding and what am I doing wrong? Can anyone explain me that?</p>

Adriano
<blockquote>
  <p>I tried to use curl after <code>kubectl exec -it podname sh</code></p>
</blockquote>

<p>In this very example the double dash is missed in front of the <code>sh</code> command.
Please note that correct syntax can be checked anytime with the <code>kubectl exec -h</code> and shall be like:</p>

<pre><code>kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...] [options]
</code></pre>

<p>if you have only one container per Pod it can be simplified to:</p>

<pre><code>kubectl exec -it PODNAME -- COMMAND
</code></pre>

<p>The caveat of not specyfying the container is that in case of multiple containers on that Pod, you'll be conected to the first one :) </p>

<p>Example:  <code>kubectl exec -it pod/frontend-57gv5 -- curl localhost:80</code></p>

<blockquote>
  <p>I tried also hit on <code>10.110.250.176:80:31859</code> but this is incorrect I think. Sorry but I'm beginner at network stuff.</p>
</blockquote>

<p>yes, that is not correct, as the value for <code>:port</code> occurs twice . In that example it is needed to hit <code>10.110.250.176:80</code> (as <code>10.110.250.176</code> is a "Cluster_IP" )</p>

<blockquote>
  <p>And after I put describe on NodePort I see that I should hit (e.g. curl <a href="http://127.0.0.1:31859/" rel="nofollow noreferrer">http://127.0.0.1:31859/</a>) to my app on address <code>http://127.0.0.1:31859</code>, but I have no response.</p>
</blockquote>

<p>It depends on where you are going to run that command. </p>

<p>In this very case it is not clear what exactly you have put into <a href="https://kubernetes.io/docs/concepts/workloads/controllers/replicaset/" rel="nofollow noreferrer">ReplicaSet</a> config (if <code>Service</code>'s <em>selector</em> matches with <code>ReplicaSet</code>'s <em>labels</em>), so let me explain "how this <em>supposed</em> to work". </p>

<p>Assuming we have the following  ReplicaSet (the below example is slightly modified version of <a href="https://kubernetes.io/docs/concepts/workloads/controllers/replicaset/#example" rel="nofollow noreferrer">official documentation on topic</a> ):</p>

<pre><code>apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: frontend-rs
  labels:
    app: guestbook
    tier: frontend-meta
spec:
  # modify replicas according to your case
  replicas: 2
  selector:
    matchLabels:
      tier: frontend-label 
  template:
    metadata:
      labels:
        tier: frontend-label      ## shall match spec.selector.matchLabels.tier
    spec:
      containers:
      - name: php-redis
        image: gcr.io/google_samples/gb-frontend:v3
</code></pre>

<p>And the following service: </p>

<pre><code>apiVersion: v1
kind: Service
metadata:
 labels:
  app: frontend
 name: frontend-svc-tier-nodeport
spec:
 type: NodePort
 ports:
 - port: 80
   protocol: TCP
   targetPort: 80
 selector:
   tier: frontend-label   ## shall match labels from ReplicaSet spec
</code></pre>

<p>We can create ReplicaSet (RS) and Service. As a result, we shall be able to see RS, Pods, Service and End Points:</p>

<pre><code>kubectl get rs -o wide
NAME          DESIRED   CURRENT   READY   AGE   CONTAINERS   IMAGES                                 SELECTOR
frontend-rs   2         2         2       10m   php-redis    gcr.io/google_samples/gb-frontend:v3   tier=frontend-label

kubectl get pods -o wide
NAME                    READY   STATUS    RESTARTS   AGE    IP           NODE                                            
frontend-rs-76sgd       1/1     Running   0          11m    10.12.0.31   gke-6v3n
frontend-rs-fxxq8       1/1     Running   0          11m    10.12.1.33   gke-m7z8 

kubectl get svc -o wide
NAME                         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)                          AGE     SELECTOR
frontend-svc-tier-nodeport   NodePort    10.0.5.10    &lt;none&gt;        80:32113/TCP                     9m41s   tier=frontend-label

kubectl get ep -o wide
NAME                         ENDPOINTS                                                     AGE
frontend-svc-tier-nodeport   10.12.0.31:80,10.12.1.33:80                                   10m

kubectl describe svc/frontend-svc-tier-nodeport
Selector:                 tier=frontend-label
Type:                     NodePort
IP:                       10.0.5.10
Port:                     &lt;unset&gt;  80/TCP
TargetPort:               80/TCP
NodePort:                 &lt;unset&gt;  32113/TCP
Endpoints:                10.12.0.31:80,10.12.1.33:80
</code></pre>

<p>Important thing that we can see from my example is that Port was set 80:32113/TCP for the service we have created.</p>

<p>That shall allow us accessing "gb-frontend:v3" app in a few different ways:</p>

<ul>
<li>from inside cluster: <code>curl 10.0.5.10:80</code><br>
(CLUSTER-IP:PORT) or <code>curl frontend-svc-tier-nodeport:80</code> </li>
<li>from external network (internet): <code>curl PUBLIC_IP:32113</code> 
here  PUBLIC_IP is the IP you can reach Node in your cluster. All the nodes in cluster are listening on a <code>NodePort</code> and forward requests according t the Service's selector.</li>
<li>from the Node : <code>curl localhost:32113</code></li>
</ul>

<p>Hope that helps.</p>
