<p>I want to run my automation test script on kubernetes via the selenium hub and the chrome node containers.
My test script is also in the form of a container and running as a pod.
My test script uses localhost:4444 to connect to grid.
But the grid has the NodePort of 31376 and it keeps changing everytime i create a new selenium grid service.</p>

<p>Is there any way i can keep a constant NodePort for my selenium hub so that my script could run.</p>

<p>Selenium hub service:</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: selenium-hub
  labels:
    app: selenium-hub
spec:
  ports:
  - port: 4444
    targetPort: 4444 
    name: port0
  selector:
    app: selenium-hub
  type: NodePort
  sessionAffinity: None
</code></pre>

<p>I don't want to change the link to selenium hub every time I execute my command.</p>

<p>This is my service description :-</p>

<pre><code>C:\KUBE&gt;kubectl describe service selenium-hub
Name:                     selenium-hub
Namespace:                default
Labels:                   app=selenium-hub
Annotations:              &lt;none&gt;
Selector:                 app=selenium-hub
Type:                     NodePort
IP:                       10.106.49.182
Port:                     port0  4444/TCP
TargetPort:               4444/TCP
NodePort:                 port0  31376/TCP
Endpoints:
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   &lt;none&gt;
</code></pre>

<p>Thanks.</p>

<p>According to <a href="https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport" rel="nofollow noreferrer">the documentation on <code>NodePort</code> services</a></p>
<blockquote>
<p>If you want a specific port number, you can specify a value in the nodePort field, and the system will allocate you that port or else the API transaction will fail (i.e. you need to take care about possible port collisions yourself). The value you specify must be in the configured range for node ports.</p>
</blockquote>
<p><a href="https://kubernetes.io/docs/concepts/services-networking/connect-applications-service/#exposing-the-service" rel="nofollow noreferrer">Here is an example</a>, which in your case would look like</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: selenium-hub
  labels:
    app: selenium-hub
spec:
  ports:
  - port: 4444
    targetPort: 4444 
    name: port0
    nodePort: &lt;your-desired-port&gt;
  selector:
    app: selenium-hub
  type: NodePort
  sessionAffinity: None
</code></pre>
