Configuring Microservices with MicroProfile and Kubernetes
source link: https://www.tuicool.com/articles/hit/VfyMbqq
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
An app’s config is everything that is likely to vary between deploys (staging, production, developer environments, etc). This includes: Resource handles to … backing services. Credentials to external services …
Microservices that are implemented with Java EE can leverage MicroProfile Config . The configuration can be done, for example, in Kubernetes yaml files and accessed from Java code via annotations and APIs. Here is a simple example from the cloud-native-starter repo. The ‘articles’ service uses configuration to define whether or not to create ten articles the first time it is invoked.In the yaml file an environment variable pointing to a ConfigMap is defined.kind: Deployment apiVersion: apps/v1beta1 metadata: name: articles spec: replicas: 1 template: metadata: labels: app: articles version: v1 spec: containers: - name: articles image: articles:1 ports: - containerPort: 8080 env: - name: samplescreation valueFrom: configMapKeyRef: name: articles-config key: samplescreation restartPolicy: Always --- kind: ConfigMap apiVersion: v1 metadata: name: articles-config data: samplescreation: CREATEIn the Java code the configuration can be accessed via @Inject and @ConfigProperty.
public class CoreService { private static final String CREATE_SAMPLES = "CREATE"; @Inject @ConfigProperty(name = "samplescreation", defaultValue = "dontcreate") private String samplescreation; @PostConstruct private void addArticles() { if (samplescreation.equalsIgnoreCase(CREATE_SAMPLES)) addSampleArticles(); }Note that you cannot access the injected variable in the constructor. Instead use the @PostConstruct annotation. Thanks to Emily Jiang for figuring this out. If you want to try this feature and many other MicroProfile and Istio features, get the code from the cloud-native-starter repo and run these commands.
$ git clone https://github.com/nheidloff/cloud-native-starter.git $ scripts/check-prerequisites.sh $ scripts/delete-all.sh $ scripts/deploy-articles-java-jee.sh $ scripts/show-urls.shTo learn more about MicroProfile Config, check out these resources:
Recommend
-
110
Accelerating the Adoption of Java Microservices with Eclipse MicroProfile Nov 08, 2...
-
32
Configuring permissions in Kubernetes with RBAC 原文 确保控制谁有权访问您的信息系统以及...
-
41
In this article, I’ll give you a quick tour of how to use the new MicroProfile Starter (Beta) site...
-
35
As stated in the reactive manifesto cloud-native reactive applications need to be resilient: The system stays responsive in the face of failure. This applies n...
-
36
For cloud-native applications Kubernetes and Istio deliver a lot of important functionality out of the box, for example certain metrics which are i...
-
65
No Comments Kubernetes does not have its own user management and relies on external providers like Key...
-
38
This article describes Tekton , an open-source framework for creating CI/CD systems, and explains how to deploy microservices built with E...
-
7
Configuring SQL Server dependencies in ASP.NET microservices with TyeThis website uses cookies to ensure you get the best experience on our website. Learn more
-
5
-
5
Resources > Blog > Tech Best Practices for Configuring Mi...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK