I use keycloak gatekeeper as a sidecar container for multiple pods on my cluster to enable SSO for those services.
But when I try to exec, view logs, etc; it asks what container I want to use instead of just going into it. Is there a way to define the default container that it will use for something like kubectl exec -it PODNAME
when I don't pass the -c
flag?
What you are asking is currently working but it's very limited. According to kubectl exec documentation you can miss
-c
flag:but you have also specify some action/command like
date
,bash
orsh
.I mention it's very limited, as this will use first container from list which was specified in YAML manifest. If you will use
-c
flag you can specify which one you want toexecute
.Output
Without using any command:
With using command
date
, it will use first container from YAML/description of the pod.Date
command with specified podKubectl exec annotation - default container
In one of the Github enhancements you can find information, that there is plan to introduce this feature in stable kubernetes version (1.23).
It would looks like:
Kubectl logs annotation - default container
Similar feature but regarding
logs
notexec
was introduced inkubectl 1.18
. It was mentioned in Github thread. To achieve that you have to add new annotationkubectl.kubernetes.io/default-logs-container=<containerName>
Scenario my
test-pod
pod withbusybox
andhttpd