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,100 points
115 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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
• 35,750 points

Related Questions In Kubernetes

0 votes
3 answers

Using multiple commands in a kubernetes yaml file

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

answered Apr 23 in Kubernetes by lyza
2,313 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
• 35,750 points
87 views
+5 votes
2 answers

Redirecting host to service path in kubernetes

What you are trying to do is ...READ MORE

answered Mar 27, 2018 in Kubernetes by DragonLord999
• 8,360 points
49 views
0 votes
1 answer

unable to start Kubernetes due to so many open files in system

You can try the following steps: You can ...READ MORE

answered May 1, 2018 in Kubernetes by shubham
• 6,480 points
135 views
0 votes
1 answer
0 votes
3 answers

Error while joining cluster with node

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

answered Jan 17 in Others by anonymous
471 views
+3 votes
1 answer
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
• 14,080 points
43 views
0 votes
1 answer

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.