Use K8s Deployment Hostname In YAML Config 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 &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;-------------------
....


Now, I changed this selenium-hub-rc.yaml to a deployment:

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
...


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.
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 &lt;deployment name here&gt;

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 &lt;service name here&gt; -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.