Configuring a Sidecar Container
Scenarios
The CCE Cloud Bursting Engine for CCI add-on can automatically inject your desired containers into a pod. 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:
- An annotation with the key set to bursting.cci.io/pod-sidecars cannot be configured in both actions.podSidecars and 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 initContainer is similar to that of initContainer for the pod. restartPolicy cannot be configured. position, envFromContainer, and volumeMountFromContainer are 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 |
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