<p>My idea of where the hostname was coming from was wrong. According to the <a href="https://kubernetes.io/docs/concepts/services-networking/service/" rel="nofollow noreferrer">docs</a>:</p>

<blockquote>
  <p>Every Service defined in the cluster (including the DNS server itself) is assigned a DNS name.</p>
</blockquote>

<p>and</p>

<blockquote>
  <p>Currently when a pod is created, its hostname is the Pod’s metadata.name value.</p>
</blockquote>

<p>So the hostname is actually the name of the service. The last sentence in my question says I did not change the service in anyway. That was an unintentional lie. I did change the service name, or else <code>selenium-hub</code> as the hostname would have worked.</p>

<p>Changing <code>HUB_PORT_4444_TCP_ADDR</code> to the <code>.metadata.name</code> of the <em>service</em> got me closer. The connection was timing out, though.</p>

<p>I believed some of the configuration was wrong in my service yaml. So instead of using my yaml file, I created the service via:
<code>kubectl expose deployment &lt;deployment name here&gt;</code></p>

<p>This created a service and I checked the selenium-hub and the node was finally connected. So there was an issue in my service yaml. To get the correct configuration I exported the currently working service:
<code>kubectl get svc &lt;service name here&gt; -o yaml --export</code></p>

<p>I copied the exported configuration to my service yaml file and it also worked. Here was the difference between the service yamls</p>

<pre><code>old yaml (copied from GitHub example above)
---
apiVersion: v1
kind: Service
metadata:
  name: selenium-hub-service
  labels:
    app: selenium-grid
spec:
  ports:
  - port: 4444
    targetPort: 4444
    protocol: TCP ------------- [added in new config]
    name: port0 ------------- [deleted in new config]
  selector:
    app: selenium-hub
  type: NodePort ------------- [deleted in new config]
  sessionAffinity: None
</code></pre>

<p>I am not sure why adding <code>.spec.ports[0].protocol</code> and deleting <code>.spec.type</code> and <code>.spec.ports[0].name</code> fixed the issue. If anyone could clarify in the comments I would appreciate it.</p>

CC BY-SA 3.0
2017-10-28T18:46:40.167Z
2017-10-28T18:52:00.770Z
2017-10-28T18:52:00.770Z
rys
<p>I am trying to convert some K8s examples from ReplicationControllers to Deployments. These examples are for a Selenium grid located: <a href="https://github.com/kubernetes/examples/tree/master/staging/selenium" rel="nofollow noreferrer">https://github.com/kubernetes/examples/tree/master/staging/selenium</a></p>

<p>When I run the examples as-is, my selenium-hub and selenium-nodes connect successfully. However, when I tried to convert <code>selenium-hub-rc.yaml</code> and <code>selenium-node-chrome-rc.yaml</code> into Deployments, the selenium-nodes will not connect to the selenium-hub.</p>

<p>In <code>selenium-node-chrome-rc.yaml</code> there are <a href="https://github.com/kubernetes/examples/blob/master/staging/selenium/selenium-node-chrome-rc.yaml#L21" rel="nofollow noreferrer">these variables</a>:</p>

<pre><code>...
env:
- name: HUB_PORT_4444_TCP_ADDR 
value: "selenium-hub"
- name: HUB_PORT_4444_TCP_PORT 
value: "4444"
...
</code></pre>

<p><code>HUB_PORT_4444_TCP_ADDR</code> is the ip/hostname of the selenium-hub. The <code>selenium-hub-rc.yaml</code> shows the phrase <code>selenium-hub</code> in <a href="https://github.com/kubernetes/examples/blob/master/staging/selenium/selenium-hub-rc.yaml#L4" rel="nofollow noreferrer">many locations</a>. <strong>Question 1</strong>: which of these is actually defining the host name? (<code>.metadata.name</code>, <code>.spec.selector.app</code>, ...?)</p>

<pre><code>apiVersion: v1
kind: ReplicationController
metadata:
  name: selenium-hub &lt;-------------------
  labels:
    app: selenium-hub &lt;-------------------
spec:
  replicas: 1
  selector:
    app: selenium-hub &lt;-------------------
  template:
    metadata:
      labels:
        app: selenium-hub &lt;-------------------
    spec:
      containers:
- name: selenium-hub &lt;-------------------
....
</code></pre>

<p>Now, I changed this <code>selenium-hub-rc.yaml</code> to a deployment:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: selenium-hub-deployment &lt;---------- this is the hostname?
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: selenium-grid
    spec:
      containers:
      - name: selenium-hub &lt;--------- this is the hostname?
        image: selenium/hub
        ports:
        - containerPort: 4444
...
</code></pre>

<p>But now the selenium-node won't connect and I believe it is due to <code>HUB_PORT_4444_TCP_ADDR</code>. I have tried:</p>

<pre><code>- name: HUB_PORT_4444_TCP_ADDR
  value: "selenium-hub"
</code></pre>

<p>and</p>

<pre><code>- name: HUB_PORT_4444_TCP_ADDR
  value: "selenium-hub-deployment"
</code></pre>

<p>Neither worked. <strong>Question 2</strong>: What is the hostname for a deployment? It seemed straight forward in the ReplicationController yaml e.g. <code>selenium-hub</code>, but I can't get it to work as a deployment.</p>

<p><s>Note, I have not changed <a href="https://github.com/kubernetes/examples/blob/master/staging/selenium/selenium-hub-svc.yaml" rel="nofollow noreferrer">the service</a> in any way.</s> Actually I DID change it and that partially caused my initial issue.</p>

<kubernetes>
Use K8s Deployment Hostname In YAML Config
rys
# Use K8s Deployment Hostname In YAML Config

(Asked by: username_0 on 2017-10-28)

I am trying to convert some K8s examples from ReplicationControllers to Deployments. These examples are for a Selenium grid located: https://github.com/kubernetes/examples/tree/master/staging/selenium
When I run the examples as-is, my selenium-hub and selenium-nodes connect successfully. However, when I tried to convert selenium-hub-rc.yaml and selenium-node-chrome-rc.yaml into Deployments, the selenium-nodes will not connect to the selenium-hub.
In selenium-node-chrome-rc.yaml there are these variables:
...
env:
- name: HUB_PORT_4444_TCP_ADDR 
value: "selenium-hub"
- name: HUB_PORT_4444_TCP_PORT 
value: "4444"
...

HUB_PORT_4444_TCP_ADDR is the ip/hostname of the selenium-hub. The selenium-hub-rc.yaml shows the phrase selenium-hub in many locations. Question 1: which of these is actually defining the host name? (.metadata.name, .spec.selector.app, ...?)
apiVersion: v1
kind: ReplicationController
metadata:
  name: selenium-hub <-------------------
  labels:
    app: selenium-hub <-------------------
spec:
  replicas: 1
  selector:
    app: selenium-hub <-------------------
  template:
    metadata:
      labels:
        app: selenium-hub <-------------------
    spec:
      containers:
- name: selenium-hub <-------------------
....

Now, I changed this selenium-hub-rc.yaml to a deployment:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: selenium-hub-deployment <---------- this is the hostname?
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: selenium-grid
    spec:
      containers:
      - name: selenium-hub <--------- this is the hostname?
        image: selenium/hub
        ports:
        - containerPort: 4444
...

But now the selenium-node won't connect and I believe it is due to HUB_PORT_4444_TCP_ADDR. I have tried:
- name: HUB_PORT_4444_TCP_ADDR
  value: "selenium-hub"

and
- name: HUB_PORT_4444_TCP_ADDR
  value: "selenium-hub-deployment"

Neither worked. Question 2: What is the hostname for a deployment? It seemed straight forward in the ReplicationController yaml e.g. selenium-hub, but I can't get it to work as a deployment.
Note, I have not changed the service in any way. Actually I DID change it and that partially caused my initial issue.

**Tags:** kubernetes


---

## 1 answers

### Answer by username_0 on 2017-10-28. Score: 2 | Accepted answer

My idea of where the hostname was coming from was wrong. According to the docs:

Every Service defined in the cluster (including the DNS server itself) is assigned a DNS name.

and

Currently when a pod is created, its hostname is the Pod’s metadata.name value.

So the hostname is actually the name of the service. The last sentence in my question says I did not change the service in anyway. That was an unintentional lie. I did change the service name, or else selenium-hub as the hostname would have worked.
Changing HUB_PORT_4444_TCP_ADDR to the .metadata.name of the service got me closer. The connection was timing out, though.
I believed some of the configuration was wrong in my service yaml. So instead of using my yaml file, I created the service via:
kubectl expose deployment 
This created a service and I checked the selenium-hub and the node was finally connected. So there was an issue in my service yaml. To get the correct configuration I exported the currently working service:
kubectl get svc  -o yaml --export
I copied the exported configuration to my service yaml file and it also worked. Here was the difference between the service yamls
old yaml (copied from GitHub example above)
---
apiVersion: v1
kind: Service
metadata:
  name: selenium-hub-service
  labels:
    app: selenium-grid
spec:
  ports:
  - port: 4444
    targetPort: 4444
    protocol: TCP ------------- [added in new config]
    name: port0 ------------- [deleted in new config]
  selector:
    app: selenium-hub
  type: NodePort ------------- [deleted in new config]
  sessionAffinity: None

I am not sure why adding .spec.ports[0].protocol and deleting .spec.type and .spec.ports[0].name fixed the issue. If anyone could clarify in the comments I would appreciate it.


---

