假设我有以下的Pod规范。
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”字符串?我的意思是,一旦我使用类似于执行以下命令进入容器:
kubectl exec -it <pod-name> -c nginx bash
有没有编程的方法来获取Pod规范中给定容器名称的方式?
注意,这不一定是在
docker ps
中打印的 Docker 容器名称。Kubernetes 为生成的 Docker 容器组合了一个较长的名称。
向下API在这方面看起来很有前途。然而,在{{code1:向下API的功能}}部分中没有提到{{code2:容器名称}}。
root@$HOSTNAME : $CONTAINER_NAME >$
在Kubernetes中,$HOSTNAME变成PodName。 - Hakan Baba