Kubernetes – An Introduction to Sidecars

https://www.maxpixel.net/Oldtimer-Bmw-500-Isolated-Old-Motorcycle-Sidecar-4344066

What is a sidecar?

An example scenario

FROM nginx:1.15.9-alpineADD nginx.conf /etc/nginx/
ADD www/* /www/
docker build --progress=plain --no-cache -t helloworld-webserver:1.0.0 docker\
apiVersion: apps/v1
kind: Deployment
metadata:
name: helloworld-deployment-1
spec:
selector:
matchLabels:
app.kubernetes.io/name: helloworld-deployment-1
replicas: 2
template:
metadata:
labels:
app.kubernetes.io/name: helloworld-deployment-1
spec:
containers:
- name: hello-world
image: helloworld-webserver:1.0.0

Example — version 2 (sidecar)

FROM alpine:latestRUN apk update && \
apk --no-cache add \
git
docker build --progress=plain --no-cache -f docker\Dockerfile.getcontent -t get-content:1.0.0 docker\
apiVersion: apps/v1
kind: Deployment
metadata:
name: helloworld-deployment-2
spec:
selector:
matchLabels:
app.kubernetes.io/name: helloworld-deployment-2
replicas: 2
template:
metadata:
labels:
app.kubernetes.io/name: helloworld-deployment-2
spec:
volumes:
- name: www-content
emptyDir: {}
containers:
- name: hello-world
image: helloworld:1.0
volumeMounts:
- mountPath: /www
name: www-content

- name: getcontent-sidecar
image: get-content:1.0.0
command:
- bash
- -c
- |
git clone
https://github.com/psdally/k8s-sidecars.git /www
while true; do
git fetch
sleep 60
done

volumeMounts:
- mountPath: /www
name: www-content

Conclusion

--

--

AVP, IT Foundation Platforms Architecture at Sun Life Financial. Views & opinions expressed are my own, not necessarily those of Sun Life

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Paul Dally

AVP, IT Foundation Platforms Architecture at Sun Life Financial. Views & opinions expressed are my own, not necessarily those of Sun Life