Home > database >  Java Spring Active profile in kubernetes Cluster
Java Spring Active profile in kubernetes Cluster

Time:09-21

i want to start Java spring app with active profile... I build Docker image in Gitlab CI/CD using maven wrapper ,

./mvnw compile jib:build -Dimage=image/sms-service:1

after that i deploy app in k8s....

now i want to run with active profile , what is best way? how can i define in k8s to run specific user

apiVersion: apps/v1
kind: Deployment
metadata:
  name: sms-service
  namespace: sms-service
spec:
  selector:
    matchLabels:
      app: sms-service
  replicas: 4 # tells deployment to run 2 pods matching the template
  template:
    metadata:
      labels:
        app: sms-service
    spec:
  template:
    spec:
      containers:
      - name: sms-service
        image: image/sms-service:1
        imagePullPolicy: Always
        ports:
        - containerPort: 8080
      imagePullSecrets:
      - name: sms-service

CodePudding user response:

Set the SPRING_PROFILES_ACTIVE environment variable to the profile(s) you want to run.

You can set it in the deployment yaml or at build time in your image but usually better to add it to deployment.

CodePudding user response:

Create a new file under the k8s config folder and add the following lines:

apiVersion: v1
kind: ConfigMap
metadata:
  name: blabla
  namespace: bla
data:
  application.yaml: |
    spring:
      profiles:
        active: prod (here goes the profile)

This tells Kubernetes to set this configuration when starting the container

  • Related