You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/en/client/java-sdk-user-guide.md
+91
Original file line number
Diff line number
Diff line change
@@ -171,6 +171,7 @@ The content of the file is stored in properties format, for example, if there ar
171
171
request.timeout=2000
172
172
batch=2000
173
173
```
174
+
> Note: If deployed in a Kubernetes environment, you can also enable the configMap cache to further improve availability
174
175
175
176
#### 1.2.3.1 Customizing the cache path
176
177
@@ -414,6 +415,96 @@ The configuration methods, in descending order of priority, are
414
415
3. Via the `app.properties` configuration file
415
416
* You can specify `apollo.override-system-properties=true` in `classpath:/META-INF/app.properties`
416
417
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.
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
+
417
508
# II. Maven Dependency
418
509
419
510
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.
0 commit comments