<p>I have a spring boot application. I want to load to my k8s (master + kubectl, 172.16.100.83) Our image registry is at 192.168.1.229:5000. </p>

<pre><code>1) With command window
a. docker pull 192.168.1.229:5000/gearboxrack/gearbox-rack-eureka-server
b. kubectl run gearbox-rack-eureka-server --image=192.168.1.229:5000/gearboxrack/gearbox-rack-eureka-server --port=8761 
c. kubectl expose deployment gearbox-rack-eureka-server --type NodePort
[root@master3 supwisdom]# kubectl get svc
NAME                         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
gearbox-rack-eureka-server   NodePort    10.103.109.185   &lt;none&gt;        8761:30719/TCP   6s
kubernetes                   ClusterIP   10.96.0.1        &lt;none&gt;        443/TCP          1h
</code></pre>

<p>Then I successfully launch the application by <code>172.16.100.83:30719</code>. Notice now port is generated randomly by k8s.</p>

<p>Now I use yaml file to try to get some result/goal.</p>

<p>eureka_pod.yaml</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: gearbox-rack-eureka-server
  labels:
    purpose: platform_eureka_demo
spec:
  containers:
  - name:  gearbox-rack-eureka-server
    image: 192.168.1.229:5000/gearboxrack/gearbox-rack-eureka-server
    ports:
        - containerPort: 8761
</code></pre>

<p>my eureka_svc.yaml files is </p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: gearbox-rack-eureka-server
  labels:
    name: gearbox_rack_eureka_server
spec:
  type: NodePort
  ports:
    - port: 8761
      nodePort: 31501
      name: tcp


[root@master3 supwisdom]# kubectl apply -f eureka_pod.yaml
pod "gearbox-rack-eureka-server" created

[root@master3 supwisdom]# kubectl apply -f  eureka_svc.yaml
service "gearbox-rack-eureka-server" created
[root@master3 supwisdom]# kubectl get services
NAME                         TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
gearbox-rack-eureka-server   NodePort    10.99.100.123   &lt;none&gt;        8761:31501/TCP   11s
kubernetes                   ClusterIP   10.96.0.1       &lt;none&gt;        443/TCP          2h
</code></pre>

<p>But now I try <code>172.16.100.83:31501</code>, I could not get same result as command lines did. Are there something wrong with my steps?</p>

user84592
<p>usually services need a <strong>selector</strong> to find the pod. Also you might need to specify <strong>targetPort</strong> in the service spec.</p>

<p>I think this should work in your case.</p>

<p>Add this to the pod labels</p>

<pre><code>labels:
  app: my-app
</code></pre>

<p>Add this to the service</p>

<pre><code>spec:
  selector:
    app: my-app
</code></pre>
