-
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
Live update is not working with Spring Cloud Kubernetes Configuration Watcher #1664
Comments
I started to look at this and will let you know my findings. |
You are missing RBAC in your sample for
I had to change the parameter : Your |
@wind57 Thank you very much for your quick response. I implemented the recommendations you gave me. I changed the Role object to ClusterRole and the RoleBinding to ClusterRoleBinding. You can see the changes in this folder of my Github repository. I also updated the SPRING_CLOUD_KUBERNETES_CONFIGURATION_WATCHER_REFRESHDELAY variable with the value: 60000 (one minute). However, the behavior seems a bit strange. Here are some pieces of evidence. I get all the pods.
Here are some logs from the spring-cloud-kubernetes-configuration-watcher.
Part of the logs from the first pod.
Part of the logs from the second pod.
As you can see, I updated the configmap at 2024-06-13T05:53:22.399-06:00 with these values:
Both pods were updated correctly. Then, I updated the configmap at 2024-06-13T05:56:02.405-06:00 with these values.
Although spring-cloud-kubernetes-configuration-watcher ran the /actuator/refresh post, only one of the pods was updated correctly.
To make sure that each pod received an HTTP request, I connected to each pod and executed next commands:
I would appreciate your help in reviewing what I am doing wrong, please. Thanks a lot! |
well... this is rather interesting. I can re-produce your issue once I go to 2 replicas indeed. Now why that happens, I don't know, but I will debug the issue and try to figure it out. I'll update this post once I have the findings. |
I've re-produced this one once, but can't do it anymore and I have tried a few times already. weird |
@ryanjbaxter this is a bug, I don't know where exactly, but it is. If I increase the replicas to 5 it is easy to reproduce . I'll try to figure out what is going on. Would you please add the label? |
investigation update: Initially I thought that there is something within our code base and we have a bug somewhere. To confirm (or infirm) this, I've added such a class to your sample:
I also add a controller method:
To reproduce the issue I've added 5 replicas in the deployment also. So here is what I do, step by step:
in the configmap; deploy the app and go to a certain pod in my
and:
OK, so that tells me that configuration watcher and app are correctly working.
wait 1 minute and go to the pods. Some pods are working as expected, but this one:
This tells me two things, first is that the refresh event was received (meaning that our code does not have problems with firing the events). The second thing I notice, is that at the time when the refresh event was received, the value in the mount was
I see that the value is finally updated to In the end, this is not our code-base issue (although I wish it were, cause in that case I could have tried to fix it). This looks like kubernetes eventual consistency problem, also looks like it is "aggravated" when there are more replicas. I will try to ask on the k8s github or figure out something, but in the end, I highly doubt that anything is really possible in your case. The only hope you have is to increase that value to more the 60 seconds... If you abstract yourself away for a second, this issue is a little frustrating for a different reason too. It is related to this one. Think about it, if you are mounting a file, why would you need configuration watcher at all (with all of its RBAC rules)? Why can't we have a mechanism in place to watch only a file/folder? We would not need to talk to the kube-api at all :) When we see that it changes, refresh the app. I plan to work on such a proposal next year, after we drop the "path support" (this PR) |
@wind57 Thanks a lot!!! |
Thank you so much @wind57 for your valuable advice and suggestions. I'm happy to report that my service and Spring Cloud Kubernetes Configuration Watcher are working perfectly fine now. I followed your advice and set up SPRING_CLOUD_KUBERNETES_CONFIGURATION_WATCHER_REFRESHDELAY variable to 2 minutes and also increased the number of replicas to 10, which has improved the performance significantly. However, I'm facing some issues while trying to implement the same with Secrets. I have updated my code in my Github repository, and I was hoping if you could kindly review it and provide me with feedback on what I'm missing or doing wrong. Once again, I'm deeply grateful for your help, and I look forward to hearing from you soon. |
I will take a look, of course, and update this post once done. Im not sure I can do it this week, since Im on vacation, but will try. |
It would be great if what is not working would not be this generic:
I mean: what issues exactly your are facing, because otherwise I have to guess. Let's see if I guessed correctly... I changed Then, I renamed some files from
I see that you are using : You need to change your app in minimal ways: drop from Dockerfile
and place this in
If I start the app this way, I see this:
Then I realized that you are using:
(be careful to respect all indention in this file). Then I deploy the app and see in logs:
So my guess was that you were no able to see those properties correctly wired to begin with... |
@wind57 Thank you once again for your generous support. |
@ryanjbaxter it seems like this one can be closed |
by the way, this was not a bug, may be worth to remove the label too |
Live update is not working with Spring Cloud Kubernetes Configuration Watcher
I would appreciate any feedback.
I have a Spring Boot 3.3.0 project and Java 21. I would like to use the Spring Cloud Kubernetes Configuration Watcher feature in my demo project to update configuration from Kubernetes ConfigMaps or Secrets.
I have tested my project with Spring Boot 2.X and Java 17 and it works fine, but not with Spring Boot 3.X.
Here is my complete code.
I have added spring-cloud-starter-kubernetes-client-config and spring-boot-starter-actuator to my pom.xml file.
My java code:
My Dockerfile
Spring Cloud Kubernetes Configuration Watcher is running OK on Kubernetes, following step by step explained in Deployment.yaml
Logs
Configmap.yaml
Deployment.yaml
To start my app on Kubernetes
Modifiyng configmap to set new values for my data.
Logs after change and apply configmap.yaml
In this step I continue to see the previous values, despite configuring the SPRING_CLOUD_KUBERNETES_CONFIGURATION_WATCHER_REFRESHDELAY environment variable.
My demo app has actuator/refresh endpoint enabled, but it is not working fine.
If I connect to bash of my pod, I see application.yml updated with new values.
I would appreciate any kind of help.
Thanks in advance.
The text was updated successfully, but these errors were encountered: