<p>I am studying services in k8s from <a href="https://kubernetes.io/docs/concepts/services-networking/service/#services-without-selectors" rel="nofollow noreferrer">here</a></p>

<p>I have created service without selector and with one endpoint. What I am trying to do is I have installed apache and it's running on port 80. I have created a node port service on port 31000. Now this service should redirect ip:31000 to ip:80 port. </p>

<p>It is doing for internal ip of service but not on external ip. </p>

<p><strong>my-service.yaml</strong></p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  ports:
  - protocol: TCP
    port: 9376
    targetPort: 80
    nodePort: 31000
  type: NodePort
</code></pre>

<p><strong>my-endpoint.yaml</strong></p>

<pre><code>apiVersion: v1
kind: Endpoints
metadata:
  name: my-service
subsets:
  - addresses:
      - ip: &lt;IP&gt;
    ports:
      - port: 80
</code></pre>

<p>Output for <strong>kubectl get service -o wide</strong> </p>

<pre><code>NAME         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE   SELECTOR
kubernetes   ClusterIP   10.96.0.1        &lt;none&gt;        443/TCP          53m   &lt;none&gt;
my-service   NodePort    10.111.205.207   &lt;none&gt;        9376:31000/TCP   30m   &lt;none&gt;
</code></pre>

<p>First thing is, you need to run a pod inside your cluster then assign the ip of  that pod inside the Endpoints yaml with port, because services exposes the pods to within or outside the cluster, we must use either selector or the address of the pod so that service can attach it self to particular pod.</p>

<pre><code>apiVersion: v1
kind: Endpoints
metadata:
  name: my-service
subsets:
  - addresses:
      - ip: &lt;ip address of the pod&gt;
    ports:
      - port: &lt;port of the pod&gt;
</code></pre>

<p>One more thing use Statefulset in place of Deployment to run pods. </p>
