1

I have a kubernetes configuration in json format file which i want to deployed in kubernetes cluster using C# kubernetes clinet api.Below is my config data file.But i want to read this values from appsettings.json. Values is always null when i tried to read this from appsetting.json using Microsoft.Extensions.Configuration .Below is yaml file

{
"yaml":{
    "apiVersion": "batch/v1beta1",
    "kind": "CronJob",
    "metadata": {
        "creationTimestamp": "2020-08-04T06:29:19Z",
        "name": "esignature-cron",
        "namespace": "esignature"
    },
    "spec": {
        "concurrencyPolicy": "Forbid",
        "failedJobsHistoryLimit": 1,
        "jobTemplate": {
            "metadata": {
                "creationTimestamp": null
            },
            "spec": {
                "template": {
                    "metadata": {
                        "creationTimestamp": null,
                        "labels": {
                            "app": "your-periodic-batch-job"
                        }
                    },
                  "spec": {
                        "containers": [
                            {
                                "image": "pystore.azurecr.io/py-app1:1.0.0",
                                "imagePullPolicy": "IfNotPresent",
                                "name": "redmine-cron",
                                "resources": {},
                                "terminationMessagePath": "/dev/termination-log",
                                "terminationMessagePolicy": "File"
                            }
                        ],
                        "dnsPolicy": "ClusterFirst",
                        "imagePullSecrets": [
                            {
                                "name": "dockerpull"
                            }
                        ],
                        "restartPolicy": "OnFailure",
                        "schedulerName": "default-scheduler",
                        "securityContext": {},
                        "terminationGracePeriodSeconds": 30
                    }
                }
            }
        },
        "schedule": "*/1 * * * *",
        "successfulJobsHistoryLimit": 3,
        "suspend": false
    }
}
"ConnectionString":"test"
}

C# code

using Microsoft.Extensions.Configuration;
namespace yamlread.Services.Implementation
{
public class yamlread : Iyamlread
    {
 public IConfiguration Configuration { get; }
 public string yaml { get; set;}
 public yamlread( IConfiguration config)
 {
     Configuration =config;
     yaml=Configuration["yaml"]
 }

1 Answer 1

2

There are few libraries in GitHub which you can use to Parse Yaml into c# object.

Below are the links

https://github.com/aaubry/YamlDotNet

https://github.com/xoofx/SharpYaml

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.