spring-cloud-kubernetes: Spring Cloud Kubernetes cant refresh config
JDK17 spring-boot-starter-parent 3.0.9 spring-cloud-dependencies 2022.0.4 spring-cloud-starter-kubernetes-fabric8-all spring-boot-starter-actuator
Application.yaml
spring:
main:
cloud-platform: kubernetes
application:
name: application
config:
import: 'kubernetes:'
cloud:
config:
enabled: false
kubernetes:
config:
name: master
namespace: istio-example
enabled: true
client:
master-url: "https://k8s.local:6443"
trust-certs: true
namespace: istio-example
oauth-token: "token"
discovery:
enabled: true
all-namespaces: false
namespaces:
- istio-example
reload:
monitoring-config-maps: true
enabled: true
strategy: refresh
profiles:
active: dev
management:
endpoint:
refresh:
enabled: true
endpoints:
web:
exposure:
include: '*'
logging:
level:
org.springframework.cloud: debug
ConfigMap.yaml
kind: ConfigMap
apiVersion: v1
metadata:
name: master
namespace: istio-example
annotations:
kubectl.kubernetes.io/last-applied-configuration: >
{"apiVersion":"v1","data":{"master-dev.yaml":"test:\n dev:\n value:
application-dev-profile","master.yaml":"test:\n application:\n value:
application-profile\nspring:\n profiles:\n active:
dev"},"kind":"ConfigMap","metadata":{"annotations":{},"name":"master","namespace":"istio-example"}}
data:
application-dev.yaml: |-
test:
dev:
value: application-dev-profile2
k8s:
value: k8s1
application.yaml: |-
test:
application:
value: application-profile1
spring:
profiles:
active: dev
Properties Class
@Data
@Component
@RefreshScope
public class RefreshProperties {
@Value("${test.dev.value}")
private String devValue;
@Value("${test.application.value}")
private String applicationValue;
}
@Autowired
private RefreshProperties pefreshProperties;
@GetMapping("/api/devValue")
public String devValue() {
return pefreshProperties.getDevValue();
}
POST localhost:8080/actuator/refresh
GET localhost:8080/api/devValue RESPONSE application-dev-profile2
After updating ConfigMap.yaml, call the refresh interface, and then request the devValue interface. In fact, the configuration has not been updated
I can see that the log has been printed and configuration changes have been detected
2023-10-20T10:39:30.581+08:00 DEBUG 31860 --- [pool-2-thread-3] o.s.c.k.c.c.reload.ConfigReloadUtil : findPropertySources : [configmap.master.istio-example]
2023-10-20T10:39:30.582+08:00 DEBUG 31860 --- [pool-2-thread-3] o.s.c.k.c.c.reload.ConfigReloadUtil : found change in : Fabric8ConfigMapPropertySource@2035899344 {name='configmap.master.istio-example', properties={test.dev.value=application-dev-profile3, k8s.value=k8s2, test.application.value=application-profile1, spring.profiles.active=dev}}
2023-10-20T10:39:30.582+08:00 INFO 31860 --- [pool-2-thread-3] o.s.c.k.c.c.reload.ConfigReloadUtil : Detected change in config maps/secrets
2023-10-20T10:39:30.582+08:00 INFO 31860 --- [pool-2-thread-3] .s.c.k.c.c.r.ConfigurationChangeDetector : Reloading using strategy: REFRESH
2023-10-20T10:39:30.707+08:00 DEBUG 31860 --- [pool-2-thread-3] o.s.c.b.BootstrapApplicationListener$1 : Activating profiles [dev]
2023-10-20T10:39:30.721+08:00 DEBUG 31860 --- [pool-2-thread-3] o.s.c.b.BootstrapApplicationListener$1 : Activating profiles [dev]
2023-10-20T10:39:30.751+08:00 INFO 31860 --- [pool-2-thread-3] o.s.boot.SpringApplication : The following 1 profile is active: "dev"
2023-10-20T10:39:30.756+08:00 INFO 31860 --- [pool-2-thread-3] o.s.boot.SpringApplication : Started application in 0.173 seconds (process running for 673.806)
About this issue
- Original URL
- State: closed
- Created 8 months ago
- Comments: 22 (10 by maintainers)
May be caused by kubersphere enterprise space permissions,The default token does not have enterprise space authorization, so when I start it, I will prompt
401unauthorizedand403 forbidden,I modified the enterprise space permissions, and then it worked.I still can’t reproduce it. I’ve create a PR for your project, see here
Here is what I do:
kind), this is needed to be able to curl on theNodePortkubectl proxy --port=8092and in a different terminal:curl http://localhost:8092/api. This will show something like this:all I need is the
serverAddress. In my case:172.18.0.3:6443. Take this value and place it inapplication.yaml:pom.xml):I only need
-Dspring-boot.build-image.builder=dashaun/builder:tinybecause I am on ARM Cpu, if you are not, you might not need that.Please note that I have also changed:
kind:If you can tell me how I ca re-produce this one against my PR that I made, that would be lovely. Thank you
I had to go through quite a few hoops to get this running: you have not defined RBAC for the service account, not said how you build the docker image, your app the way it is would fail start-up with some dependency miss-configuration… Next time, pretty please, make sure you provide a complete and minimal example, otherwise I might miss what set-up you have exactly.
What I had to do with your app (besides creating the RBAC rules for the service account) is to remove
bootstrap.yamland thespring-cloud-starter-bootstrapdependency. Otherwise, you have both config-data and bootstrap, so there would be a certain bean created two times and Spring context would not start.After I removed the above mentioned, created the image (using the spring-boot plugin), I deployed the config-map and deployment and then did :
to find out the IP of the pod (since you have not provided a service and ingress either). Then:
and got the
application-dev-profile11as a response. So far, you get the same result.Then, I did a
kubectl edit configmap master(notice that I have simplified your initial example by not including the namespace you had, its only to make my life easier 😃 )and then did another curl, and I got the new value as a response, the updated one.
Notice that I did not have to do any
POST localhost:8080/actuator/refresh, because you already have:and the refresh will happen automatically.
Unless you have an example where your problem is really re-producible, there is nothing I can do more.
@ryanjbaxter can you please add the proper label in here? We need to get proper feedback from OP, otherwise it should be closed. thank you
oh sorry, idea setting repository is private ,im changed. you can access