1

I have a Nest.js based application running in kubernetes. There is ConfigModule initialized in the app and ConfigService that reads env variable defined in configMap.

@Module({
  imports: [
    ConfigModule.forRoot({
      isGlobal: true,
    }),
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}
@Injectable()
export class AppService {

  @Inject(ConfigService)
  private config: ConfigService;

  getHello(): string {
    const app = this.config.get('app-name')
    const psw = this.config.get('app-password')
    return `name: ${app}, password: ${psw}`;
  }
}

configMap.yaml is attached to my container in deployment.yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nestjs-k8s
spec:
  selector:
    matchLabels:
      app: nestjs-k8s
  replicas: 1
  template:
    metadata:
      labels:
        app: nestjs-k8s
    spec:
      containers:
        - name: nestjs-k8s
          image: multiplexor88/nestjs-k8s
          ports:
            - containerPort: 3000
          envFrom:
            - configMapRef:
                name: config-map
            - secretRef:
                name: secret


I want to refresh my configuration in application when configMap is changed. Is there a way to make it? If it is not possible, then at list is somehow schedule Nest.js ConfigModule to reinitialize without application restart.

Igor Dumchykov
  • 347
  • 1
  • 15
  • Does this answer your question? [Restart pods when configmap updates in Kubernetes?](https://stackoverflow.com/questions/37317003/restart-pods-when-configmap-updates-in-kubernetes) – kool Aug 05 '22 at 13:04
  • It is kind of solution, but the best for me is not to reload a pod, but just somehow reload configuration service inside application – Igor Dumchykov Aug 05 '22 at 13:14
  • I found https://www.npmjs.com/package/@nestcloud/config, but would be better to use something the same without additional dependencies – Igor Dumchykov Aug 10 '22 at 09:33
  • Secrets mounted as volumes in pods automatically get updated every time they are changed without restarting pods. Your current approach for using ENV requires restarting pods manually. – Taimoor Mirza Aug 12 '22 at 06:25

0 Answers0