Transfer Octopus variables to Kubernetes pod

Hi, i’m trying to deploy a .net core service to a Kubernetes cluster through Octopus but i’m having a hard time with variables. I’m using the “Deploy raw Kubernetes yaml” step.

Any idea on how I can easily transfer my Octopus variables to the pod without having to define them all in the “env” part of my deployment.yaml file? (See screenshot)


What I ideally want is to be able to define a variable in Octopus and then my pod knows about it automatically. Kind of like what you would normally do with json file replacement.

Hi @cwh , thanks for getting in touch about your variables!

It looks like our Structured Configuration Variables feature is what you need to use. The following documention page has some more information on it Structured Configuration Variables.

One thing to note; you’ll likely need to upgrade to 2020.4.1 to take adavantage of this. That is being worked on right now and should be availiable in the next week or so.

Please let me know if that works for you or if you have any other questions!

Hi @cwh,

Apologies, I was a little unclear in my initial message.

You can do this in versions before 2020.4.1, it’s just that you use JSON Configuration variables instead of Structured Configuration Variables. Structured Configuration variables is an enhanced version of what we used to use in Octopus and this can be configured in the step by selecting Configuration Features. You will need to define these as variables in Octopus either as a Library Variable Set or a Project Varaible.

Please let me know if I can help further,

All the best

Hi, thanks for the reply.

Is this possible to do with the “Deploy raw Kubernetes yaml” step? I don’t see how this applies here. Maybe i’m missing something?

Hi @cwh,

Upon further investigation; we hadn’t noticed that the step type didn’t have the configure features option. I want to apologise for the oversight on that.

Unfortunately; I don’t think what you’re asking can be done, but I am going to speak to a Kubernetes expert and get back to you with a definitive answer on this early next week.

Hi, thats OK. I got it working in another way. I’m now creating a secret using a Kubectl CLI script which i’m then mounting in my containers.

The secret is my appsettings.json (Retrieved from a NuGet package) which is being replaced by Octopus using JSON configuration variables.

Here is the script i’m using:

$FILE = "$($OctopusParameters["Octopus.Action.Package[<PackageId>].ExtractedPath"])/appsettings.json"
$SECRET_NAME = "<secret name>"
kubectl delete secret $SECRET_NAME --ignore-not-found=true
kubectl create secret generic $SECRET_NAME --from-file=$FILE

Excellent, I’m happy to hear that you managed to get it working!

Thank you for also for sharing your script; that’s an interesting workaround.

Please feel free to reach out if you have any other questions in the future.

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.