Say I have the following pod spec.
apiVersion: apps/v1beta1
kind: Deployment
metadata:
# Unique key of the Deployment instance
name: deployment-example
spec:
# 3 Pods should exist at all times.
replicas: 3
template:
metadata:
labels:
# Apply this label to pods and default
# the Deployment label selector to this value
app: nginx
spec:
containers:
- name: nginx
# Run this image
image: nginx:1.10
Here, the name of the container is nginx. Is there a way to get the "nginx" string from within the running container?
I mean, once I exec into the container with something like
kubectl exec -it <pod-name> -c nginx bash
Is there a programmatic way to get to the given container name in the pod spec ?
Note that this is not necessarily the docker container name that gets printed in docker ps. Kubernetes composes a longer name for the spawned docker container.
The downward api looks promising in this regard. However container name is not mentioned in the Capabilities of the Downward API section.