Configuring a Sidecar Container (Dynamic Injection)
Scenarios
When the CCE Cloud Bursting Engine for CCI add-on is used to schedule workloads to CCI 2.0, your desired containers can be automatically injected into pods. Injected containers run as sidecar containers.
For example, if you want to use the add-on to burst the workloads to CCI 2.0 and report collected logs to your log center, you can configure the policy for automatically injecting a log collection container.
There are three ways to configure sidecar containers:
Prerequisites
If you want to configure sidecar containers using a ClusterExtensionProfile or ExtensionProfile, you need to configure the ClusterExtensionProfile or ExtensionProfile first. For details, see Configuring a ClusterExtensionProfile or ExtensionProfile.
Constraints
- Multiple containers (including init containers) can be injected. The injected containers cannot have the same names as other containers in the pod.
- Multiple volumes can be injected. Only volumes of the types supported by CCI can be injected. The injected volumes cannot have the same names as those in pod.spec.volumes.
- When a ClusterExtensionProfile or ExtensionProfile is used:
- When you are configuring actions.podSidecars, the annotation with the key set to bursting.cci.io/pod-sidecars cannot be configured in actions.annotations.
- If there is already an annotation with the key set to bursting.cci.io/pod-sidecars for the pod matched by the profile, the annotation is overwritten or kept as it is based on the policy of the profile.
Method 1: Using Annotations
You can add annotations to Pod.Annotations to inject sidecar containers into pods deployed on CCI.
bursting.cci.io/pod-sidecars: '{
"containers":[{"name":"container-sidecar1","image":"busybox:latest","command":["sh","-c","sleep 3600"],"position":"head"}],
"initContainers":[{"command":["sh","-c","sleep 10"],"image":"busybox:latest","name":"initbusybox","position":"tail","resources":{},"volumeMounts":[{"mountPath":"/tmp/auth","name":"mysecret"}]}],
"volumes":[{"name":"mysecret","secret":{"secretName":"testsecret"}}]}' Method 2: Using a ClusterExtensionProfile
apiVersion: bursting.cci.io/v1
kind: ClusterExtensionProfile
metadata:
name: podsidecar-cluster-profile
spec:
actions:
podSidecars:
initContainers:
- command:
- sh
- -c
- sleep 10
image: busybox:latest
name: initbusybox
position: tail
resources: {}
volumeMounts:
- mountPath: /tmp/auth
name: mysecret
volumes:
- name: mysecret
secret:
secretName: testsecret
namespaceLabels:
matchLabels:
key: value Method 3: Using an ExtensionProfile
apiVersion: bursting.cci.io/v1
kind: ExtensionProfile
metadata:
name: podsidecar-profile
namespace: default
spec:
actions:
podSidecars:
containers:
- command:
- sh
- -c
- sleep 3600
image: busybox:latest
name: busybox
volumeMounts:
- mountPath: /tmp/auth
name: mysecret
volumes:
- name: mysecret
secret:
secretName: testsecret
objectLabels:
matchLabels:
key1: value1 Parameter Description
| Parameter | Description |
|---|---|
| initContainers | The list of init containers injected on CCI through pod.spec.initContainers. The structure of an init container is similar to that of an init container in the pod, with parameters position, envFromContainer, and volumeMountFromContainer added. For details, see Table 2. |
| containers | The list of containers injected on CCI through pod.spec.containers. For details, see Table 2. |
| volumes | The list of volumes injected on CCI through pod.spec.volumes. |
| Parameter | Mandatory | 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. |
| restartPolicy | No | String | Container restart policy. This parameter is valid only in initContainers. If this parameter is set to Always, the container runs as a native Kubernetes sidecar container. This function depends on the CCE Cloud Bursting Engine for CCI add-on v1.5.80 or later. |
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