Configuring a Sidecar Container
Scenarios
A sidecar container is a secondary container that runs along with the main service container in the same pod. Sidecar containers are usually used to extend the functionality of the main application in a non-intrusive manner. A common scenario is that a sidecar container reads log files of the main service container and sends the log files to a log service, such as LTS.
Function Description
CCI supports sidecar containers based on the Kubernetes sidecar container feature. A traditional init container runs and exits before the main service container starts. If an init container is created with its restartPolicy set to Always, this container becomes a sidecar container.
Configuration Example
kind: Deployment
apiVersion: cci/v2
metadata:
name: test
spec:
replicas: 1
selector:
matchLabels:
app: test
template:
metadata:
labels:
app: test
annotations:
resource.cci.io/pod-size-specs: 0.50_1.0
spec:
# Configure the sidecar container.
initContainers:
- name: container2
image: nginx:latest # Replace it with the actual image path.
restartPolicy: Always # If restartPolicy is set to Always in initContainers, the init container becomes a sidecar container.
# Configure the main service container.
containers:
- name: container-1
image: nginx:latest
command:
- /bin/sh
- '-c'
- while true ;do echo hello ;sleep 3; done
resources:
limits:
cpu: 250m
memory: 512Mi
requests:
cpu: 250m
memory: 512Mi
imagePullSecrets:
- name: imagepull-secret
schedulerName: default-scheduler
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 0
maxSurge: 100%
progressDeadlineSeconds: 600 | Parameter Location | Parameter | Example Value | Description |
|---|---|---|---|
| spec.template.spec.initContainers | restartPolicy | Always | (Mandatory) Restart policy of a container. If this parameter is set to Always in initContainers, CCI identifies the container as a sidecar container. Unlike a common init container, this sidecar container starts before the main service container and remains running. It does not exit after running. |
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