How can I set the container order for a multi-container pod in Kubernetes (with Kustomize)?

7/24/2019

It's sort of a minor annoyance, but I would definitely prefer to have my main container be the default container in the pod for kubectl attach -i $PODNAME or accessing logs, etc. Currently I have a two-container pod, where the sidecar (a database proxy) is always the first listed. The output of kustomize build . where . is my overlay directory shows that the sidecar is listed first, which I understand is the controlling feature when the yaml is applied to the cluster.

The frustrating part for me is that I have not been able to find any means of control over their order via kustomize.

# ./kustomize.yaml
namespace: staging
namePrefix: staging-
bases:
- ../../base
patches:
- staging_api_container.yaml
- staging_db_connect.yaml

In the base deployment to which those patches are applied, only the main container is defined. I even renamed the patches so their names would not only be semantic, as per the kustomize best practices, but so they would be in alphabetical order, which in turn corresponds to the desired file order. The containers themselves are also named such that alphabetizing them produces the correct order.

Really any sort of solution would be acceptable--a yaml key for the cluster to identify the primary container, a kustomize setting to specify the order of the lists or merge strategy?

-- Ben
kubernetes
kustomize

0 Answers