Replicating Environment Variables and Volume Mount Points of a Service Container
Scenarios
In scenarios such as container log collection and processing, configuration management, and data synchronization, you can transfer the configuration file path through environment variables or mount the volume of the main service container to the sidecar container through the shared volume mount point to implement specific functions. CCI allows you to replicate the environment variables (env) and volume mount points (volumeMounts) of a service container to implement specific functions. This simplifies the operations.
You can replicate environment variables and volume mount points of a service container in the following ways:
Prerequisites
If you use a ClusterExtensionProfile or ExtensionProfile to replicate environment variables and volume mount points of a service container, you need to configure the sidecar container first. For details, see Configuring the Sidecar Container.
Functions
Function |
Description |
---|---|
Replicate environment variables of the service container when the sidecar container is injected. |
|
Replicate the volume mount points of the service container when the sidecar container is injected. |
|
Constraints
Field |
Constraints |
---|---|
envFromContainer |
|
volumeMountFromContainer |
|
Method 1: Using Annotations
Add the envFromContainer and volumeMountFromContainer annotations to copy the environment variables and volume mount points of the service container.
bursting.cci.io/pod-sidecars: '{"containers":[{"name":"busybox","image":"busybox:latest","command":["sh","-c","sleep 3600"],"resources":{},"envFromContainer":[{"name":"POD_IP","containerFieldRef":{"index":0,"fieldPath":"env.POD_IP"}},{"name":"POD_NAME","containerFieldRef":{"name":"nginx","fieldPath":"env.POD_NAME"}},{"name":"CONTAINER_NAME","containerFieldRef":{"index":0,"fieldPath":"name"}}],"volumeMountFromContainer":[{"volumeMountName":"log-storage","containerRef":{"index":0}},{"volumeMountName":"log-storage1","containerRef":{"name":"nginx"}}]}]}'
Method 2: Using a ClusterExtensionProfile
- Generate a YAML file. Use a ClusterExtensionProfile to configure the environment variables and volume mount points of the sidecar container.
The following is an example YAML file:
apiVersion: bursting.cci.io/v1 kind: ClusterExtensionProfile metadata: name: podsidecar-cluster-profile spec: actions: podSidecars: containers: - command: - sh - -c - sleep 3600 image: busybox:latest name: busybox envFromContainer: - containerFieldRef: fieldPath: env.POD_IP index: 0 name: POD_IP - containerFieldRef: fieldPath: env.POD_NAME name: nginx name: POD_NAME - containerFieldRef: fieldPath: name index: 0 name: CONTAINER_NAME volumeMountFromContainer: - containerRef: index: 0 volumeMountName: log-storage - containerRef: name: nginx volumeMountName: log-storage1 namespaceLabels: matchLabels: key: value
- Create the object.
kubectl apply -f <podsidecar-cluster-profile> #YAML file name (Replace it with the actual file name.)
- (Optional) Verify that the object has been created.
kubectl get cextp
Method 3: Using an ExtensionProfile
- Generate a YAML file. Use an ExtensionProfile to configure the environment variables and volume mount points of the sidecar container.
The following is an example YAML file:
apiVersion: bursting.cci.io/v1 kind: ExtensionProfile metadata: name: podsidecar-profile spec: actions: podSidecars: containers: - command: - sh - -c - sleep 3600 image: busybox:latest name: busybox envFromContainer: - containerFieldRef: fieldPath: env.POD_IP index: 0 name: POD_IP - containerFieldRef: fieldPath: env.POD_NAME name: nginx name: POD_NAME - containerFieldRef: fieldPath: name index: 0 name: CONTAINER_NAME volumeMountFromContainer: - containerRef: index: 0 volumeMountName: log-storage - containerRef: name: nginx volumeMountName: log-storage1 objectLabels: matchLabels: key1: value1
- Create the object.
kubectl apply -f <podsidecar-profile> #YAML file name (Replace it with the actual file name.)
- (Optional) Verify that the object has been created.
kubectl get extp
Parameter Description
Parameter |
Description |
---|---|
InitContainers |
The list of init containers injected on CCI through pod.spec.initContainers. The structure of initContainer is similar to that of initContainer for the pod. restartPolicy cannot be configured. position, envFromContainer, and volumeMountFromContainer are added. For details, see Table 4. |
Containers |
The list of containers injected on CCI through pod.spec.containers. For details, see Table 4. |
Volumes |
The list of volumes injected on CCI through pod.spec.volumes. |
Parameter |
Mandatory |
Value Type |
Description |
---|---|---|---|
position |
No |
String |
You can configure the position field for a container to specify where the injection is to be performed. If position is set to head, the container is injected at the beginning. If position is set to tail, the container is injected at the end. By default, the container is injected at the end. Containers with the same position settings are injected in the sequence specified by actions.podSidecars. |
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot