Skip to content

Commit 638c506

Browse files
authored
[Docs]OSPP Support Kubernetes ConfigMap for Apollo java, golang client (#5233)
## What's the purpose of this PR docs for pr apolloconfig/apollo-java#79 discussion #5210 Co-authored-by: ZhangJian He <[email protected]>
1 parent d886164 commit 638c506

File tree

2 files changed

+183
-0
lines changed

2 files changed

+183
-0
lines changed

docs/en/client/java-sdk-user-guide.md

+91
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ The content of the file is stored in properties format, for example, if there ar
171171
request.timeout=2000
172172
batch=2000
173173
```
174+
> Note: If deployed in a Kubernetes environment, you can also enable the configMap cache to further improve availability
174175
175176
#### 1.2.3.1 Customizing the cache path
176177

@@ -414,6 +415,96 @@ The configuration methods, in descending order of priority, are
414415
3. Via the `app.properties` configuration file
415416
* You can specify `apollo.override-system-properties=true` in `classpath:/META-INF/app.properties`
416417

418+
#### 1.2.4.10 ConfigMap cache
419+
420+
> For version 2.4.0 and above
421+
422+
Starting from version 2.4.0, the availability of the client in the Kubernetes environment has been enhanced. After enabling the ConfigMap cache, the client will cache a copy of the configuration information fetched from the server in the ConfigMap. In the case of service unavailability, network issues, and loss of local cache files, the configuration can still be restored from the ConfigMap. Here are the relevant configurations:
423+
424+
`apollo.cache.kubernetes.enable`:Whether to enable the ConfigMap cache mechanism, the default is false.
425+
426+
`apollo.cache.kubernetes.namespace`:The namespace of the ConfigMap to be used (the namespace in Kubernetes), the default value is "default".
427+
428+
The configuration information will be placed in the specified ConfigMap according to the following correspondence:
429+
430+
namespace: Use the specified value, if not specified, the default is "default"
431+
432+
configMapName: apollo-configcache-{appId}
433+
434+
key:{cluster}___{namespace}
435+
436+
value: The content is the JSON format string of the corresponding configuration information.
437+
438+
> appId is the application's own appId, such as 100004458.
439+
>
440+
> cluster is the cluster used by the application, which is usually default if not configured locally
441+
>
442+
> namespace Indicates the configuration namespace used by the application. If '_' appears in the namespace, it will be escaped to '__' when the key is concatenated.
443+
> Since this feature is extended, so the client-java dependency is set to optional. You need to import the matching version
444+
> Since read and write operations on the ConfigMap are required, the pod where the client is located must have the corresponding permissions. The specific configuration method can be referred to below.
445+
446+
How to authorize a Pod's Service Account to have read and write permissions for ConfigMap:
447+
448+
1. Create a Service Account: If there is no Service Account, you need to create one.
449+
```yaml
450+
apiVersion: v1
451+
kind: ServiceAccount
452+
metadata:
453+
name: my-service-account
454+
namespace: default
455+
```
456+
2. Create a Role or ClusterRole: Define a Role or ClusterRole to grant read and write permissions for a specific ConfigMap. If the ConfigMap is used across multiple Namespaces, a ClusterRole should be used.
457+
```yaml
458+
apiVersion: rbac.authorization.k8s.io/v1
459+
kind: Role
460+
metadata:
461+
namespace: default
462+
name: configmap-role
463+
rules:
464+
- apiGroups: [""]
465+
resources: ["configmaps"]
466+
verbs: ["get", "list", "watch", "create", "update", "delete"]
467+
```
468+
3. Bind the Service Account to the Role or ClusterRole: Use RoleBinding or ClusterRoleBinding to bind the Service Account to the Role or ClusterRole created above.
469+
```yaml
470+
apiVersion: rbac.authorization.k8s.io/v1
471+
kind: RoleBinding
472+
metadata:
473+
name: configmap-reader-binding
474+
namespace: default
475+
subjects:
476+
- kind: ServiceAccount
477+
name: my-service-account
478+
namespace: default
479+
roleRef:
480+
kind: Role
481+
name: configmap-role
482+
apiGroup: rbac.authorization.k8s.io
483+
```
484+
4. Specify the Service Account in the Pod configuration: Ensure that the Pod's configuration uses the Service Account created above.
485+
```yaml
486+
apiVersion: v1
487+
kind: Pod
488+
metadata:
489+
name: my-pod
490+
namespace: default
491+
spec:
492+
serviceAccountName: my-service-account
493+
containers:
494+
- name: my-container
495+
image: my-image
496+
```
497+
5. Apply the configuration: Use the kubectl command-line tool to apply these configurations.
498+
```yaml
499+
kubectl apply -f service-account.yaml
500+
kubectl apply -f role.yaml
501+
kubectl apply -f role-binding.yaml
502+
kubectl apply -f pod.yaml
503+
```
504+
505+
These steps give the Service Account in the Pod read and write permissions for the specified ConfigMap.
506+
If the ConfigMap is cross-namespace, use ClusterRole and ClusterRoleBinding instead of Role and RoleBinding, and ensure that these configurations are applied in all Namespaces that need to access the ConfigMap.
507+
417508
# II. Maven Dependency
418509

419510
Apollo's client jar package has been uploaded to the central repository, the application only needs to be introduced in the following way when it is actually used.

docs/zh/client/java-sdk-user-guide.md

+92
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ request.timeout=2000
163163
batch=2000
164164
```
165165

166+
> 注:如果部署在Kubernetes环境中,您还可以启用configMap缓存来进一步提高可用性
167+
166168
#### 1.2.3.1 自定义缓存路径
167169

168170
1.0.0版本开始支持以下方式自定义缓存路径,按照优先级从高到低分别为:
@@ -398,6 +400,96 @@ apollo.label=YOUR-APOLLO-LABEL
398400
3. 通过`app.properties`配置文件
399401
* 可以在`classpath:/META-INF/app.properties`指定`apollo.override-system-properties=true`
400402

403+
#### 1.2.4.10 ConfigMap缓存设置
404+
405+
> 适用于2.4.0及以上版本
406+
407+
在2.4.0版本开始,客户端在Kubernetes环境下的可用性得到了加强,开启configMap缓存后,客户端会将从服务端拉取到的配置信息在configMap中缓存一份,在服务不可用,或网络不通,且本地缓存文件丢失的情况下,依然能从configMap恢复配置。以下是相关配置
408+
409+
`apollo.cache.kubernetes.enable`:是否开启configMap缓存机制,默认false
410+
411+
`apollo.cache.kubernetes.namespace`:将使用的configMap所在的namespace(Kubernetes中的namespace),默认值为"default"
412+
413+
配置信息会以下面的对应关系放置于指定的configmap中:
414+
415+
namespace:使用指定的值,若未指定默认为"default"
416+
417+
configMapName: apollo-configcache-{appId}
418+
419+
key:{cluster}___{namespace}
420+
421+
value:内容为对应的配置信息的json格式字符串
422+
423+
424+
> appId是应用自己的appId,如100004458
425+
> cluster是应用使用的集群,一般在本地模式下没有做过配置的话,是default
426+
> namespace就是应用使用的配置namespace。 如果namespace中出现‘_’ , 将会在拼接key时被转义为‘__
427+
428+
> 由于此功能为拓展功能,所以对于client-java的依赖设为了optional。需用户自行导入匹配的版本
429+
430+
> 由于需要对configmap进行读写操作,所以客户端所在pod必须有相应读写权限,具体配置方法可参考下文
431+
432+
如何授权一个Pod的Service Account具有对ConfigMap的读写权限:
433+
1. 创建Service Account: 如果还没有Service Account,你需要创建一个。
434+
```yaml
435+
apiVersion: v1
436+
kind: ServiceAccount
437+
metadata:
438+
name: my-service-account
439+
namespace: default
440+
```
441+
2. 创建Role或ClusterRole: 定义一个Role或ClusterRole,授予对特定ConfigMap的读写权限。如果ConfigMap是跨多个Namespace使用的,应该使用ClusterRole。
442+
```yaml
443+
apiVersion: rbac.authorization.k8s.io/v1
444+
kind: Role
445+
metadata:
446+
namespace: default
447+
name: configmap-role
448+
rules:
449+
- apiGroups: [""]
450+
resources: ["configmaps"]
451+
verbs: ["get", "list", "watch", "create", "update", "delete"]
452+
```
453+
3. 绑定Service Account到Role或ClusterRole: 使用RoleBinding或ClusterRoleBinding将Service Account绑定到上面创建的Role或ClusterRole。
454+
```yaml
455+
apiVersion: rbac.authorization.k8s.io/v1
456+
kind: RoleBinding
457+
metadata:
458+
name: configmap-reader-binding
459+
namespace: default
460+
subjects:
461+
- kind: ServiceAccount
462+
name: my-service-account
463+
namespace: default
464+
roleRef:
465+
kind: Role
466+
name: configmap-role
467+
apiGroup: rbac.authorization.k8s.io
468+
```
469+
4. 在Pod配置中指定Service Account: 确保Pod的配置中使用了上面创建的Service Account。
470+
```yaml
471+
apiVersion: v1
472+
kind: Pod
473+
metadata:
474+
name: my-pod
475+
namespace: default
476+
spec:
477+
serviceAccountName: my-service-account
478+
containers:
479+
- name: my-container
480+
image: my-image
481+
```
482+
5. 应用配置: 使用kubectl命令行工具应用这些配置。
483+
```yaml
484+
kubectl apply -f service-account.yaml
485+
kubectl apply -f role.yaml
486+
kubectl apply -f role-binding.yaml
487+
kubectl apply -f pod.yaml
488+
```
489+
这些步骤使Pod中的Service Account具有对指定ConfigMap的读写权限。
490+
491+
如果ConfigMap是跨Namespace的,使用ClusterRole和ClusterRoleBinding代替Role和RoleBinding,并确保在所有需要访问ConfigMap的Namespace中应用这些配置。
492+
401493
# 二、Maven Dependency
402494
Apollo的客户端jar包已经上传到中央仓库,应用在实际使用时只需要按照如下方式引入即可。
403495
```xml

0 commit comments

Comments
 (0)