简体   繁体   中英

Java Spring Active profile in kubernetes Cluster

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

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.

Create a new file, named configmap.yaml 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM