config-map kubernetes multiple environments

0 votes

I am trying to deploy a Spring Boot application using configuration data from Kubernetes cluster. 

I have a simple RestController that prints a message.

    private String message = "Message not coming from Kubernetes config map";

@RequestMapping(value="/echo", method=GET)
public String printKubeConfig() {
    return message;
}

Specified the name of the config map in my application.yml

spring:
  application:
    name: echo-configmap

echo-configmap

apiVersion: v1
kind: ConfigMap
metadata:
  name: echo-configmap
data:
  application.properties: |-
    message=Hello from dev Kubernetes Configmap
  application_qa.properties: |-
    message=Hello from qa Kubernetes Configmap

My doubt was how can you specify environment specific properties in the most efficient way?

Aug 31, 2018 in Kubernetes by lina
• 8,220 points
2,078 views

1 answer to this question.

0 votes

Deploy your application as helm chart. 

After having created a Chart with helm create, you will get a templates/ directory, in which you might place the following YAML template for your ConfigMap:

apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ printf "%s-%s" .Release.Name .Chart.Name }}
  labels:
    app: {{ .Chart.Name | trunc 63 | trimSuffix "-" }}
    chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
data:
  application.properties: |-
    message={{ .Values.properties.message }}
You can add a second YAML template for your Deployment object 
containers:
  - name: {{ .Chart.Name }}
    # [...]
    volumes:
      - name: property-volume
        mountPath: /etc/your-app/properties
volumes:
  - name: property-volume
    configMap:
      name: {{ printf "%s-%s" .Release.Name .Chart.Name }}

This is how the default file values.yaml looks like

replicaCount: 1
image:
  repository: your-docker-image
  tag: your-docker-tag
properties:
  message: Hello!

Next, use this Helm chart and the helm install command to deploy your application

helm install --name dev --set image.tag=latest --set replicaCount=1 path/to/chart
$ helm install --name prod --set image.tag=stable --set replicaCount=3 --set properties.message="Hello from prod" path/to/chart
answered Aug 31, 2018 by Kalgi
• 52,350 points

Related Questions In Kubernetes

0 votes
1 answer

What is the difference between config map and secret in kubernetes?

Config maps ideally stores application configuration in ...READ MORE

answered Jul 17, 2019 in Kubernetes by Sirajul
• 59,230 points
3,729 views
0 votes
3 answers

Using multiple commands in a kubernetes yaml file

Try something like this: containers: - name: ...READ MORE

answered Apr 23, 2019 in Kubernetes by lyza
49,875 views
0 votes
2 answers

Kubernetes on AWS: “Error: unknown flag: --config”

Update the cluster.yaml, changing the line kubernetesVersion: v1.6.6_coreos.1 to kubernetesVersion: v1.7.10_coreos.0 Should ...READ MORE

answered Oct 4, 2018 in Kubernetes by Kalgi
• 52,350 points
2,526 views
0 votes
1 answer

Kubernetes: Can we use multiple claims out of a persistent volume?

The mapping between persistentVolume and persistentVolumeClaim is ...READ MORE

answered Jul 16, 2019 in Kubernetes by Sirajul
• 59,230 points
6,084 views
+1 vote
1 answer
0 votes
3 answers

Error while joining cluster with node

Hi Kalgi after following above steps it ...READ MORE

answered Jan 17, 2019 in Others by anonymous
15,477 views
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
4,036 views
0 votes
2 answers

single point of entry for multiple services in kubernetes ingress

I tried having something similar too. Deployment apiVersion: extensions/v1beta1 kind: ...READ MORE

answered Sep 7, 2018 in Kubernetes by Hannah
• 18,520 points
2,700 views
0 votes
1 answer

map 2 ports in my deployment file - kubernetes ingress

You can add as many ports as ...READ MORE

answered Sep 24, 2018 in Kubernetes by Kalgi
• 52,350 points
1,026 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP