Hi guys,
I’m going through practice exams to prepare to CKA exam and I’m kinda confused about the sidecar container questions in it.
So the Kubernetes’ docs states that sidecar container is a special case of the initcontainer, so it could be described like this:
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp
labels:
app: myapp
spec:
replicas: 1
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
spec:
containers:
- name: myapp
image: alpine:latest
command: ['sh', '-c', 'while true; do echo "logging" >> /opt/logs.txt; sleep 1; done']
volumeMounts:
- name: data
mountPath: /opt
initContainers:
- name: logshipper
image: alpine:latest
restartPolicy: Always
command: ['sh', '-c', 'tail -F /opt/logs.txt']
volumeMounts:
- name: data
mountPath: /opt
volumes:
- name: data
emptyDir: {}
at the same time I do see that the answer to the question about the sidecar container assumes this as a right answer:
piVersion: apps/v1
kind: Deployment
metadata:
name: olive-app-cka10-str
spec:
replicas: 1
template:
metadata:
labels:
app: olive-app-cka10-str
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- cluster1-node01
containers:
- name: python
image: poroko/flask-demo-app
ports:
- containerPort: 5000
volumeMounts:
- name: python-data
mountPath: /usr/share/
- name: busybox
image: busybox
command:
- "bin/sh"
- "-c"
- "sleep 10000"
volumeMounts:
- name: python-data
mountPath: "/usr/src"
readOnly: true
volumes:
- name: python-data
persistentVolumeClaim:
claimName: olive-pvc-cka10-str
selector:
matchLabels:
app: olive-app-cka10-str
So question - what is the proper way for creating the sidecar container? Is it just an additional container in containers section or it’s initContainers though?