<p>I have yaml file</p>
<pre><code>  apiVersion: batch/v1beta1
   kind: CronJob
   metadata:
     name: ct-cron
   spec:
     schedule: &quot;*/1 * * * *&quot;
     concurrencyPolicy: Forbid
     jobTemplate:
       spec:
         template:
           metadata:
             labels:
               app: your-periodic-batch-job
               aadpodidbinding: managedaks
           spec:
             containers:
             - name: redmine-cron
               image: orm.azurecr.io/py-app:v3
               imagePullPolicy: IfNotPresent
             - name: redmine-cron1
               image: orm.azurecr.io/py-app:v5
               imagePullPolicy: IfNotPresent
               volumeMounts:
                 - name: store01-inline1
                   mountPath: &quot;/mnt/secrets-store&quot;
                   readOnly: true            
             restartPolicy: OnFailure
             volumes:
               - name: store01-inline1
                 csi:
                   driver: secrets-store.csi.k8s.io
                   readOnly: true
                   volumeAttributes:
                     secretProviderClass: &quot;azure-kvname-podid&quot;
</code></pre>
<p>I stored this yaml as a string in the database.I want to deploy this YAML using c# code. But I couldn't find any option to deploy the yaml file using c# code.Is it possible ?</p>

<p>It's possible with the nuget package <em>KubernetesClient</em></p>
<p>it includes a yaml parser, <a href="https://github.com/kubernetes-client/csharp/blob/master/examples/yaml/Program.cs" rel="nofollow noreferrer">sample</a></p>
<pre><code>var typeMap = new Dictionary&lt;String, Type&gt;();
typeMap.Add(&quot;v1/Pod&quot;, typeof(V1Pod));
typeMap.Add(&quot;v1/Service&quot;, typeof(V1Service));
typeMap.Add(&quot;apps/v1beta1/Deployment&quot;, typeof(Appsv1beta1Deployment));

var objects = await Yaml.LoadAllFromFileAsync(args[0], typeMap);
</code></pre>
<p>Those objects can be applied with the Kubernetes class' <em>Create</em> methods e.g. Namespace</p>
<pre><code>var k8SClientConfig = KubernetesClientConfiguration.BuildConfigFromConfigFile();
IKubernetes client = new Kubernetes(k8SClientConfig);

var ns = new V1Namespace { Metadata = new V1ObjectMeta { Name = &quot;test&quot; } };
var result = client.CreateNamespace(ns);
</code></pre>
