GET_HOSTS_FROM 变量的值是多少?

hal*_*hal 3 kubernetes

我正在关注 Kubernetes 教程: https

但是有一行我不明白。在前端部署中有 GET_HOSTS_FROM 变量。它的值是“dns”。它是进一步评估还是保留为“dns”?

这是整个对应的yaml:

#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
Run Code Online (Sandbox Code Playgroud)

api*_*sim 7

的值GET_HOSTS_FROM不会进一步评估 - 它仍然是“dns”。

此处查看应用程序的源代码,GET_HOSTS_FROM用于确定 Redis 主服务器和从服务器的主机是否来自环境,或者默认情况下是主服务器服务器的 Kubernetes 服务名称:

  $host = 'redis-master';
  if (getenv('GET_HOSTS_FROM') == 'env') {
    $host = getenv('REDIS_MASTER_SERVICE_HOST');
  }
Run Code Online (Sandbox Code Playgroud)

当主机名是 Kubernetes Service 名称时,它们将使用集群的DNS 进行解析

值得一提的是 Pod 如何引用相同和不同命名空间中的服务(摘录来自上面给出的文档的链接):

...如果您在 Kubernetes 命名空间“my-ns”中有一个名为“my-service”的服务,则控制平面和 DNS 服务共同为“my-service.my-ns”创建一个 DNS 记录。“my-ns”命名空间中的 Pod 应该能够通过简单地对 my-service 进行名称查找来找到它(“my-service.my-ns”也可以)。