Recently, we made the container ID optional because it is not always reliable to fetch it automatically from cgroupV2
. And cgroupV2
is more and more widely adopted. However, container id could be important in some case. For example, it is used to retrieve the container name, which is subsequently set to cloud_RoleName
in the telemetries. In some applications, cloud_RoleName
is crucial for organizing telemetries.
If the container ID cannot be fetched automatically and there is only one container in the pod, this is easily resolved because the container name/ID will be backfilled.
However, when multiple containers are present in the same pod, starting from version 6.1.1-beta2
, we now allow users to provide container names through the ContainerName
environment variable. More details about this can be found in issue #344, and in the implementation details in this PR 347.
Here's an example of how to provide the ContainerName
environment variable, please pay attention to the env
section below.
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: "ai-k8s-demo"
name: ai-k8s-f5webapi-deployment
labels:
app: ai-k8s-f5webapi
spec:
replicas: 1
selector:
matchLabels:
app: ai-k8s-f5webapi
template:
metadata:
labels:
app: ai-k8s-f5webapi
spec:
containers:
- name: ai-k8s-f5webapi
image: registry_account_name/f5webapi:latest
env:
- name: ContainerName
value: "ai-k8s-f5webapi"
Different approaches can be used to provide the value. For example, you can also use labels, assuming there is one that happens to have the same value:
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: "ai-k8s-demo"
name: ai-k8s-f5webapi-deployment
labels:
app: ai-k8s-f5webapi
spec:
replicas: 1
selector:
matchLabels:
app: ai-k8s-f5webapi
template:
metadata:
labels:
app: ai-k8s-f5webapi
spec:
containers:
- name: ai-k8s-f5webapi
image: registry_account_name/f5webapi:latest
env:
- name: ContainerName
valueFrom:
fieldRef:
fieldPath: metadata.labels['app']