Namespace resolution
-
spring.cloud.kubernetes.client.namespace
属性 -
文件中指定的位置
-
/var/run/secrets/kubernetes.io/serviceaccount/namespace
文件 -
客户端方法调用(如果客户端提供),例如 Fabric8 的
KubernetesClient::getNamespace
查找应用程序命名空间是在尽力而为的基础上进行的。为了找到命名空间,我们会迭代一些步骤。最简单、最常用的方法是在适当的配置中指定命名空间,例如:
Finding an application namespace happens on a best-effort basis. There are some steps that we iterate in order to find it. The easiest and most common one, is to specify it in the proper configuration, for example:
spring:
application:
name: app
cloud:
kubernetes:
secrets:
name: secret
namespace: default
sources:
# Spring Cloud Kubernetes looks up a Secret named 'a' in namespace 'default'
- name: a
# Spring Cloud Kubernetes looks up a Secret named 'secret' in namespace 'b'
- namespace: b
# Spring Cloud Kubernetes looks up a Secret named 'd' in namespace 'c'
- namespace: c
name: d
请记住,ConfigMap 可以执行相同的操作。如果未指定此类命名空间,将按(以下)此顺序读取命名空间:
Remember that the same can be done for config maps. If such a namespace is not specified, it will be read (in this order):
-
from property
spring.cloud.kubernetes.client.namespace
-
from a String residing in a file denoted by
spring.cloud.kubernetes.client.serviceAccountNamespacePath
property -
from a String residing in
/var/run/secrets/kubernetes.io/serviceaccount/namespace
file (kubernetes default namespace path) -
from a designated client method call (for example fabric8’s :
KubernetesClient::getNamespace
), if the client provides such a method. This, in turn, could be configured via environment properties. For example fabric8 client can be configured via "KUBERNETES_NAMESPACE" property; consult the client documentation for exact details.
如果从上述步骤中找不到命名空间,将导致引发异常。
Failure to find a namespace from the above steps will result in an Exception being raised.