I have created the 2 config map named personservice and personservice-dev.
I am running spring boot application with profile dev but it is not loading the right config map. This is what I see in logs of the pod which gets crashed.
2019-11-05 16:29:37.336 INFO [personservice,,,] 7 --- [ main] b.c.PropertySourceBootstrapConfiguration : Located property source: CompositePropertySource {name='composite-configmap', propertySources=[ConfigMapPropertySource {name='configmap.personservice.default'}]}
2019-11-05 16:29:37.341 INFO [personservice,,,] 7 --- [ main] b.c.PropertySourceBootstrapConfiguration : Located property source: SecretsPropertySource {name='secrets.personservice.default'}
2019-11-05 16:29:37.445 INFO [personservice,,,] 7 --- [ main] c.person.PersonMicroServiceApplication : The following profiles are active: kubernetes,dev
Kubectl get configmaps
Deployment file:
apiVersion: apps/v1
kind: Deployment
metadata:
name: personservice
labels:
app: personservice
spec:
replicas: 1
selector:
matchLabels:
app: personservice
template:
metadata:
labels:
app: personservice
spec:
containers:
- name: personservice
image: microservice-k8s/personmicroservice-k8s:1.0
ports:
- containerPort: 8080
env:
- name: PROFILE
value: "dev"
- name: SERVER_PORT
value: "8080"
- name: ZIPKIN_URI
value: "http://172.19.27.145:9411"
Bootstrap:
spring:
application:
name: personservice
You confused things. Your configmap is named personservice-dev
and your application's name is personservice
not personservice-dev
, by default Spring Cloud K8S looks for configmap with name equals to spring.application.name
and not spring.application.name-{profile}
.
You have 2 ways to solve your problem:
1-Remove personservice-dev
and in your personservice
configmap:
kind: ConfigMap
apiVersion: v1
metadata:
name: personservice
data:
application.yml: |-
p1:
pa: blabla
---
spring:
profiles: dev
p1:
pa: blibli
---
spring:
profiles: prod
p1:
pa: blublu
2-Keep personservice-dev
and personservice
and define this in bootstrap.yml
:
spring:
cloud:
kubernetes:
config:
name: ${spring.application.name} #This is optional
sources:
- name: ${spring.application.name}-${PROFILE} # Here you get your `personservice-dev` configmap