假设我有以下pod规范。是否可以从kubernetes容器中获取容器名称?
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
在这里,容器的名称是nginx
。有没有办法从正在运行的容器中获取“nginx”字符串?
我的意思是,一旦我Exec的放入容器的东西,如
kubectl exec -it <pod-name> -c nginx bash
有一个纲领性的方式来获得在吊舱规范指定容器名称?
请注意,这不一定是打印在docker ps
中的码头容器名称。 Kubernetes为产生的码头集装箱组成了一个更长的名字。
downward api在这方面看起来很有前景。但Capabilities of the Downward API
部分未提及container name
。
我希望把它变成我的提示。我想要这样的东西 'root @ $ HOSTNAME:$ CONTAINER_NAME> $'在kubernetes中,$ HOSTNAME变成了PodName –