<p>I am following Kubernetes tutorial: <a href="https://kubernetes.io/docs/tutorials/stateless-application/guestbook/#creating-the-redis-master-service" rel="nofollow noreferrer">https://kubernetes.io/docs/tutorials/stateless-application/guestbook/#creating-the-redis-master-service</a></p>

<p>However there is one line i do not understand. In frontend-deployment there is GET_HOSTS_FROM variable. Its value is "dns". Is it evaluated further or does it remain as "dns"?</p>

<p>This is the whole corresponding yaml:</p>

<pre><code>#application/guestbook/frontend-deployment.yaml 

apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
  name: frontend
  labels:
    app: guestbook
spec:
  selector:
    matchLabels:
      app: guestbook
      tier: frontend
  replicas: 3
  template:
    metadata:
      labels:
        app: guestbook
        tier: frontend
    spec:
      containers:
      - name: php-redis
        image: gcr.io/google-samples/gb-frontend:v4
        resources:
          requests:
            cpu: 100m
            memory: 100Mi
        env:
        - name: GET_HOSTS_FROM
          value: dns
          # Using `GET_HOSTS_FROM=dns` requires your cluster to
          # provide a dns service. As of Kubernetes 1.3, DNS is a built-in
          # service launched automatically. However, if the cluster you are using
          # does not have a built-in DNS service, you can instead
          # access an environment variable to find the master
          # service's host. To do so, comment out the 'value: dns' line above, and
          # uncomment the line below:
          # value: env
        ports:
        - containerPort: 80
</code></pre>

hal
<p>The value for the <code>GET_HOSTS_FROM</code> isn't evaluated any further - it remains as "dns".</p>

<p>Looking at the application's source code <a href="https://github.com/kubernetes/examples/blob/master/guestbook/php-redis/guestbook.php" rel="noreferrer">here</a>, <code>GET_HOSTS_FROM</code> is used to determine if the hosts for the Redis primary and slave will come from the environment or, by default, be the Kubernetes service names for the <a href="https://github.com/kubernetes/examples/blob/master/guestbook/all-in-one/guestbook-all-in-one.yaml#L4" rel="noreferrer">primary</a> and the <a href="https://github.com/kubernetes/examples/blob/master/guestbook/all-in-one/guestbook-all-in-one.yaml#L49" rel="noreferrer">slave</a>:</p>

<pre><code>  $host = 'redis-master';
  if (getenv('GET_HOSTS_FROM') == 'env') {
    $host = getenv('REDIS_MASTER_SERVICE_HOST');
  }
</code></pre>

<p>When the host names are Kubernetes Service names, they will be resolved using cluster's <a href="https://kubernetes.io/docs/concepts/services-networking/service/#dns" rel="noreferrer">DNS</a>.</p>

<p>It is worth mentioning how pods can reference Services in the same vs. a different namespace (the excerpt is from the link to the docs given above):</p>

<blockquote>
  <p>...if you have a Service called "my-service" in a Kubernetes Namespace
  "my-ns", the control plane and the DNS Service acting together create
  a DNS record for "my-service.my-ns". Pods in the "my-ns" Namespace
  should be able to find it by simply doing a name lookup for my-service
  ("my-service.my-ns" would also work).</p>
</blockquote>
