Search code examples
.netpostgresqlazurekuberneteskubernetes-helm

How to get runtime settings from helm in a kubernetes deployment config file to overwrite appsettings in asp.net


I have a microservice "MyService" in DotNet that has a database. While development time I have a local postgreSQL and I have the connectionstring in my appsettings config:

{
 "MyConString": ....
}

Now in production env I will have a postgresCluster that I start with terraform and a helm chart:

resource "helm_release" "postgres-cluster" {
  name       = "postgres-cluster"
  repository = "https://charts.bitnami.com/bitnami"
  chart      = "postgresql-ha"
  namespace  = local.namespace

  ....
}

No I deploy my service in the same kubernetes cluster (Azure / aks) as the postgres cluster with my kubernetes deployment:

apiVersion: v1
kind: Service
metadata: 
  name: my-service-service
spec:
  selector:
    app: my-service
  ports:
    - protocol: TCP
      port: 80
      targetPort: 9376

So my order is: The infrastructure will be deployed once with terraform (kuberentes, postgresql), then everything is running and then my service will be deployed.

So, I need to put the missing puzzle pieces together: How to get the information from the running helm chart into my kubernetes service deployment to replace the connection string in the appsettings?


Solution

  • You can use helm commands to dump all values.

    First get helm release deployed in namespace.

    helm list -n ingress-controller
    NAME            NAMESPACE               REVISION        UPDATED                                 STATUS          CHART                   APP VERSION
    ingress-nginx   ingress-controller      1               2022-11-03 18:57:32.4117796 +0500 PKT   deployed        ingress-nginx-4.3.0     1.4.0
    

    In my case release name is ingress-nginx. Now you can dump your specified values from release.

    helm get values ingress-nginx -n ingress-controller
    

    If you want to dump all values from the release. You can do this way.

    helm get values ingress-nginx -a -n ingress-controller > values.yaml
    

    From values.yaml file you can get strings/config details of your choice.

    OPTIONAL: There is one IDE of kubernetes that help you get all these values from UI. Lens. I use it frequently for doing such tasks on daily basis.