gpt4 book ai didi

kubernetes - GET_HOSTS_FROM 变量的值是多少?

转载 作者:行者123 更新时间:2023-12-02 11:34:21 26 4
gpt4 key购买 nike

我正在关注 Kubernetes 教程:https://kubernetes.io/docs/tutorials/stateless-application/guestbook/#creating-the-redis-master-service

但是有一条线我不明白。在前端部署中有 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

最佳答案

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

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

  $host = 'redis-master';
if (getenv('GET_HOSTS_FROM') == 'env') {
$host = getenv('REDIS_MASTER_SERVICE_HOST');
}

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

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

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

关于kubernetes - GET_HOSTS_FROM 变量的值是多少?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58733807/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com