<p>Trying to curl the service deployed in k8s cluster from the master node </p>

<pre><code>curl: (7) Failed to connect to localhost port 31796: Connection 
refused
</code></pre>

<p>For kubernetes cluster, when I check my iptables on master I get the following . </p>

<pre><code>Chain KUBE-SERVICES (1 references)
target     prot opt source               destination         
REJECT     tcp  --  anywhere             10.100.94.202        /* 
default/some-service: has no endpoints */ tcp dpt:9015 reject-with 
icmp-port-unreachable
REJECT     tcp  --  anywhere             10.103.64.79         /* 
default/some-service: has no endpoints */ tcp dpt:9000 reject-with 
icmp-port-unreachable
REJECT     tcp  --  anywhere             10.107.111.252       /* 
default/some-service: has no endpoints */ tcp dpt:9015 reject-with 
icmp-port-unreachable
</code></pre>

<p>if I flush my iptables with</p>

<pre><code>iptables -F
</code></pre>

<p>and then curl  </p>

<pre><code>curl -v  localhost:31796 
</code></pre>

<p>I get the following </p>

<pre><code>* Rebuilt URL to: localhost:31796/
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 31796 (#0)
&gt; GET / HTTP/1.1
&gt; Host: localhost:31796
&gt; User-Agent: curl/7.58.0
&gt; Accept: */*    
</code></pre>

<p>but soon after it results in </p>

<pre><code>* Rebuilt URL to: localhost:31796/
*   Trying 127.0.0.1...
* TCP_NODELAY set
* connect to 127.0.0.1 port 31796 failed: Connection refused
* Failed to connect to localhost port 31796: Connection refused
* Closing connection 0
curl: (7) Failed to connect to localhost port 31796: Connection 
refused
</code></pre>

<p>I'm using the <code>nodePort</code> concept in my service</p>

<p>Details </p>

<pre><code>kubectl get node 

NAME              STATUS   ROLES    AGE   VERSION
ip-Master-IP   Ready    master   26h   v1.12.7
ip-Node1-ip    Ready    &lt;none&gt;   26h   v1.12.7
ip-Node2-ip    Ready    &lt;none&gt;   23h   v1.12.7


Kubectl get pods 
NAME                             READY   STATUS    RESTARTS   AGE
config-service-7dc8fc4ff-5kk88   1/1     Running   0          5h49m

kubectl get svc -o wide

NAME            TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)          
AGE   SELECTOR
cadmin-server   NodePort    10.109.55.255   &lt;none&gt;        
9015:31796/TCP   22h   app=config-service
kubernetes      ClusterIP   10.96.0.1       &lt;none&gt;        443/TCP          
26h   &lt;none&gt;

Kubectl get cs 

NAME                 STATUS    MESSAGE              ERROR
controller-manager   Healthy   ok                   
scheduler            Healthy   ok                   
etcd-0               Healthy   {"health": "true"} 

endpoint.yml

apiVersion: v1
kind: Endpoints
metadata:
name: xyz
subsets:
- addresses:
  - ip: node1_ip
  - ip: node2_ip
 ports:
  - port: 31796
  - name: xyz

service.yml
apiVersion: v1
kind: Service
metadata:
name: xyz
namespace: default
annotations:
alb.ingress.kubernetes.io/healthcheck-path: /xyz
labels:
app: xyz
spec:
type: NodePort
ports:
- nodePort: 31796
  port: 8001
  targetPort: 8001
  protocol: TCP
selector:
app: xyz


deployment.yml 
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: xyz
name: xyz
namespace: default
spec:

replicas: 1
selector:
matchLabels:
  app: xyz
template:
  metadata:
  labels:
    app:  xyz
  spec:
  containers:
  - name: xyz
    image:  abc
    ports:
     - containerPort: 8001
    imagePullPolicy: Always
    resources:
      requests:
        cpu: 200m
    volumeMounts:
    - mountPath: /app/
      name: config-volume    
    restartPolicy: Always
    imagePullSecrets:
    - name: awslogin


     volumes:
     - configMap:
      name: xyz
      name: config-volume
</code></pre>

Charvee Punia
<p>You can run the following command to check endpoints.</p>
<p>kubectl get endpoints</p>
<p>If endpoint is not showing up for the service. Please check the yml files that you used for creating the loadbalancer and the deployment. Make sure the labels match.</p>
