Custom Names for Containers Deployed to Kubernetes

I am deploying Octopus Deploy Workers to Kubernetes using the “Deploy Kubernetes Containers” step type. When I do it, I set the Replica count to 3 (so it makes three instances of the container).

I also set the environment variables for the containers to be deployed. One of them is TargetName. When I set it, all three instances of the container get the same value. (And they show up as one worker in Octopus deploy.)

If I don’t set TargetName then each worker gets the name of the pod it is placed in (inside Kubernetes).

I would like to know if there is a way to get both of those together? Meaning I would like a custom name + the name of the pod set in the TargetName environment variable used when creating the containers.

For example, if my pod was named: octopus-tentacles-5bd8c5458d-s5fjm and the custom name I wanted for the Worker was blue- then the value in TargetName would be set to blue-octopus-tentacles-5bd8c5458d-s5fjm

Basically, I need something to add to TargetName that will allow each replica to have a different value, but still allow my custom value (that is derived from a variable).

Hi @OctopusSchaff,

Thanks for reaching out and for the question.

I’ve spoke it over internally with our solutions team and it doesn’t appear like there is a way (at least built into the Deploy a Kubernetes Container step) to do what you’re looking to do.
Using this step, it may be best to deploy separate containers rather than a replica set.

As the replicas are part of a set, there’s no way to differentiate at the time of creation which replica gets which environmental variable.

It may be worth looking in to using StatefulSets to attain what you’re looking for:
“Unlike a Deployment, a StatefulSet maintains a sticky identity for each of their Pods”
Perhaps using this identity, you can retrieve the index value and set different environment variables for each replica.

The functionality for this isn’t included in the “Deploy a Kubernetes Container” step, to do this from within Octopus you would have to build out a YAML and use the “Deploy a raw kubernetes yaml” step.

Apologies for the uncertain solution, this isn’t something we’ve tested, so I can’t confirm if it will work in this way.

If you have further questions or if there’s any way I can help further please don’t hesitate to get back in touch.

Kind Regards,

Thank you for the response.

One quick follow up question. When I try to set the container name, it does not seem to allow any kind of variable bindings:

Is there some way I am not seeing to construct this value using a variable? (That would give the same effect as what I was asking for above.) If it could somehow set it to #{Pipeline}-octopus-tentacles that would be perfect.

Hi @OctopusSchaff,

Unfortunately the Name field in the Image Details form cannot contain special characters and the “Deploy Kubernetes Containers” step also does not undergo variable substitution on the YAML.

Your best bet would be to build out a YAML configuration you would like for your deployments and then use the “Deploy raw kubernetes yaml” step with variable substitution to achieve the desired results.

Apologies that I could not assist further with this but please reach out if you have any further questions.

Kind Regards,

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

Hey @OctopusSchaff

Sorry to re-open this but just to let you know another user here has asked for container named variables in the Kubernetes step. Our engineers have reviewed this and said it is a legitimate case and they would look into ways to implement it!

They did say it will take them a while to do as they are pretty busy right now with some P1 issues but they have created a Public GitHub Issue for this (linked below) so please feel free to subscribe to it. You will then get updates as to the progress of it and when its implemented!

Add support for container name variables in “Deploy Kubernetes containers” step template

I hope that is some welcomed news, reach out if you need anything further,

Kind Regards,


1 Like