How to get Rancher/Kubernetes opaque secret in .NET Core API

1/1/2022

I am new to this Rancher/kubernetes. Wanted to store DB connection string from appsetting-UAT.json file to Rancher secrets and wanted to fetch at runtime in UAT environment.Please find below code:

  1. Installed nuget package Microsoft.Extension.Configuration.UserSecrets
  2. Added the below code where we generally fetch DB connection from Appsettings.json file

    var config= new ConfigurationBuilder() .SetBasePath(StartupHostEnvironment.ContentBasePath) .AddJsonFile("appsetting.json",optional:true, reloadOnChange: true) .AddJsonFile(

    quot;appsetting.{StartupHostEnvironment.EnvironmentName}.json",optional:true) .AddUserSecrets<myBusinessApp>() .AddEnvironmentVariables() .Build();

    _myAppsettings=config.GetSection(_Service.MyAppService).Get<_Service>();

  3. Changes in Deployment.yaml file under UAT environment section:

    • name: MyAppService valueFrom: secretKeyRef: name: fund-overview-secret key: ServiceDbConnection
  4. Also added the secret key in Rancher, under secret->selecting opaque(key/value pair).

but I'm unable to fetch the secrets from Rancher.

Any suggestion will be helpful.

-- Sanjeeb Mondal
asp.net-core
kubernetes
rancher

0 Answers