-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Spring cloud kuberentes watcher spring boot 3.x help required #1461
Comments
I am not sure what exactly you are looking for with regards to using the watcher and spring boot 3.x. |
Hi @ryanjbaxter, thank you for first answer. And for second question I'm looking for help regarding. I want to mount my secrets and configmap to pod as mounted volume and reload them using spring cloud kubernetes config watcher via actuator end point not using amqp bus event. But I couldn't find any example for this. Could you please share any example code for this use case ? |
I am going to write an extensive answer here with an example today, FYI. |
Can you tell me what you have tried and what issue you are running into? |
I agree on the sparse sources for examples. I plan to make some youtube videos in the future on how to configure everything and use, unfortunately I don't have much time at the moment for that. It's on my TODO list nevertheless. A couple of things, using Kubernetes API for secrets/configmaps is still supported and is not planned to go anywhere anytime soon. Support for paths (not As interesting as it sounds, I have been recently preparing for dropping path support and using Since this question might appear for other people, I'll try to summarize this here and point to this issue in the feature. The example can be seen here, it is called
Please notice a few things (I've added a few options for debugging purposes, this can help you greatly when inspecting the logs on your initial set-up, to understand what is going on). The second part, is that here, we have explicitly defined the namespace(s) where configuration watcher will look for stuff (more on that later). This is how I prefer to do it: explicit. If you don't do it like this, then namespace resolution chapter from the documentation will kick in. So, first see if there are explicit namespaces defined ( Keep in mind that
So, Let's go to the part on how you configure Let's suppose this is my configmap:
To mount it (I'm going to put it here as json, the way we have it in the integration test)
If you start such a pod, exec into it, and look into You need to tell Spring about this configuration, and this is done (in
Spring, in turn, having a properties configuration like this:
will be able to inject the It's time to wire these two concepts together: watcher and spring. Once you have everything set-up and change your configmap, for example it becomes:
configuration watcher will detect this, and schedule "something" (will get to it shortly) to happen. First, you need to know one important thing here. When you change a configmap, the path it is mounted to, will change also, so that path inside the pod where
The documentation of k8s is clear as mud in this regard:
Notice the eventually part ... this has an implication on our side: this means that the configuration watcher might have caught this change (remember that it watches for configmap changes), might schedule a remote refresh to the pod of interest (will get to it), but the value inside the pod (the
This value is specified in milliseconds and it means in plain english something like this:
Code-wise would be even simpler to explain:
So don't do it instantly, but after a certain "pause" to give the pods a chance to be updated by the k8s in those mounted paths. By default this is 2 minutes. So after 2 minutes, send a http request to the apps that you want to refresh. Now, what "apps" are supposed to be refreshed/restarted? By default, it is the app that matches the configmap name - that is:
These Since by default these requests will go to the actuator endpoint (you can use a bus for this too, like rabbit or kafka - not going to go into the details for now), you need to enable those endpoints on the pods where the refresh/restart is supposed to go to:
Of course the actuator URI might be different in your case then the default one :) and we do support configuring this also, in case you need explanation on this subject too, just let me know. Keep in mind, that we will send requests to all the "service instances" (pods) at the same time almost, this is not a rolling refresh. We do not support this at the moment. P.S. I hope I got everything right here, if I forgot something, just let me know and I'll update this answer. |
This is epic thanks! When I originally wrote the confg watcher I read some where on the k8s docs what the maximum time was before the values in the Pod would be updated, and I added a little bit to that to be safe as the default value. I am having trouble finding that now, but this is a good explanation on the topic |
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed. |
Hi @wind57 and @ryanjbaxter, Thank you for your help and detailed answer about config watcher. With your information I was able to use it correctly. |
@Nomi67 Could you solve the problem? I'm facing the same issue. Spring Cloud Kubernetes Configuration Watcher works fine with Spring Boot 2.x, but not with Spring Boot 3.x. I cloned this repository: https://github.com/alexdefelipe/spring-cloud-k8s-watcher-demo.git, but it has the same problem as my code. When updating the values of the ConfigMap, the application does not automatically update the configuration. I would appreciate some help to solve the issue with Spring Boot 3.x." |
Hi,
I'm trying to implement spring cloud kubernetes in our projects. My main goals are to read configMap, secrets and enable reload using spring cloud kubernetes config watcher.
Since there are very less examples available about how to use spring cloud for kubernetes apps, I read the documentation and figured out how to read secrets and configmap from k8s. There are 2 ways you can read these i.e
The 2nd one is not recommended due to security problems which can occur so I'm preferring 1st one. But when it comes to reloading properties using watcher then there is zero examples available with spring boot 3.x.
While using below properties in bootstrap.properties I get below warning logs
bootstrap.properties
spring.cloud.kubernetes.discovery.enabled=false spring.cloud.kubernetes.secrets.paths=/etc/secrets/secret-k8s spring.cloud.kubernetes.secrets.fail-fast=true spring.cloud.kubernetes.secrets.enabled=true
warning log
o.s.c.k.c.c.SecretsPropertySourceLocator : path support is deprecated and will be removed in a future release. Please use **spring.config.import**
But I couldn't find any help about how to use this property with kubernetes using volume mounts.
second thing is if possible could you please share an example of watcher with spring boot 3.x which should update mounted volume(secret/configmap) ?
build.gradle
dependencies { implementation 'org.springframework.boot:spring-boot-starter-actuator' implementation 'org.springframework.boot:spring-boot-starter-web' implementation group: 'org.springframework.cloud', name: 'spring-cloud-starter-kubernetes-fabric8-config', version: '3.0.4' compileOnly 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok' testImplementation 'org.springframework.boot:spring-boot-starter-test' }
The text was updated successfully, but these errors were encountered: